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

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