From 657b053d0dccc587842ffa77c30f58c2b51007eb Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Wed, 26 Feb 2025 19:28:17 +0530 Subject: [PATCH] Updated: When a service or room is deleted from the order, it will now also be removed from the cart. --- .../controllers/carts/helpers/view/view.tpl | 12 +++-- controllers/admin/AdminCartsController.php | 36 +++++++++---- controllers/admin/AdminOrdersController.php | 52 ++++++++++++++++++- .../classes/HotelCartBookingData.php | 7 ++- .../RoomTypeServiceProductCartDetail.php | 7 ++- .../RoomTypeServiceProductOrderDetail.php | 4 +- 6 files changed, 98 insertions(+), 20 deletions(-) diff --git a/admin/themes/default/template/controllers/carts/helpers/view/view.tpl b/admin/themes/default/template/controllers/carts/helpers/view/view.tpl index 41f4ee2fe..09decd44b 100644 --- a/admin/themes/default/template/controllers/carts/helpers/view/view.tpl +++ b/admin/themes/default/template/controllers/carts/helpers/view/view.tpl @@ -109,7 +109,7 @@ {displayWtPriceWithCurrency price=$room['feature_price_tax_excl'] currency=$currency} - {if (isset($room['extra_demands']) && $room['extra_demands']) || (isset($room['additional_service']) && $room['additional_service'])} + {if (isset($room['selected_demands']) && $room['selected_demands']) || (isset($room['selected_services']) && $room['selected_services'])} {displayWtPriceWithCurrency price=($room['demand_price'] + $room['additional_service_price'] + $room['additional_services_auto_add_price'])|escape:'html':'UTF-8' currency=$currency} @@ -118,7 +118,7 @@ {/if} - {if (isset($room['extra_demands']) && $room['extra_demands']) || (isset($room['additional_service']) && $room['additional_service'])} + {if (isset($room['selected_demands']) && $room['selected_demands']) || (isset($room['selected_services']) && $room['selected_services'])} {displayWtPriceWithCurrency price=($room['amt_with_qty'] + $room['additional_services_auto_add_price'] + $room['demand_price'] + $room['additional_service_price'])|escape:'html':'UTF-8' currency=$currency} {else} {displayWtPriceWithCurrency price=$room['amt_with_qty']|escape:'html':'UTF-8' currency=$currency} @@ -166,7 +166,13 @@
-

{if isset($roomDemand['adv_option']) && $roomDemand['adv_option']}{convertPrice price = $roomDemand['adv_option'][$idGlobalDemand]['price']|escape:'html':'UTF-8'}{else}{convertPrice price = $roomDemand['price']|escape:'html':'UTF-8'}{/if}

+

+ {if isset($roomDemand['adv_option']) && $roomDemand['adv_option']} + {convertPrice price = $roomDemand['adv_option'][$demand['id_option']]['price']|escape:'html':'UTF-8'} + {else} + {convertPrice price = $roomDemand['price']|escape:'html':'UTF-8'} + {/if} +

{/if} diff --git a/controllers/admin/AdminCartsController.php b/controllers/admin/AdminCartsController.php index 2ce84593f..69e2d671c 100644 --- a/controllers/admin/AdminCartsController.php +++ b/controllers/admin/AdminCartsController.php @@ -302,6 +302,31 @@ class AdminCartsControllerCore extends AdminController $product['image'] = (isset($image['id_image']) ? ImageManager::thumbnail(_PS_IMG_DIR_.'p/'.$image_product->getExistingImgPath().'.jpg', 'product_mini_'.(int)$product['id_product'].(isset($product['id_product_attribute']) ? '_'.(int)$product['id_product_attribute'] : '').'.jpg', 45, 'jpg') : '--'); } + // by webkul to show rooms available in the cart + $cartHtlData = array(); + $objHotelCartBookingData = new HotelCartBookingData(); + $objHotelRoomType = new HotelRoomType(); + if ($cartHtlData = $objHotelCartBookingData->getCartFormatedBookinInfoByIdCart((int) $cart->id)) { + foreach ($cartHtlData as $key => $value) { + $cartHtlData[$key]['room_type_info'] = $objHotelRoomType->getRoomTypeInfoByIdProduct($value['id_product']); + if (isset($value['selected_services']) && $value['selected_services']) { + foreach ($value['selected_services'] as $service) { + if ($service['id_cart'] != $value['id_cart']) { + if ($tax_calculation_method == PS_TAX_EXC) { + $total_price += ($service['quantity'] * $service['total_price_tax_excl']); + $total_products += ($service['quantity'] * $service['total_price_tax_excl']); + } else { + $total_price += ($service['quantity'] * $service['total_price_tax_incl']); + $total_products += ($service['quantity'] * $service['total_price_tax_incl']); + } + } + } + } + } + } else { + $cartHtlData = array(); + } + $helper = new HelperKpi(); $helper->id = 'box-kpi-cart'; $helper->icon = 'icon-shopping-cart'; @@ -310,17 +335,6 @@ class AdminCartsControllerCore extends AdminController $helper->subtitle = sprintf($this->l('Cart #%06d', null, null, false), $cart->id); $helper->value = Tools::displayPrice($total_price, $currency); $kpi = $helper->generate(); - // by webkul to show rooms available in the cart - $cartHtlData = array(); - $objHotelCartBookingData = new HotelCartBookingData(); - $objHotelRoomType = new HotelRoomType(); - if ($cartHtlData = $objHotelCartBookingData->getCartFormatedBookinInfoByIdCart((int) $cart->id)) { - foreach ($cartHtlData as $key => $value) { - $cartHtlData[$key]['room_type_info'] = $objHotelRoomType->getRoomTypeInfoByIdProduct($value['id_product']); - } - } else { - $cartHtlData = array(); - } //end $this->tpl_view_vars = array( 'cart_htl_data' => $cartHtlData,//by webkul hotel rooms in order data diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index b852574d7..1ea20ab15 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -5442,6 +5442,15 @@ class AdminOrdersControllerCore extends AdminController $idHotelBooking ); + //This is added to remove the services from the cart along with room deletion process. + $objHotelCartBookingData = new HotelCartBookingData(); + $roomHtlCartInfo = $objHotelCartBookingData->getRoomRowByIdProductIdRoomInDateRange( + $objBookingDetail->id_cart, + $objBookingDetail->id_product, + $objBookingDetail->date_from, + $objBookingDetail->date_to, + $objBookingDetail->id_room + ); /*$totalProductPriceBeforeTE = $order_detail->total_price_tax_excl; $totalProductPriceBeforeTI = $order_detail->total_price_tax_incl;*/ @@ -5476,6 +5485,7 @@ class AdminOrdersControllerCore extends AdminController $res &= $order_detail->update(); } // update order detail for selected aditional services + $objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail(); foreach ($selectedAdditonalServices['additional_services'] as $service) { $serviceOrderDetail = new OrderDetail($service['id_order_detail']); @@ -5496,6 +5506,21 @@ class AdminOrdersControllerCore extends AdminController // Save order detail $res &= $serviceOrderDetail->update(); } + + if (isset($roomHtlCartInfo['id'])) { + if ($id_room_type_service_product_cart_detail = $objRoomTypeServiceProductCartDetail->alreadyExists( + $service['id_product'], + $service['id_cart'], + $roomHtlCartInfo['id'] + )) { + $objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail((int) $id_room_type_service_product_cart_detail); + $serviceQuantity = $objRoomTypeServiceProductCartDetail->quantity; + if ($objRoomTypeServiceProductCartDetail->delete()) { + $objCart = new Cart($service['id_cart']); + $objCart->updateQty((int)abs($serviceQuantity), $service['id_product'], null, false, 'down'); + } + } + } } /*End*/ @@ -5574,7 +5599,9 @@ class AdminOrdersControllerCore extends AdminController $objBookingDetail->id_product, $objBookingDetail->id_room, $objBookingDetail->date_from, - $objBookingDetail->date_to + $objBookingDetail->date_to, + 1, + 1 ); $objBookingDetail->delete(); @@ -6493,8 +6520,31 @@ class AdminOrdersControllerCore extends AdminController $quantity = $objRoomTypeServiceProductOrderDetail->quantity; $res = true; $objHotelBookingDetail = new HotelBookingDetail($objRoomTypeServiceProductOrderDetail->id_htl_booking_detail); + $idServiceProduct = $objRoomTypeServiceProductOrderDetail->id_product; + $objHotelCartBookingData = new HotelCartBookingData(); + $roomHtlCartInfo = $objHotelCartBookingData->getRoomRowByIdProductIdRoomInDateRange( + $objHotelBookingDetail->id_cart, + $objHotelBookingDetail->id_product, + $objHotelBookingDetail->date_from, + $objHotelBookingDetail->date_to, + $objHotelBookingDetail->id_room + ); + $objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail(); if ($res &= $objRoomTypeServiceProductOrderDetail->delete()) { + if (isset($roomHtlCartInfo['id'])) { + if ($id_room_type_service_product_cart_detail = $objRoomTypeServiceProductCartDetail->alreadyExists( + $idServiceProduct, + $objRoomTypeServiceProductOrderDetail->id_cart, + $roomHtlCartInfo['id'] + )) { + $objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail($id_room_type_service_product_cart_detail); + if ($objRoomTypeServiceProductCartDetail->delete()) { + $objCart = new Cart($objRoomTypeServiceProductOrderDetail->id_cart); + $objCart->updateQty((int)abs($quantity), $objRoomTypeServiceProductOrderDetail->id_product, null, false, 'down'); + } + } + } $order = new Order($objRoomTypeServiceProductOrderDetail->id_order); if ($quantity >= $objOrderDetail->product_quantity) { $objOrderDetail->delete(); diff --git a/modules/hotelreservationsystem/classes/HotelCartBookingData.php b/modules/hotelreservationsystem/classes/HotelCartBookingData.php index 7f8a3e151..9258f4cb1 100644 --- a/modules/hotelreservationsystem/classes/HotelCartBookingData.php +++ b/modules/hotelreservationsystem/classes/HotelCartBookingData.php @@ -346,7 +346,8 @@ class HotelCartBookingData extends ObjectModel $idRoom = 0, $dateFrom = 0, $dateTo = 0, - $updPsCart = 1 + $updPsCart = 1, + $excludeOrdered = 0 ) { $where = '1'; if ($idCart) { @@ -365,7 +366,9 @@ class HotelCartBookingData extends ObjectModel $where .= ' AND `date_to`=\''.pSQL($dateTo).'\''; } // we have to delete only rows which order is not created - $where .= ' AND `id_order`= 0'; + if (!$excludeOrdered) { + $where .= ' AND `id_order`= 0'; + } // If rooms is deleting from cart the we need to delete the ps_cart quantity of the product from table // if product will delete the prestashop will handle $numRooms = 0; diff --git a/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php b/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php index fec2fed2c..753d4ec3e 100644 --- a/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php +++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php @@ -217,7 +217,7 @@ class RoomTypeServiceProductCartDetail extends ObjectModel $idLang = Context::getContext()->language->id; - $sql = 'SELECT rscd.`id_product`, rscd.`quantity`, cbd.`id_cart`, cbd.`id` as `htl_cart_booking_id` , + $sql = 'SELECT rscd.`id_product`, rscd.`quantity`, cbd.`id_cart`, rscd.`id_cart` as service_id_cart, cbd.`id` as `htl_cart_booking_id` , cbd.`id_product` as `room_type_id_product`, cbd.`adults`, cbd.`children`, cbd.`date_from`, cbd.`date_to`'; if (!$getTotalPrice) { $sql .= ', pl.`name`, cbd.`id_guest`, cbd.`id_customer`, p.`auto_add_to_cart`, p.`price_addition_type`, @@ -233,7 +233,8 @@ class RoomTypeServiceProductCartDetail extends ObjectModel $sql .= ' LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.`id_product` = p.`id_product` AND pl.`id_lang` = '.(int)$idLang.')'; } - $sql .= ' WHERE 1'; + + $sql .= ' WHERE 1 AND rscd.`id_product`!=0'; if (!is_null($autoAddToCart)) { $sql .= ' AND p.`auto_add_to_cart` = '. (int)$autoAddToCart; @@ -334,6 +335,7 @@ class RoomTypeServiceProductCartDetail extends ObjectModel 'name' => $product['name'], 'quantity' => $product['quantity'], 'auto_add_to_cart' => $product['auto_add_to_cart'], + 'id_cart' => $product['service_id_cart'], 'allow_multiple_quantity' => $product['allow_multiple_quantity'], 'price_addition_type' => $product['price_addition_type'], 'price_calculation_method' => $product['price_calculation_method'], @@ -449,6 +451,7 @@ class RoomTypeServiceProductCartDetail extends ObjectModel 'quantity' => $product['quantity'], 'auto_add_to_cart' => $product['auto_add_to_cart'], 'allow_multiple_quantity' => $product['allow_multiple_quantity'], + 'id_cart' => $product['service_id_cart'], 'price_addition_type' => $product['price_addition_type'], 'price_calculation_method' => $product['price_calculation_method'], 'unit_price_tax_excl' => ($objRoomTypeServiceProductPrice->getServicePrice( diff --git a/modules/hotelreservationsystem/classes/RoomTypeServiceProductOrderDetail.php b/modules/hotelreservationsystem/classes/RoomTypeServiceProductOrderDetail.php index d8a236f66..af16ab91b 100644 --- a/modules/hotelreservationsystem/classes/RoomTypeServiceProductOrderDetail.php +++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProductOrderDetail.php @@ -247,6 +247,7 @@ class RoomTypeServiceProductOrderDetail extends ObjectModel 'id_order_detail' => $product['id_order_detail'], 'id_product' => $product['id_product'], 'name' => $product['name'], + 'id_cart' => $product['id_cart'], 'quantity' => $product['quantity'], 'allow_multiple_quantity' => $product['product_allow_multiple_quantity'], 'max_quantity' => $product['max_quantity'], @@ -272,6 +273,7 @@ class RoomTypeServiceProductOrderDetail extends ObjectModel 'id_order_detail' => $product['id_order_detail'], 'id_product' => $product['id_product'], 'name' => $product['name'], + 'id_cart' => $product['id_cart'], 'quantity' => $product['quantity'], 'allow_multiple_quantity' => $product['product_allow_multiple_quantity'], 'max_quantity' => $product['max_quantity'], @@ -314,4 +316,4 @@ class RoomTypeServiceProductOrderDetail extends ObjectModel // delete entry from order detail table. return parent::delete(); } -} \ No newline at end of file +}