From 7aaa29e07bec662eea479ca44beb28fcbcbb2bd5 Mon Sep 17 00:00:00 2001 From: Amit sharma Date: Tue, 3 Mar 2026 16:20:58 +0530 Subject: [PATCH] Fix: correct invoice price calculation and fix standalone service product not being added when another product exists --- classes/Cart.php | 35 ++++-- classes/PaymentModule.php | 104 ------------------ classes/order/OrderInvoice.php | 18 +-- controllers/admin/AdminCartsController.php | 2 +- controllers/admin/AdminOrdersController.php | 2 +- controllers/front/CartController.php | 4 +- .../classes/ServiceProductCartDetail.php | 4 +- 7 files changed, 41 insertions(+), 128 deletions(-) diff --git a/classes/Cart.php b/classes/Cart.php index 0b2d86500..4f7d24e46 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -2556,17 +2556,32 @@ class CartCore extends ObjectModel null, (int)$product['id_product'] )) { - if (!isset($standaloneProduct[$id_address])) { - $standaloneProduct[$id_address] = array( - 'product_list' => array(), - 'warehouse_list' => $package['warehouse_list'], - 'carrier_list' => $product['carrier_list'], - 'id_warehouse' => $package['id_warehouse'], - 'id_carrier' => isset($package['id_carrier']) ? $package['id_carrier'] : 0 - ); + $hasStandaloneService = false; + foreach ($selectedServiceProducts as $selectedServiceProduct) { + if ((int) $selectedServiceProduct['id_hotel'] === 0 + && (int) $selectedServiceProduct['id_hotel_cart_booking'] === 0 + ) { + $hasStandaloneService = true; + break; + } + } + + if ($hasStandaloneService) { + if (!isset($standaloneProduct[$id_address])) { + $standaloneProduct[$id_address] = array( + 'product_list' => array(), + 'warehouse_list' => $package['warehouse_list'], + 'carrier_list' => $product['carrier_list'], + 'id_warehouse' => $package['id_warehouse'], + 'id_carrier' => isset($package['id_carrier']) ? $package['id_carrier'] : 0 + ); + } + $productinfo = $product; + $productinfo['id_hotel'] = 0; + $productinfo['id_hotel_cart_booking'] = 0; + $productinfo['id_room_type'] = 0; + $standaloneProduct[$id_address]['product_list'][] = $productinfo; } - $productinfo = $product; - $standaloneProduct[$id_address]['product_list'][] = $product; } } diff --git a/classes/PaymentModule.php b/classes/PaymentModule.php index 6745a0e2d..4a38a14c7 100644 --- a/classes/PaymentModule.php +++ b/classes/PaymentModule.php @@ -974,110 +974,6 @@ abstract class PaymentModuleCore extends Module $canSellWithHotel = Product::isSellableWithHotel($product['selling_preference_type']); $canSellAsStandalone = Product::isSellableAsStandalone($product['selling_preference_type']); - if ($canSellWithRoomType || $canSellWithHotel || $canSellAsStandalone) { - $idProductRoomType = null; - $idProductHotel = null; - if (isset($product['id_room_type']) && $product['id_room_type']) { - $idProductRoomType = $product['id_room_type']; - } elseif (isset($product['id_hotel']) && $product['id_hotel']) { - $idProductHotel = $product['id_hotel']; - } - - if ($serviceProducts = $objServiceProductCartDetail->getServiceProductsInCart( - $this->context->cart->id, - [], - $idProductHotel, - null, - $idProductRoomType, - $product['id_product'] - )) { - foreach ($serviceProducts as $serviceProduct) { - $isRoomTypeService = !empty($serviceProduct['id_hotel_cart_booking']); - $isHotelService = !$isRoomTypeService && !empty($serviceProduct['id_hotel']); - - if ($isRoomTypeService) { - $idOrderDetail = $objBookingDetail->getPsOrderDetailIdByIdProduct( - $idProduct, - $order->id, - Product::SELLING_PREFERENCE_WITH_ROOM_TYPE - ); - } elseif ($isHotelService) { - $idOrderDetail = $objBookingDetail->getPsOrderDetailIdByIdProduct( - $idProduct, - $order->id, - Product::SELLING_PREFERENCE_HOTEL_STANDALONE - ); - } else { - $idOrderDetail = $objBookingDetail->getPsOrderDetailIdByIdProduct( - $idProduct, - $order->id, - Product::SELLING_PREFERENCE_STANDALONE - ); - } - - if (!$idOrderDetail) { - $idOrderDetail = $objBookingDetail->getPsOrderDetailIdByIdProduct( - $idProduct, - $order->id, - $product['selling_preference_type'] - ); - } - if (!$idOrderDetail) { - $idOrderDetail = $objBookingDetail->getPsOrderDetailIdByIdProduct( - $idProduct, - $order->id - ); - } - if (!$idOrderDetail) { - continue; - } - - $objServiceProductOrderDetail = new ServiceProductOrderDetail(); - $objServiceProductOrderDetail->id_product = $idProduct; - $objServiceProductOrderDetail->id_order = $order->id; - $objServiceProductOrderDetail->id_order_detail = $idOrderDetail; - $objServiceProductOrderDetail->id_cart = $this->context->cart->id; - $objServiceProductOrderDetail->unit_price_tax_excl = $serviceProduct['unit_price_tax_excl']; - $objServiceProductOrderDetail->unit_price_tax_incl = $serviceProduct['unit_price_tax_incl']; - $objServiceProductOrderDetail->total_price_tax_excl = $serviceProduct['total_price_tax_excl']; - $objServiceProductOrderDetail->total_price_tax_incl = $serviceProduct['total_price_tax_incl']; - $objServiceProductOrderDetail->name = $product['name']; - $objServiceProductOrderDetail->quantity = $serviceProduct['quantity']; - $objServiceProductOrderDetail->id_product_option = $serviceProduct['id_product_option']; - $objServiceProductOrderDetail->option_name = $serviceProduct['option_name']; - if ($isHotelService) { - $objServiceProductOrderDetail->id_hotel = $serviceProduct['id_hotel']; - if (Validate::isLoadedObject( - $objHotelBranch = new HotelBranchInformation($serviceProduct['id_hotel'], $this->context->cart->id_lang) - )) { - $objServiceProductOrderDetail->hotel_name = $objHotelBranch->hotel_name; - } - } elseif ($isRoomTypeService) { - if (!Validate::isDate($serviceProduct['date_from']) - || !Validate::isDate($serviceProduct['date_to']) - || !(int) $serviceProduct['id_room_type'] - ) { - continue; - } - $roomBookingDetail = $objBookingDetail->getRowByIdOrderIdProductInDateRange( - $order->id, - $serviceProduct['id_room_type'], - $serviceProduct['date_from'], - $serviceProduct['date_to'], - $serviceProduct['id_room'] - ); - if (empty($roomBookingDetail['id'])) { - continue; - } - $objServiceProductOrderDetail->id_htl_booking_detail = $roomBookingDetail['id']; - $objServiceProductOrderDetail->auto_added = $product['auto_add_to_cart']; - } - $objServiceProductOrderDetail->save(); - } - } - continue; - } - if ($canSellWithRoomType && !$canSellWithHotel && !$canSellAsStandalone) { if ($roomTypeServices = $objServiceProductCartDetail->getServiceProductsInCart( $this->context->cart->id, diff --git a/classes/order/OrderInvoice.php b/classes/order/OrderInvoice.php index dc74a2105..911951c59 100644 --- a/classes/order/OrderInvoice.php +++ b/classes/order/OrderInvoice.php @@ -478,14 +478,16 @@ class OrderInvoiceCore extends ObjectModel // - 'total_price_tax_excl' // - 'total_amount' $breakdown = array(); - $order_detail = $this->getProducts(); - $order_detail = array_filter($order_detail, function($v) { - return ( - !$v['is_booking_product'] - && !$v['product_auto_add'] - && Product::isSellableWithRoomType($v['selling_preference_type']) - ); - }); + $order_detail = $this->getProducts( + $order->getProductsDetail( + false, + null, + 0, + Product::PRICE_ADDITION_TYPE_INDEPENDENT, + array(), + Order::SERVICE_PRODUCT_CONTEXT_ROOM_LINKED + ) + ); $details = $order->getProductTaxesDetails($order_detail, false); if ($sum_composite_taxes) { diff --git a/controllers/admin/AdminCartsController.php b/controllers/admin/AdminCartsController.php index d7bda66aa..03b07ba0e 100644 --- a/controllers/admin/AdminCartsController.php +++ b/controllers/admin/AdminCartsController.php @@ -1670,7 +1670,7 @@ class AdminCartsControllerCore extends AdminController $idServiceProduct, $operator, $quantity, - 0, + false, $idCartBooking ))) { $originalPrice = Product::getPriceStatic($idServiceProduct, false); diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 7be742582..9cafbb2be 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -5644,7 +5644,7 @@ class AdminOrdersControllerCore extends AdminController $idProduct, 'up', $productInformations['product_quantity'], - isset($addressTax->id_hotel) ? $addressTax->id_hotel : 0, + isset($addressTax->id_hotel) ? $addressTax->id_hotel : false, false, isset($productInformations['product_option']) ? $productInformations['product_option'] : null )) { diff --git a/controllers/front/CartController.php b/controllers/front/CartController.php index c22b5f0b5..98fb6eaac 100644 --- a/controllers/front/CartController.php +++ b/controllers/front/CartController.php @@ -665,8 +665,8 @@ class CartControllerCore extends FrontController $this->id_product, $operator, $this->qty, - false, - false, + 0, + 0, isset($idProductOption) ? $idProductOption : null ); if ($operator == 'up') { diff --git a/modules/hotelreservationsystem/classes/ServiceProductCartDetail.php b/modules/hotelreservationsystem/classes/ServiceProductCartDetail.php index 25a1edfcb..8f9a908ec 100644 --- a/modules/hotelreservationsystem/classes/ServiceProductCartDetail.php +++ b/modules/hotelreservationsystem/classes/ServiceProductCartDetail.php @@ -58,10 +58,10 @@ class ServiceProductCartDetail extends ObjectModel if ($idProduct) { $sql .= ' AND `id_product` = '.(int)$idProduct; } - if ($idHotel) { + if ($idHotel !== false && $idHotel !== null) { $sql .= ' AND `id_hotel` = '.(int)$idHotel; } - if ($idHtlCartData) { + if ($idHtlCartData !== false && $idHtlCartData !== null) { $sql .= ' AND `htl_cart_booking_id` = '.(int)$idHtlCartData; } if ($idProductOption) {