Fix: correct invoice price calculation and fix standalone service product not being added when another product exists

This commit is contained in:
Amit sharma
2026-03-03 16:20:58 +05:30
parent e5dd7e67a5
commit 7aaa29e07b
7 changed files with 41 additions and 128 deletions

View File

@@ -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;
}
}

View File

@@ -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,

View File

@@ -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) {

View File

@@ -1670,7 +1670,7 @@ class AdminCartsControllerCore extends AdminController
$idServiceProduct,
$operator,
$quantity,
0,
false,
$idCartBooking
))) {
$originalPrice = Product::getPriceStatic($idServiceProduct, false);

View File

@@ -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
)) {

View File

@@ -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') {

View File

@@ -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) {