update price calculation for service product
This commit is contained in:
@@ -718,32 +718,54 @@ class HotelRoomTypeFeaturePricing extends ObjectModel
|
||||
}
|
||||
}
|
||||
if ($with_auto_room_services) {
|
||||
if ($servicesWithTax = RoomTypeServiceProduct::getAutoAddServices(
|
||||
$id_product,
|
||||
$date_from,
|
||||
$date_to,
|
||||
Product::PRICE_ADDITION_TYPE_WITH_ROOM,
|
||||
true,
|
||||
$id_cart,
|
||||
$id_room,
|
||||
$use_reduc
|
||||
)) {
|
||||
foreach($servicesWithTax as $service) {
|
||||
$totalPrice['total_price_tax_incl'] += Tools::processPriceRounding($service['price']);
|
||||
if ($id_cart) {
|
||||
$objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail();
|
||||
if ($roomServicesServices = $objRoomTypeServiceProductCartDetail->getServiceProductsInCart(
|
||||
$id_cart,
|
||||
0,
|
||||
0,
|
||||
$id_product,
|
||||
$date_from,
|
||||
$date_to,
|
||||
0,
|
||||
0,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
$id_room
|
||||
)) {
|
||||
$selectedServices = array_shift($roomServicesServices);
|
||||
}
|
||||
}
|
||||
if ($servicesWithoutTax = RoomTypeServiceProduct::getAutoAddServices(
|
||||
$id_product,
|
||||
$date_from,
|
||||
$date_to,
|
||||
Product::PRICE_ADDITION_TYPE_WITH_ROOM,
|
||||
false,
|
||||
$id_cart,
|
||||
$id_room,
|
||||
$use_reduc
|
||||
)) {
|
||||
foreach($servicesWithoutTax as $service) {
|
||||
$totalPrice['total_price_tax_excl'] += Tools::processPriceRounding($service['price']);
|
||||
|
||||
if (isset($selectedServices)) {
|
||||
$totalPrice['total_price_tax_incl'] += Tools::processPriceRounding($selectedServices['total_price_tax_incl']);
|
||||
$totalPrice['total_price_tax_excl'] += Tools::processPriceRounding($selectedServices['total_price_tax_excl']);
|
||||
} else {
|
||||
if ($servicesWithTax = RoomTypeServiceProduct::getAutoAddServices(
|
||||
$id_product,
|
||||
$date_from,
|
||||
$date_to,
|
||||
Product::PRICE_ADDITION_TYPE_WITH_ROOM,
|
||||
true,
|
||||
$use_reduc
|
||||
)) {
|
||||
foreach($servicesWithTax as $service) {
|
||||
$totalPrice['total_price_tax_incl'] += Tools::processPriceRounding($service['price']);
|
||||
}
|
||||
}
|
||||
if ($servicesWithoutTax = RoomTypeServiceProduct::getAutoAddServices(
|
||||
$id_product,
|
||||
$date_from,
|
||||
$date_to,
|
||||
Product::PRICE_ADDITION_TYPE_WITH_ROOM,
|
||||
false,
|
||||
$use_reduc
|
||||
)) {
|
||||
foreach($servicesWithoutTax as $service) {
|
||||
$totalPrice['total_price_tax_excl'] += Tools::processPriceRounding($service['price']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,33 +135,14 @@ class RoomTypeServiceProduct extends ObjectModel
|
||||
return Db::getInstance()->getValue($sql);
|
||||
}
|
||||
|
||||
public static function getAutoAddServices($idProduct,
|
||||
$dateFrom = null,
|
||||
$dateTo = null,
|
||||
$priceAdditionType = null,
|
||||
$useTax = null,
|
||||
$idCart = 0,
|
||||
$idRoom = 0,
|
||||
$use_reduc = 1
|
||||
) {
|
||||
public static function getAutoAddServices($idProduct, $dateFrom = null, $dateTo = null, $priceAdditionType = null, $useTax = null, $use_reduc = 1)
|
||||
{
|
||||
if (Product::isBookingProduct($idProduct)) {
|
||||
$sql = 'SELECT p.`id_product` FROM `'._DB_PREFIX_.'htl_room_type_service_product` rsp
|
||||
INNER JOIN `'._DB_PREFIX_.'product` p ON (rsp.`id_product` = p.`id_product` AND p.`auto_add_to_cart` = 1)';
|
||||
if ($idCart || ($dateFrom && $dateTo) || $idRoom) {
|
||||
$sql .= ' INNER JOIN `'._DB_PREFIX_.'htl_room_type_service_product_cart_detail` spcd
|
||||
ON (rsp.`id_product` = spcd.`id_product` AND spcd.`id_cart` = '.(int)$idCart.')
|
||||
INNER JOIN `'._DB_PREFIX_.'htl_cart_booking_data` hcbd
|
||||
ON (hcbd.`id` = spcd.`htl_cart_booking_id`)';
|
||||
}
|
||||
$sql .= ' WHERE p.`active` = 1 AND `id_element` = '.(int)$idProduct.' AND `element_type` = '.self::WK_ELEMENT_TYPE_ROOM_TYPE;
|
||||
INNER JOIN `'._DB_PREFIX_.'product` p ON (rsp.`id_product` = p.`id_product` AND p.`auto_add_to_cart` = 1)
|
||||
WHERE p.`active` = 1 AND `id_element` = '.(int)$idProduct.' AND `element_type` = '.self::WK_ELEMENT_TYPE_ROOM_TYPE;
|
||||
if (!is_null($priceAdditionType)) {
|
||||
$sql .= ' AND p.`price_addition_type` = '.(int)$priceAdditionType;
|
||||
}
|
||||
if ($dateFrom && $dateTo) {
|
||||
$sql .= ' AND hcbd.`date_from` = \''.pSQL($dateFrom).'\' AND hcbd.`date_to` = \''.pSQL($dateTo).'\'';
|
||||
}
|
||||
if ($idRoom) {
|
||||
$sql .= ' AND hcbd.`id_room` = '.(int)$idRoom;
|
||||
$sql .= ' AND p.`price_addition_type` = '.$priceAdditionType;
|
||||
}
|
||||
if ($services = Db::getInstance()->executeS($sql)) {
|
||||
$objRoomTypeServiceProductPrice = new RoomTypeServiceProductPrice();
|
||||
|
||||
@@ -211,7 +211,8 @@ class RoomTypeServiceProductCartDetail extends ObjectModel
|
||||
$useTax = null,
|
||||
$autoAddToCart = 0,
|
||||
$id_address = null,
|
||||
$priceAdditionType = null
|
||||
$priceAdditionType = null,
|
||||
$idRoom = 0
|
||||
) {
|
||||
if ($useTax === null)
|
||||
$useTax = Product::$_taxCalculationMethod == PS_TAX_EXC ? false : true;
|
||||
@@ -256,6 +257,9 @@ class RoomTypeServiceProductCartDetail extends ObjectModel
|
||||
if ($dateFrom && $dateTo) {
|
||||
$sql .= ' AND cbd.`date_from` = \''.pSQL($dateFrom).'\' AND cbd.`date_to` = \''.pSQL($dateTo).'\'';
|
||||
}
|
||||
if ($idRoom) {
|
||||
$sql .= ' AND cbd.`id_room`='.(int) $idRoom;
|
||||
}
|
||||
if ($htlCartBookingId) {
|
||||
$sql .= ' AND cbd.`id`='.(int) $htlCartBookingId;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user