From f0d6e23ea190bfabb99bb778104755efb33a1cba Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Mon, 11 Mar 2024 10:50:37 +0530 Subject: [PATCH 1/5] Update order is now split according to booking dates --- classes/Cart.php | 161 ++++++++++++------ classes/PaymentModule.php | 9 +- .../classes/HotelCartBookingData.php | 10 +- .../RoomTypeServiceProductCartDetail.php | 5 +- 4 files changed, 125 insertions(+), 60 deletions(-) diff --git a/classes/Cart.php b/classes/Cart.php index 66c60bb88..516a296c0 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -1803,7 +1803,12 @@ class CartCore extends ObjectModel $with_taxes, null ); - } else if ($roomTypesByIdProduct = $objCartBookingData->getCartInfoIdCartIdProduct($this->id, $product['id_product'])) { + } else if ($roomTypesByIdProduct = $objCartBookingData->getCartInfoIdCartIdProduct( + $this->id, + $product['id_product'], + isset($product['date_from']) ? $product['date_from'] : 0, + isset($product['date_to']) ? $product['date_to'] : 0, + )) { // by webkul to calculate rates of the product from hotelreservation syatem tables with feature prices.... $totalPriceByProduct = 0; $priceDisplay = Group::getPriceDisplayMethod(Group::getCurrent()->id); @@ -2350,28 +2355,60 @@ class CartCore extends ObjectModel foreach ($packages as $id_package => $package) { foreach ($package['product_list'] as $product) { if ($product['booking_product']) { - $productInfo = $objRoomType->getRoomTypeInfoByIdProduct($product['id_product']); - $idHotel = $productInfo['id_hotel'] ? $productInfo['id_hotel'] : 0; + if ($roomsBookingDetails = $objHtlCartBookingData->getOnlyCartBookingData( + $this->id, + $this->id_guest, + $product['id_product'] + )) { + $productInfo = $objRoomType->getRoomTypeInfoByIdProduct($product['id_product']); + $idHotel = $productInfo['id_hotel'] ? $productInfo['id_hotel'] : 0; + foreach ($roomsBookingDetails as $roomBooking) { + $dateJoin = strtotime($roomBooking['date_from']).strtotime($roomBooking['date_to']); + if (!isset($orderPackage[$id_address][$idHotel][$dateJoin])) { + $orderPackage[$id_address][$idHotel][$dateJoin]['product_list'] = array(); - $orderPackage[$id_address][$idHotel]['product_list'][] = $product; - $orderPackage[$id_address][$idHotel]['id_hotel'] = $idHotel; - if (!isset($orderPackage[$id_address][$idHotel]['id_hotel'])) { - $orderPackage[$id_address][$idHotel]['id_hotel'] = $productInfo['id_hotel']; - } - if (!isset($orderPackage[$id_address][$idHotel]['carrier_list'])) { - $orderPackage[$id_address][$idHotel]['carrier_list'] = $product['carrier_list']; - } else { - $orderPackage[$id_address][$idHotel]['carrier_list'] = array_intersect($orderPackage[$id_address][$idHotel]['carrier_list'], $product['carrier_list']); - } - if (!isset($orderPackage[$id_address][$idHotel]['warehouse_list'])) { - $orderPackage[$id_address][$idHotel]['warehouse_list'] = $package['warehouse_list']; - } - if (!isset($orderPackage[$id_address][$idHotel]['id_warehouse'])) { - $orderPackage[$id_address][$idHotel]['id_warehouse'] = $package['id_warehouse']; - } - if (isset($package['id_carrier'])) { - if (!isset($orderPackage[$id_address][$idHotel]['id_carrier'])) { - $orderPackage[$id_address][$idHotel]['id_carrier'] = $package['id_carrier']; + $orderPackage[$id_address][$idHotel][$dateJoin]['id_hotel'] = $idHotel; + if (!isset($orderPackage[$id_address][$idHotel][$dateJoin]['id_hotel'])) { + $orderPackage[$id_address][$idHotel][$dateJoin]['id_hotel'] = $productInfo['id_hotel']; + } + if (!isset($orderPackage[$id_address][$idHotel][$dateJoin]['carrier_list'])) { + $orderPackage[$id_address][$idHotel][$dateJoin]['carrier_list'] = $product['carrier_list']; + } else { + $orderPackage[$id_address][$idHotel][$dateJoin]['carrier_list'] = array_intersect($orderPackage[$id_address][$idHotel][$dateJoin]['carrier_list'], $product['carrier_list']); + } + if (!isset($orderPackage[$id_address][$idHotel][$dateJoin]['warehouse_list'])) { + $orderPackage[$id_address][$idHotel][$dateJoin]['warehouse_list'] = $package['warehouse_list']; + } + if (!isset($orderPackage[$id_address][$idHotel][$dateJoin]['id_warehouse'])) { + $orderPackage[$id_address][$idHotel][$dateJoin]['id_warehouse'] = $package['id_warehouse']; + } + if (isset($package['id_carrier'])) { + if (!isset($orderPackage[$id_address][$idHotel][$dateJoin]['id_carrier'])) { + $orderPackage[$id_address][$idHotel][$dateJoin]['id_carrier'] = $package['id_carrier']; + } + } + } + $product['cart_quantity'] = HotelHelper::getNumberOfDays( + $roomBooking['date_from'], + $roomBooking['date_to'] + ); + $product['date_from'] = $roomBooking['date_from']; + $product['date_to'] = $roomBooking['date_to']; + + $roomTotalPrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( + $product['id_product'], + $roomBooking['date_from'], + $roomBooking['date_to'], + 0, + Group::getCurrent()->id, + $this->id, + $this->id_guest, + 0, + 0 + ); + $product['total_wt'] = $roomTotalPrice['total_price_tax_incl']; + $product['total'] = $roomTotalPrice['total_price_tax_excl']; + $orderPackage[$id_address][$idHotel][$dateJoin]['product_list'][] = $product; } } } else { @@ -2379,44 +2416,60 @@ class CartCore extends ObjectModel if ($selectedServiceProducts = $objRoomTypeServiceProductCartDetail->getServiceProductsInCart($this->id, $product['id_product'], 0, 0, 0, 0, 0, 0, null, null)) { $array = array(); foreach($selectedServiceProducts as $selectedProduct) { - if (isset($array[$selectedProduct['id_hotel']])) { - $array[$selectedProduct['id_hotel']]['quantity'] += $selectedProduct['quantity']; - $array[$selectedProduct['id_hotel']]['total_price_tax_excl'] += $selectedProduct['total_price_tax_excl']; - $array[$selectedProduct['id_hotel']]['total_price_tax_incl'] += $selectedProduct['total_price_tax_incl']; + $dateJoin = strtotime($selectedProduct['date_from']).strtotime($selectedProduct['date_to']); + if (isset($array[$selectedProduct['id_hotel']][$dateJoin])) { + $array[$selectedProduct['id_hotel']][$dateJoin]['total_price_tax_excl'] += $selectedProduct['total_price_tax_excl']; + $array[$selectedProduct['id_hotel']][$dateJoin]['total_price_tax_incl'] += $selectedProduct['total_price_tax_incl']; } else { - $array[$selectedProduct['id_hotel']] = array( - 'quantity' => $selectedProduct['quantity'], + $array[$selectedProduct['id_hotel']][$dateJoin] = array( 'id_hotel' => $selectedProduct['id_hotel'], + 'quantity' => 0, + 'date_from' => $selectedProduct['date_from'], + 'date_to' => $selectedProduct['date_to'], 'unit_price_tax_incl' => $selectedProduct['unit_price_tax_incl'], 'total_price_tax_excl' => $selectedProduct['total_price_tax_excl'], 'total_price_tax_incl' => $selectedProduct['total_price_tax_incl'], ); } - } - foreach($array as $selectedProduct) { - $product['cart_quantity'] = $selectedProduct['quantity']; - $product['total'] = $selectedProduct['total_price_tax_excl']; - $product['total_wt'] = $selectedProduct['total_price_tax_incl']; - $product['price_wt'] = $selectedProduct['unit_price_tax_incl']; - $product['id_hotel'] = $selectedProduct['id_hotel']; - $orderPackage[$id_address][$selectedProduct['id_hotel']]['product_list'][] = $product; - if (!isset($orderPackage[$id_address][$selectedProduct['id_hotel']]['id_hotel'])) { - $orderPackage[$id_address][$selectedProduct['id_hotel']]['id_hotel'] = $selectedProduct['id_hotel']; - } - if (!isset($orderPackage[$id_address][$selectedProduct['id_hotel']]['carrier_list'])) { - $orderPackage[$id_address][$selectedProduct['id_hotel']]['carrier_list'] = $product['carrier_list']; + if (Product::PRICE_CALCULATION_METHOD_PER_DAY == $selectedProduct['price_calculation_method']) { + $numDays = HotelHelper::getNumberOfDays( + $selectedProduct['date_from'], + $selectedProduct['date_to'] + ); + $array[$selectedProduct['id_hotel']][$dateJoin]['quantity'] += ($selectedProduct['quantity'] * $numDays); } else { - $orderPackage[$id_address][$selectedProduct['id_hotel']]['carrier_list'] = array_intersect($orderPackage[$id_address][$selectedProduct['id_hotel']]['carrier_list'], $product['carrier_list']); + $array[$selectedProduct['id_hotel']][$dateJoin]['quantity'] += $selectedProduct['quantity']; + } - if (!isset($orderPackage[$id_address][$selectedProduct['id_hotel']]['warehouse_list'])) { - $orderPackage[$id_address][$selectedProduct['id_hotel']]['warehouse_list'] = $package['warehouse_list']; - } - if (!isset($orderPackage[$id_address][$selectedProduct['id_hotel']]['id_warehouse'])) { - $orderPackage[$id_address][$selectedProduct['id_hotel']]['id_warehouse'] = $package['id_warehouse']; - } - if (isset($package['id_carrier'])) { - if (!isset($orderPackage[$id_address][$selectedProduct['id_hotel']]['id_carrier'])) { - $orderPackage[$id_address][$selectedProduct['id_hotel']]['id_carrier'] = $package['id_carrier']; + } + foreach($array as $selectedProductDateWise) { + foreach($selectedProductDateWise as $dateJoin => $selectedProduct) { + $product['cart_quantity'] = $selectedProduct['quantity']; + $product['total'] = $selectedProduct['total_price_tax_excl']; + $product['total_wt'] = $selectedProduct['total_price_tax_incl']; + $product['price_wt'] = $selectedProduct['unit_price_tax_incl']; + $product['id_hotel'] = $selectedProduct['id_hotel']; + $product['date_from'] = $selectedProduct['date_from']; + $product['date_to'] = $selectedProduct['date_to']; + $orderPackage[$id_address][$selectedProduct['id_hotel']][$dateJoin]['product_list'][] = $product; + if (!isset($orderPackage[$id_address][$selectedProduct['id_hotel']][$dateJoin]['id_hotel'])) { + $orderPackage[$id_address][$selectedProduct['id_hotel']][$dateJoin]['id_hotel'] = $selectedProduct['id_hotel']; + } + if (!isset($orderPackage[$id_address][$selectedProduct['id_hotel']][$dateJoin]['carrier_list'])) { + $orderPackage[$id_address][$selectedProduct['id_hotel']][$dateJoin]['carrier_list'] = $product['carrier_list']; + } else { + $orderPackage[$id_address][$selectedProduct['id_hotel']][$dateJoin]['carrier_list'] = array_intersect($orderPackage[$id_address][$selectedProduct['id_hotel']][$dateJoin]['carrier_list'], $product['carrier_list']); + } + if (!isset($orderPackage[$id_address][$selectedProduct['id_hotel']][$dateJoin]['warehouse_list'])) { + $orderPackage[$id_address][$selectedProduct['id_hotel']][$dateJoin]['warehouse_list'] = $package['warehouse_list']; + } + if (!isset($orderPackage[$id_address][$selectedProduct['id_hotel']][$dateJoin]['id_warehouse'])) { + $orderPackage[$id_address][$selectedProduct['id_hotel']][$dateJoin]['id_warehouse'] = $package['id_warehouse']; + } + if (isset($package['id_carrier'])) { + if (!isset($orderPackage[$id_address][$selectedProduct['id_hotel']][$dateJoin]['id_carrier'])) { + $orderPackage[$id_address][$selectedProduct['id_hotel']][$dateJoin]['id_carrier'] = $package['id_carrier']; + } } } } @@ -2467,8 +2520,10 @@ class CartCore extends ObjectModel } foreach ($orderPackage as $id_address => $packageByAddress) { $numHotels += count($packageByAddress); - foreach ($packageByAddress as $id_package => $package) { - $hotelWisePackageList[$id_address][] = $package; + foreach ($packageByAddress as $id_package => $packageByDate) { + foreach ($packageByDate as $package) { + $hotelWisePackageList[$id_address][] = $package; + } } } // add sevice products as new package if there are multiple hotels in cart diff --git a/classes/PaymentModule.php b/classes/PaymentModule.php index 5e5fb6f52..ad29e36c6 100644 --- a/classes/PaymentModule.php +++ b/classes/PaymentModule.php @@ -786,8 +786,9 @@ abstract class PaymentModuleCore extends Module foreach ($order->product_list as $product) { $objCartBookingData = new HotelCartBookingData(); $idProduct = $product['id_product']; - $cartBookingData = $objCartBookingData->getOnlyCartBookingData($this->context->cart->id, $this->context->cart->id_guest, $idProduct); - if ($cartBookingData) { + if ($product['booking_product'] + && $cartBookingData = $objCartBookingData->getCartInfoIdCartIdProduct($this->context->cart->id, $idProduct, $product['date_from'], $product['date_to']) + ) { foreach ($cartBookingData as $bookingInfo) { $objCartBookingData = new HotelCartBookingData($bookingInfo['id']); $objCartBookingData->id_order = $order->id; @@ -941,8 +942,8 @@ abstract class PaymentModuleCore extends Module $product['id_product'], isset($product['id_hotel']) ? $product['id_hotel'] : 0, 0, - 0, - 0, + $product['date_from'], + $product['date_to'], 0, 0, null, diff --git a/modules/hotelreservationsystem/classes/HotelCartBookingData.php b/modules/hotelreservationsystem/classes/HotelCartBookingData.php index 11ae5e14c..e68dad83c 100644 --- a/modules/hotelreservationsystem/classes/HotelCartBookingData.php +++ b/modules/hotelreservationsystem/classes/HotelCartBookingData.php @@ -1107,9 +1107,15 @@ class HotelCartBookingData extends ObjectModel * * @return [array/false] [returns all entries if data found else return false] */ - public function getCartInfoIdCartIdProduct($id_cart, $id_product) + public function getCartInfoIdCartIdProduct($id_cart, $id_product, $date_from = false, $date_to = false) { - return Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'htl_cart_booking_data` WHERE `id_cart`='.(int) $id_cart.' AND `id_product`='.(int) $id_product); + $sql = 'SELECT * + FROM `'._DB_PREFIX_.'htl_cart_booking_data` + WHERE `id_cart`='.(int) $id_cart.' AND `id_product`='.(int) $id_product; + if ($date_from && $date_to) { + $sql .= ' AND `date_from` = \''.pSQL($date_from).'\' AND `date_to` = \''.pSQL($date_to).'\''; + } + return Db::getInstance()->executeS($sql); } /** diff --git a/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php b/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php index 94c40c1ec..e535a126a 100644 --- a/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php +++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php @@ -328,7 +328,7 @@ class RoomTypeServiceProductCartDetail extends ObjectModel 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`, - cbd.`id_hotel`, cbd.`id_room`, cbd.`date_from`, cbd.`date_to`, cbd.`is_refunded`'; + p.`price_calculation_method`, cbd.`id_hotel`, cbd.`id_room`, cbd.`date_from`, cbd.`date_to`, cbd.`is_refunded`'; } $sql .= ' FROM `'._DB_PREFIX_.'htl_cart_booking_data` cbd LEFT JOIN `'._DB_PREFIX_.'htl_room_type_service_product_cart_detail` rscd @@ -401,6 +401,7 @@ class RoomTypeServiceProductCartDetail extends ObjectModel 'quantity' => $product['quantity'], 'auto_add_to_cart' => $product['auto_add_to_cart'], 'price_addition_type' => $product['price_addition_type'], + 'price_calculation_method' => $product['price_calculation_method'], 'unit_price_tax_excl' => $objRoomTypeServiceProductPrice->getServicePrice( (int)$product['id_product'], (int)$product['room_type_id_product'], @@ -472,6 +473,7 @@ class RoomTypeServiceProductCartDetail extends ObjectModel $selectedServiceProducts[$product['htl_cart_booking_id']]['quantity'] = $product['quantity']; $selectedServiceProducts[$product['htl_cart_booking_id']]['auto_add_to_cart'] = $product['auto_add_to_cart']; $selectedServiceProducts[$product['htl_cart_booking_id']]['price_addition_type'] = $product['price_addition_type']; + $selectedServiceProducts[$product['htl_cart_booking_id']]['price_calculation_method'] = $product['price_calculation_method']; $selectedServiceProducts[$product['htl_cart_booking_id']]['unit_price_tax_excl'] = $objRoomTypeServiceProductPrice->getServicePrice( (int)$product['id_product'], (int)$product['room_type_id_product'], @@ -499,6 +501,7 @@ class RoomTypeServiceProductCartDetail extends ObjectModel 'quantity' => $product['quantity'], 'auto_add_to_cart' => $product['auto_add_to_cart'], 'price_addition_type' => $product['price_addition_type'], + 'price_calculation_method' => $product['price_calculation_method'], 'unit_price_tax_excl' => $objRoomTypeServiceProductPrice->getServicePrice( (int)$product['id_product'], (int)$product['room_type_id_product'], From 761709d6c6af85605d078a23a10d025175d149c0 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Tue, 12 Mar 2024 10:24:17 +0530 Subject: [PATCH 2/5] update services price calculation in order split --- classes/Cart.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/Cart.php b/classes/Cart.php index 516a296c0..540c36ba5 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -1797,8 +1797,8 @@ class CartCore extends ObjectModel (int)$product['id_product'], isset($product['id_hotel']) ? $product['id_hotel'] : 0, 0, - 0, - 0, + isset($product['date_from']) ? $product['date_from'] : 0, + isset($product['date_to']) ? $product['date_to'] : 0, 0, $with_taxes, null From 993b41277e5f965e5332ebd81dfa36cfb3db9360 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Sun, 17 Mar 2024 13:01:53 +0530 Subject: [PATCH 3/5] resolve all room not showing in order confirmation page --- .../front/OrderConfirmationController.php | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/controllers/front/OrderConfirmationController.php b/controllers/front/OrderConfirmationController.php index 40955333f..c7af4835c 100644 --- a/controllers/front/OrderConfirmationController.php +++ b/controllers/front/OrderConfirmationController.php @@ -155,9 +155,6 @@ class OrderConfirmationControllerCore extends FrontController if (!empty($orderProducts)) { foreach ($orderProducts as $type_key => $type_value) { - if (in_array($type_value['product_id'], $processed_product)) { - continue; - } $processed_product[] = $type_value['product_id']; $product = new Product($type_value['product_id'], false, $this->context->language->id); @@ -372,13 +369,6 @@ class OrderConfirmationControllerCore extends FrontController } } - - if (!empty($cart_htl_data)) { - $this->context->smarty->assign('cart_htl_data', $cart_htl_data); - } - if (!empty($cart_service_products)) { - $this->context->smarty->assign('cart_service_products', $cart_service_products); - } } if (!$objCartOrder->hasInvoice()) { $orders_has_invoice = 0; @@ -402,6 +392,13 @@ class OrderConfirmationControllerCore extends FrontController } } + if (!empty($cart_htl_data)) { + $this->context->smarty->assign('cart_htl_data', $cart_htl_data); + } + if (!empty($cart_service_products)) { + $this->context->smarty->assign('cart_service_products', $cart_service_products); + } + $this->context->smarty->assign('orderTotalInfo', $orderTotalInfo); $this->context->smarty->assign('non_requested_rooms', $non_requested_rooms); $this->context->smarty->assign('orders_has_invoice', $orders_has_invoice); From bd03f138f5908c3d2b88d635822864c35edd7f0e Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Sun, 17 Mar 2024 15:22:30 +0530 Subject: [PATCH 4/5] optimized package hotel and date wise package list --- classes/Cart.php | 125 +++++++++++++++++++++++------------------------ 1 file changed, 61 insertions(+), 64 deletions(-) diff --git a/classes/Cart.php b/classes/Cart.php index bd2e1a615..b8e052c76 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -2363,28 +2363,28 @@ class CartCore extends ObjectModel $productInfo = $objRoomType->getRoomTypeInfoByIdProduct($product['id_product']); $idHotel = $productInfo['id_hotel'] ? $productInfo['id_hotel'] : 0; foreach ($roomsBookingDetails as $roomBooking) { - $dateJoin = strtotime($roomBooking['date_from']).strtotime($roomBooking['date_to']); - if (!isset($orderPackage[$id_address][$idHotel][$dateJoin])) { - $orderPackage[$id_address][$idHotel][$dateJoin]['product_list'] = array(); + $dateJoinKey = $idHotel.'-'.strtotime($roomBooking['date_from']).strtotime($roomBooking['date_to']); + if (!isset($orderPackage[$id_address][$dateJoinKey])) { + $orderPackage[$id_address][$dateJoinKey]['product_list'] = array(); - $orderPackage[$id_address][$idHotel][$dateJoin]['id_hotel'] = $idHotel; - if (!isset($orderPackage[$id_address][$idHotel][$dateJoin]['id_hotel'])) { - $orderPackage[$id_address][$idHotel][$dateJoin]['id_hotel'] = $productInfo['id_hotel']; + $orderPackage[$id_address][$dateJoinKey]['id_hotel'] = $idHotel; + if (!isset($orderPackage[$id_address][$dateJoinKey]['id_hotel'])) { + $orderPackage[$id_address][$dateJoinKey]['id_hotel'] = $productInfo['id_hotel']; } - if (!isset($orderPackage[$id_address][$idHotel][$dateJoin]['carrier_list'])) { - $orderPackage[$id_address][$idHotel][$dateJoin]['carrier_list'] = $product['carrier_list']; + if (!isset($orderPackage[$id_address][$dateJoinKey]['carrier_list'])) { + $orderPackage[$id_address][$dateJoinKey]['carrier_list'] = $product['carrier_list']; } else { - $orderPackage[$id_address][$idHotel][$dateJoin]['carrier_list'] = array_intersect($orderPackage[$id_address][$idHotel][$dateJoin]['carrier_list'], $product['carrier_list']); + $orderPackage[$id_address][$dateJoinKey]['carrier_list'] = array_intersect($orderPackage[$id_address][$dateJoinKey]['carrier_list'], $product['carrier_list']); } - if (!isset($orderPackage[$id_address][$idHotel][$dateJoin]['warehouse_list'])) { - $orderPackage[$id_address][$idHotel][$dateJoin]['warehouse_list'] = $package['warehouse_list']; + if (!isset($orderPackage[$id_address][$dateJoinKey]['warehouse_list'])) { + $orderPackage[$id_address][$dateJoinKey]['warehouse_list'] = $package['warehouse_list']; } - if (!isset($orderPackage[$id_address][$idHotel][$dateJoin]['id_warehouse'])) { - $orderPackage[$id_address][$idHotel][$dateJoin]['id_warehouse'] = $package['id_warehouse']; + if (!isset($orderPackage[$id_address][$dateJoinKey]['id_warehouse'])) { + $orderPackage[$id_address][$dateJoinKey]['id_warehouse'] = $package['id_warehouse']; } if (isset($package['id_carrier'])) { - if (!isset($orderPackage[$id_address][$idHotel][$dateJoin]['id_carrier'])) { - $orderPackage[$id_address][$idHotel][$dateJoin]['id_carrier'] = $package['id_carrier']; + if (!isset($orderPackage[$id_address][$dateJoinKey]['id_carrier'])) { + $orderPackage[$id_address][$dateJoinKey]['id_carrier'] = $package['id_carrier']; } } } @@ -2408,7 +2408,7 @@ class CartCore extends ObjectModel ); $product['total_wt'] = $roomTotalPrice['total_price_tax_incl']; $product['total'] = $roomTotalPrice['total_price_tax_excl']; - $orderPackage[$id_address][$idHotel][$dateJoin]['product_list'][] = $product; + $orderPackage[$id_address][$dateJoinKey]['product_list'][] = $product; } } } else { @@ -2416,12 +2416,12 @@ class CartCore extends ObjectModel if ($selectedServiceProducts = $objRoomTypeServiceProductCartDetail->getServiceProductsInCart($this->id, $product['id_product'], 0, 0, 0, 0, 0, 0, null, null)) { $array = array(); foreach($selectedServiceProducts as $selectedProduct) { - $dateJoin = strtotime($selectedProduct['date_from']).strtotime($selectedProduct['date_to']); - if (isset($array[$selectedProduct['id_hotel']][$dateJoin])) { - $array[$selectedProduct['id_hotel']][$dateJoin]['total_price_tax_excl'] += $selectedProduct['total_price_tax_excl']; - $array[$selectedProduct['id_hotel']][$dateJoin]['total_price_tax_incl'] += $selectedProduct['total_price_tax_incl']; + $dateJoinKey = $selectedProduct['id_hotel'].'-'.strtotime($selectedProduct['date_from']).strtotime($selectedProduct['date_to']); + if (isset($array[$dateJoinKey])) { + $array[$dateJoinKey]['total_price_tax_excl'] += $selectedProduct['total_price_tax_excl']; + $array[$dateJoinKey]['total_price_tax_incl'] += $selectedProduct['total_price_tax_incl']; } else { - $array[$selectedProduct['id_hotel']][$dateJoin] = array( + $array[$dateJoinKey] = array( 'id_hotel' => $selectedProduct['id_hotel'], 'quantity' => 0, 'date_from' => $selectedProduct['date_from'], @@ -2435,41 +2435,40 @@ class CartCore extends ObjectModel $selectedProduct['date_from'], $selectedProduct['date_to'] ); - $array[$selectedProduct['id_hotel']][$dateJoin]['quantity'] += ($selectedProduct['quantity'] * $numDays); + $array[$dateJoinKey]['quantity'] += ($selectedProduct['quantity'] * $numDays); } else { - $array[$selectedProduct['id_hotel']][$dateJoin]['quantity'] += $selectedProduct['quantity']; + $array[$dateJoinKey]['quantity'] += $selectedProduct['quantity']; } } - foreach($array as $selectedProductDateWise) { - foreach($selectedProductDateWise as $dateJoin => $selectedProduct) { - $product['cart_quantity'] = $selectedProduct['quantity']; - $product['total'] = $selectedProduct['total_price_tax_excl']; - $product['total_wt'] = $selectedProduct['total_price_tax_incl']; - $product['price_wt'] = $selectedProduct['total_price_tax_incl'] / $product['cart_quantity']; - $product['price'] = $selectedProduct['total_price_tax_excl'] / $product['cart_quantity']; - $product['id_hotel'] = $selectedProduct['id_hotel']; - $product['date_from'] = $selectedProduct['date_from']; - $product['date_to'] = $selectedProduct['date_to']; - $orderPackage[$id_address][$selectedProduct['id_hotel']][$dateJoin]['product_list'][] = $product; - if (!isset($orderPackage[$id_address][$selectedProduct['id_hotel']][$dateJoin]['id_hotel'])) { - $orderPackage[$id_address][$selectedProduct['id_hotel']][$dateJoin]['id_hotel'] = $selectedProduct['id_hotel']; - } - if (!isset($orderPackage[$id_address][$selectedProduct['id_hotel']][$dateJoin]['carrier_list'])) { - $orderPackage[$id_address][$selectedProduct['id_hotel']][$dateJoin]['carrier_list'] = $product['carrier_list']; - } else { - $orderPackage[$id_address][$selectedProduct['id_hotel']][$dateJoin]['carrier_list'] = array_intersect($orderPackage[$id_address][$selectedProduct['id_hotel']][$dateJoin]['carrier_list'], $product['carrier_list']); - } - if (!isset($orderPackage[$id_address][$selectedProduct['id_hotel']][$dateJoin]['warehouse_list'])) { - $orderPackage[$id_address][$selectedProduct['id_hotel']][$dateJoin]['warehouse_list'] = $package['warehouse_list']; - } - if (!isset($orderPackage[$id_address][$selectedProduct['id_hotel']][$dateJoin]['id_warehouse'])) { - $orderPackage[$id_address][$selectedProduct['id_hotel']][$dateJoin]['id_warehouse'] = $package['id_warehouse']; - } - if (isset($package['id_carrier'])) { - if (!isset($orderPackage[$id_address][$selectedProduct['id_hotel']][$dateJoin]['id_carrier'])) { - $orderPackage[$id_address][$selectedProduct['id_hotel']][$dateJoin]['id_carrier'] = $package['id_carrier']; - } + + foreach($array as $dateJoinKey => $selectedProduct) { + $product['cart_quantity'] = $selectedProduct['quantity']; + $product['total'] = $selectedProduct['total_price_tax_excl']; + $product['total_wt'] = $selectedProduct['total_price_tax_incl']; + $product['price_wt'] = $selectedProduct['total_price_tax_incl'] / $product['cart_quantity']; + $product['price'] = $selectedProduct['total_price_tax_excl'] / $product['cart_quantity']; + $product['id_hotel'] = $selectedProduct['id_hotel']; + $product['date_from'] = $selectedProduct['date_from']; + $product['date_to'] = $selectedProduct['date_to']; + $orderPackage[$id_address][$dateJoinKey]['product_list'][] = $product; + if (!isset($orderPackage[$id_address][$dateJoinKey]['id_hotel'])) { + $orderPackage[$id_address][$dateJoinKey]['id_hotel'] = $selectedProduct['id_hotel']; + } + if (!isset($orderPackage[$id_address][$dateJoinKey]['carrier_list'])) { + $orderPackage[$id_address][$dateJoinKey]['carrier_list'] = $product['carrier_list']; + } else { + $orderPackage[$id_address][$dateJoinKey]['carrier_list'] = array_intersect($orderPackage[$id_address][$dateJoinKey]['carrier_list'], $product['carrier_list']); + } + if (!isset($orderPackage[$id_address][$dateJoinKey]['warehouse_list'])) { + $orderPackage[$id_address][$dateJoinKey]['warehouse_list'] = $package['warehouse_list']; + } + if (!isset($orderPackage[$id_address][$dateJoinKey]['id_warehouse'])) { + $orderPackage[$id_address][$dateJoinKey]['id_warehouse'] = $package['id_warehouse']; + } + if (isset($package['id_carrier'])) { + if (!isset($orderPackage[$id_address][$dateJoinKey]['id_carrier'])) { + $orderPackage[$id_address][$dateJoinKey]['id_carrier'] = $package['id_carrier']; } } } @@ -2508,30 +2507,28 @@ class CartCore extends ObjectModel } } - $hotelWisePackageList = array(); + $hotelAndDateWisePackageList = array(); $numHotels = 0; if (!empty($serviceProducts)) { foreach ($serviceProducts as $id_address => $packagesByHotels) { foreach ($packagesByHotels as $packageByHotel) { - $hotelWisePackageList[$id_address][] = $packageByHotel; + $hotelAndDateWisePackageList[$id_address][] = $packageByHotel; } } } foreach ($orderPackage as $id_address => $packageByAddress) { $numHotels += count($packageByAddress); - foreach ($packageByAddress as $id_package => $packageByDate) { - foreach ($packageByDate as $package) { - $hotelWisePackageList[$id_address][] = $package; - } + foreach ($packageByAddress as $id_package => $package) { + $hotelAndDateWisePackageList[$id_address][] = $package; } } // add sevice products as new package if there are multiple hotels in cart // if ($numHotels > 1 || count($serviceProducts) > 1) { // foreach ($serviceProducts as $productsByAddress) { // if (isset($orderPackage[$id_address])) { - // $hotelWisePackageList[$id_address][] = array( + // $hotelAndDateWisePackageList[$id_address][] = array( // 'product_list' => $productsByAddress['products'], // 'carrier_list' => $productsByAddress['carrier_list'], // 'warehouse_list' => $productsByAddress['warehouse_list'], @@ -2544,13 +2541,13 @@ class CartCore extends ObjectModel // } else if (!empty($serviceProducts)) { // $serviceProductsIdAddress = array_keys($serviceProducts)[0]; // $productsByAddress = array_shift($serviceProducts); - // if (isset($hotelWisePackageList[$serviceProductsIdAddress])) { - // $hotelWisePackageList[$serviceProductsIdAddress][0]['product_list'] = array_merge( - // $hotelWisePackageList[$serviceProductsIdAddress][0]['product_list'], + // if (isset($hotelAndDateWisePackageList[$serviceProductsIdAddress])) { + // $hotelAndDateWisePackageList[$serviceProductsIdAddress][0]['product_list'] = array_merge( + // $hotelAndDateWisePackageList[$serviceProductsIdAddress][0]['product_list'], // $productsByAddress['products'] // ); // } else { - // $hotelWisePackageList[$id_address][] = array( + // $hotelAndDateWisePackageList[$id_address][] = array( // 'product_list' => $productsByAddress['products'], // 'carrier_list' => $productsByAddress['carrier_list'], // 'warehouse_list' => $productsByAddress['warehouse_list'], @@ -2560,7 +2557,7 @@ class CartCore extends ObjectModel // ); // } // } - $final_package_list = $hotelWisePackageList; + $final_package_list = $hotelAndDateWisePackageList; // END $package_list hotel wise $cache[$cache_key] = $final_package_list; return $final_package_list; From 37fa2d0a77f27b73ff8e4a12d13e3ac4d615526c Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Mon, 18 Mar 2024 19:23:53 +0530 Subject: [PATCH 5/5] fix duplicate room issue --- classes/Cart.php | 58 +++++++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/classes/Cart.php b/classes/Cart.php index b8e052c76..50d4cf587 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -2362,8 +2362,39 @@ class CartCore extends ObjectModel )) { $productInfo = $objRoomType->getRoomTypeInfoByIdProduct($product['id_product']); $idHotel = $productInfo['id_hotel'] ? $productInfo['id_hotel'] : 0; + $cartRoomInfo = array(); foreach ($roomsBookingDetails as $roomBooking) { $dateJoinKey = $idHotel.'-'.strtotime($roomBooking['date_from']).strtotime($roomBooking['date_to']); + $roomTotalPrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( + $product['id_product'], + $roomBooking['date_from'], + $roomBooking['date_to'], + 0, + Group::getCurrent()->id, + $this->id, + $this->id_guest, + 0, + 0 + ); + $newQty = HotelHelper::getNumberOfDays( + $roomBooking['date_from'], + $roomBooking['date_to'] + ); + if (isset($cartRoomInfo[$dateJoinKey])) { + $cartRoomInfo[$dateJoinKey]['cart_quantity'] += $newQty; + $cartRoomInfo[$dateJoinKey]['total_price_tax_incl'] += $roomTotalPrice['total_price_tax_incl']; + $cartRoomInfo[$dateJoinKey]['total_price_tax_excl'] += $roomTotalPrice['total_price_tax_excl']; + } else { + $cartRoomInfo[$dateJoinKey] = array( + 'cart_quantity' => $newQty, + 'total_price_tax_incl' => $roomTotalPrice['total_price_tax_incl'], + 'total_price_tax_excl' => $roomTotalPrice['total_price_tax_excl'], + 'date_from' => $roomBooking['date_from'], + 'date_to' => $roomBooking['date_to'], + ); + } + } + foreach ($cartRoomInfo as $dateJoinKey => $cartRoom) { if (!isset($orderPackage[$id_address][$dateJoinKey])) { $orderPackage[$id_address][$dateJoinKey]['product_list'] = array(); @@ -2388,26 +2419,13 @@ class CartCore extends ObjectModel } } } - $product['cart_quantity'] = HotelHelper::getNumberOfDays( - $roomBooking['date_from'], - $roomBooking['date_to'] - ); - $product['date_from'] = $roomBooking['date_from']; - $product['date_to'] = $roomBooking['date_to']; - - $roomTotalPrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( - $product['id_product'], - $roomBooking['date_from'], - $roomBooking['date_to'], - 0, - Group::getCurrent()->id, - $this->id, - $this->id_guest, - 0, - 0 - ); - $product['total_wt'] = $roomTotalPrice['total_price_tax_incl']; - $product['total'] = $roomTotalPrice['total_price_tax_excl']; + $product['date_from'] = $cartRoom['date_from']; + $product['date_to'] = $cartRoom['date_to']; + $product['total_wt'] = $cartRoom['total_price_tax_incl']; + $product['total'] = $cartRoom['total_price_tax_excl']; + $product['cart_quantity'] = $cartRoom['cart_quantity']; + $product['price_wt'] = $cartRoom['total_price_tax_incl'] / $cartRoom['cart_quantity']; + $product['price'] = $cartRoom['total_price_tax_excl'] / $cartRoom['cart_quantity']; $orderPackage[$id_address][$dateJoinKey]['product_list'][] = $product; } }