Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed: Invalid auto-added service prices when multiple rooms are added in cart or service is diabled or removed from catalog. #1203

Merged
merged 9 commits into from
Sep 12, 2024
11 changes: 4 additions & 7 deletions controllers/admin/AdminCartsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1114,14 +1114,11 @@ public function ajaxProcessGetRoomTypeCartDemands()
$dateTo,
$idRoom
)) {
$selectedRoomServiceProduct['selected_service'] = $objRoomTypeServiceProductCartDetail->getServiceProductsInCart(
$idCart,
0,
0,
0,
0,
0,
$selectedRoomServiceProduct['selected_service'] = $objRoomTypeServiceProductCartDetail->getRoomServiceProducts(
$selectedRoomServiceProduct['id'],
0,
null,
null
);
}
$this->context->smarty->assign(array(
Expand Down
13 changes: 1 addition & 12 deletions controllers/admin/AdminOrdersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4514,18 +4514,7 @@ public function ajaxProcessAddProductOnOrder()
$objRoomTypeServiceProduct = new RoomTypeServiceProduct();
$objRoomTypeServiceProductPrice = new RoomTypeServiceProductPrice();
$objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail();
if ($services = $objRoomTypeServiceProductCartDetail->getServiceProductsInCart(
$objCartBookingData->id_cart,
0,
0,
0,
0,
0,
$objCartBookingData->id,
0,
null,
1
)) {
if ($services = $objRoomTypeServiceProductCartDetail->getRoomServiceProducts($objCartBookingData->id, 0, null, 1)) {
foreach ($services as $service) {
$insertedServiceProductIdOrderDetail = $objBookingDetail->getLastInsertedServiceIdOrderDetail($order->id, $service['id_product']);
$numDays = 1;
Expand Down
11 changes: 4 additions & 7 deletions controllers/front/OrderOpcController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1032,14 +1032,11 @@ public function getRoomTypeBookingServices()
$roomTypeServiceProducts = $objRoomTypeServiceProduct->getServiceProductsData($idProduct, 1, 0, true, 1);
$cartRooms = $objCartBookingData->getHotelCartRoomsInfoByRoomType($this->context->cart->id, $idProduct,$dateFrom, $dateTo);
foreach($cartRooms as &$room) {
$room['selected_service'] = $objRoomTypeServiceProductCartDetail->getServiceProductsInCart(
$room['id_cart'],
$room['selected_service'] = $objRoomTypeServiceProductCartDetail->getRoomServiceProducts(
$room['id'],
0,
0,
0,
0,
0,
$room['id']
null,
null
);
}
$this->context->smarty->assign(array(
Expand Down
181 changes: 93 additions & 88 deletions modules/hotelreservationsystem/classes/HotelCartBookingData.php

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -718,32 +718,54 @@ public static function getRoomTypeTotalPrice(
}
}
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_guest,
$use_reduc
)) {
foreach($servicesWithTax as $service) {
$totalPrice['total_price_tax_incl'] += Tools::processPriceRounding($service['price']);
if ($id_cart && $id_room) {
$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_guest,
$use_reduc
)) {
foreach($servicesWithoutTax as $service) {
$totalPrice['total_price_tax_excl'] += Tools::processPriceRounding($service['price']);

if (isset($selectedServices)) {
$totalPrice['total_price_tax_incl'] += $selectedServices['total_price_tax_incl'];
$totalPrice['total_price_tax_excl'] += $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']);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,12 @@ public function isRoomTypeLinkedWithProduct($idProductRoomType, $idServiceProduc
return Db::getInstance()->getValue($sql);
}

public static function getAutoAddServices($idProduct, $dateFrom = null, $dateTo = null, $priceAdditionType = null, $useTax = null, $idCart = 0, $idGuest = 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) {
$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.')';
}
$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` = '.$priceAdditionType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ public function addServiceProductInCart(
return false;
}

public function removeServiceProductByIdHtlCartBooking($htlCartBookingId)
public function removeServiceProductByIdHtlCartBooking($htlCartBookingId, $idService = 0)
{
if ($stadardProductsData = Db::getInstance()->executeS(
'SELECT * FROM `' . _DB_PREFIX_ . 'htl_room_type_service_product_cart_detail`
WHERE `htl_cart_booking_id` = ' . (int)$htlCartBookingId
WHERE `htl_cart_booking_id` = ' . (int)$htlCartBookingId.
($idService? ' AND `id_product` = '.(int)$idService : '')
)) {
foreach ($stadardProductsData as $product) {
if (Validate::isLoadedObject(
Expand Down Expand Up @@ -164,9 +165,6 @@ public function getServiceProductsTotalInCart(
);
}

/**
* @deprecated since 1.6.1 use getServiceProductsInCart() instead
*/
public function getRoomServiceProducts(
$htlCartBookingId,
$idLang = 0,
Expand All @@ -192,7 +190,7 @@ public function getRoomServiceProducts(
);

if (isset($selectedServiceProducts[$htlCartBookingId]['selected_products_info'])) {
return $selectedServiceProducts;
return $selectedServiceProducts[$htlCartBookingId]['selected_products_info'];
}
}

Expand All @@ -211,7 +209,8 @@ public function getServiceProductsInCart(
$useTax = null,
$autoAddToCart = 0,
$id_address = null,
$priceAdditionType = null
$priceAdditionType = null,
$idRoom = 0
) {
if ($useTax === null)
$useTax = Product::$_taxCalculationMethod == PS_TAX_EXC ? false : true;
Expand Down Expand Up @@ -256,6 +255,9 @@ public function getServiceProductsInCart(
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;
}
Expand Down Expand Up @@ -504,6 +506,16 @@ public function updateCartServiceProduct(
return false;
}

public function getAllServiceProduct($idCart)
{
return Db::getInstance()->executeS(
'SELECT spcd.*, cbd.`id_product` as `id_product_room_type`, cbd.`id_room`, cbd.`id_hotel`, cbd.`date_from`, cbd.`date_to` FROM `' . _DB_PREFIX_ . 'htl_room_type_service_product_cart_detail` spcd
INNER JOIN `'._DB_PREFIX_.'htl_cart_booking_data` cbd
ON(spcd.`htl_cart_booking_id` = cbd.`id`)
WHERE spcd.`id_cart` = ' . (int)$idCart
);
}

public static function validateServiceProductsInCart()
{
$context = Context::getContext();
Expand Down