From 2a86378bae57b62b39aff58d532fc178989f8479 Mon Sep 17 00:00:00 2001 From: Amit sharma Date: Fri, 27 Feb 2026 10:14:09 +0530 Subject: [PATCH] Fix price calculation in order confirmation email --- classes/Cart.php | 81 +++++---- classes/PaymentModule.php | 60 +++++-- classes/pdf/HTMLTemplateInvoice.php | 80 ++++++++- classes/pdf/HTMLTemplateOrderSlip.php | 14 +- .../WebserviceSpecificManagementBookings.php | 10 +- controllers/admin/AdminImportController.php | 6 +- controllers/front/GuestTrackingController.php | 35 ++-- modules/blockcart/ajax-cart.js | 157 +++++++++++------- modules/blockcart/blockcart.tpl | 21 ++- modules/blockcart/cartrow.tpl | 12 +- .../AdminHotelRoomsBookingController.php | 4 +- 11 files changed, 321 insertions(+), 159 deletions(-) diff --git a/classes/Cart.php b/classes/Cart.php index cc5d94173..e936c663c 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -1791,42 +1791,59 @@ class CartCore extends ObjectModel } } else if ($canSellWithHotel) { - if ($type == Cart::ONLY_ROOM_SERVICES - || $type == Cart::ONLY_CONVENIENCE_FEE - || $type == Cart::ONLY_ROOM_SERVICES_WITHOUT_AUTO_ADD - || $type == Cart::ONLY_ROOM_SERVICES_WITHOUT_CONVENIENCE_FEE - || $type == Cart::ONLY_ROOM_SERVICES_WITH_AUTO_ADD_WITHOUT_CONVENIENCE_FEE - ) { - $servicePorducts = $objServiceProductCartDetail->getServiceProductsInCart( - $this->id, - [], - 0, - null, - null, - (int)$product['id_product'] - ); - } elseif ($type == Cart::ONLY_STANDALONE_PRODUCTS) { - $servicePorducts = $objServiceProductCartDetail->getServiceProductsInCart( - $this->id, - [], - null, - 0, - null, - (int)$product['id_product'] - ); - } else { - $servicePorducts = $objServiceProductCartDetail->getServiceProductsInCart( - $this->id, - [], - 0, - null, - null, - (int)$product['id_product'] - ); + $isRoomServiceTotalType = in_array($type, array( + Cart::ONLY_ROOM_SERVICES, + Cart::ONLY_CONVENIENCE_FEE, + Cart::ONLY_ROOM_SERVICES_WITHOUT_AUTO_ADD, + Cart::ONLY_ROOM_SERVICES_WITHOUT_CONVENIENCE_FEE, + Cart::ONLY_ROOM_SERVICES_WITH_AUTO_ADD_WITHOUT_CONVENIENCE_FEE, + )); + $id_hotel = null; + $id_hotel_cart_booking = null; + if ($param_product) { + if (isset($product['id_hotel']) && (int)$product['id_hotel']) { + $id_hotel = (int)$product['id_hotel']; + } + if (isset($product['id_hotel_cart_booking']) && (int)$product['id_hotel_cart_booking']) { + $id_hotel_cart_booking = (int)$product['id_hotel_cart_booking']; + } } + $servicePorducts = $objServiceProductCartDetail->getServiceProductsInCart( + $this->id, + [], + null, + null, + null, + (int)$product['id_product'] + ); + if ($servicePorducts) { foreach ($servicePorducts as $servicePorduct) { + if ($param_product) { + if ($id_hotel_cart_booking !== null + && (int)$servicePorduct['id_hotel_cart_booking'] !== $id_hotel_cart_booking + ) { + continue; + } + if ($id_hotel_cart_booking === null + && $id_hotel !== null + && ( + !empty($servicePorduct['id_hotel_cart_booking']) + || (int)$servicePorduct['id_hotel'] !== $id_hotel + ) + ) { + continue; + } + } + if ($isRoomServiceTotalType && empty($servicePorduct['id_hotel_cart_booking'])) { + continue; + } + if ($type == Cart::ONLY_STANDALONE_PRODUCTS + && !empty($servicePorduct['id_hotel_cart_booking']) + ) { + continue; + } if ($with_taxes) { $priceAdd = $servicePorduct['total_price_tax_incl']; } else { diff --git a/classes/PaymentModule.php b/classes/PaymentModule.php index 3af3b70dc..e39aa34b6 100644 --- a/classes/PaymentModule.php +++ b/classes/PaymentModule.php @@ -541,6 +541,7 @@ abstract class PaymentModuleCore extends Module $product_var_tpl_list = array(); $orderServiceProducts = array(); + $processedServiceProductCartIds = array(); $objProduct = new Product(); foreach ($order->product_list as $product) { @@ -591,11 +592,11 @@ abstract class PaymentModuleCore extends Module } if ( - !$product['booking_product'] + !$product['booking_product'] && !$product['id_hotel_cart_booking'] && ( Product::isSellableAsStandalone($product['selling_preference_type']) || Product::isSellableWithHotel($product['selling_preference_type']) - ) + ) ) { $cover_image_arr = $objProduct->getCover($product['id_product']); @@ -613,7 +614,8 @@ abstract class PaymentModuleCore extends Module null, $product['id_product'] ); - + $standaloneServiceProducts = array(); + $hotelServiceProducts = array(); foreach ($serviceProducts as $serviceProduct) { $orderServiceProducts[] = array_merge($product_var_tpl, $serviceProduct); } @@ -1402,28 +1404,52 @@ abstract class PaymentModuleCore extends Module $normal_products_data_txt = $this->getEmailTemplateContent('service_product_data_text.tpl', Mail::TYPE_TEXT, $orderServiceProducts); // get order total information html/txt files + // room-related selling types: + // 1: with room type, 3: hotel+room, 6: standalone+room, 7: hotel+room+standalone + $roomRelatedSellingTypes = array( + Product::SELLING_PREFERENCE_WITH_ROOM_TYPE, + Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE, + Product::SELLING_PREFERENCE_STANDALONE_AND_WITH_ROOM_TYPE, + Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE, + ); + // total room price - $room_price_tax_excl = $order->getTotalProductsWithoutTaxes(false, true) + $order->getTotalProductsWithoutTaxes(false, false, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE, 1, Product::PRICE_ADDITION_TYPE_WITH_ROOM); - $room_price_tax_incl = $order->getTotalProductsWithTaxes(false, true) + $order->getTotalProductsWithTaxes(false, false, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE, 1, Product::PRICE_ADDITION_TYPE_WITH_ROOM); + $room_auto_with_room_tax_excl = 0; + $room_auto_with_room_tax_incl = 0; + foreach ($roomRelatedSellingTypes as $sellingType) { + $room_auto_with_room_tax_excl += $order->getTotalProductsWithoutTaxes(false, false, $sellingType, 1, Product::PRICE_ADDITION_TYPE_WITH_ROOM); + $room_auto_with_room_tax_incl += $order->getTotalProductsWithTaxes(false, false, $sellingType, 1, Product::PRICE_ADDITION_TYPE_WITH_ROOM); + } + $room_price_tax_excl = $order->getTotalProductsWithoutTaxes(false, true) + $room_auto_with_room_tax_excl; + $room_price_tax_incl = $order->getTotalProductsWithTaxes(false, true) + $room_auto_with_room_tax_incl; $room_tax = ($room_price_tax_incl - $room_price_tax_excl); // extra services - $additional_service_price_tax_excl = ($order->getTotalProductsWithoutTaxes(false, false, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE, 0) + $cart_booking_data['total_extra_demands_te']); - $additional_service_price_tax_incl = ($order->getTotalProductsWithTaxes(false, false, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE, 0) + $cart_booking_data['total_extra_demands_ti']); + $additional_service_price_tax_excl = (float) $cart_booking_data['total_extra_demands_te']; + $additional_service_price_tax_incl = (float) $cart_booking_data['total_extra_demands_ti']; + foreach ($roomRelatedSellingTypes as $sellingType) { + $additional_service_price_tax_excl += $order->getTotalProductsWithoutTaxes(false, false, $sellingType, 0, Product::PRICE_ADDITION_TYPE_INDEPENDENT); + $additional_service_price_tax_incl += $order->getTotalProductsWithTaxes(false, false, $sellingType, 0, Product::PRICE_ADDITION_TYPE_INDEPENDENT); + } $additional_service_tax = ($additional_service_price_tax_incl - $additional_service_price_tax_excl); // convenience fee price - $total_convenience_fee_ti = $order->getTotalProductsWithTaxes(false, false, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE, 1, Product::PRICE_ADDITION_TYPE_INDEPENDENT); - $total_convenience_fee_te = $order->getTotalProductsWithoutTaxes(false, false, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE, 1, Product::PRICE_ADDITION_TYPE_INDEPENDENT); + $total_convenience_fee_ti = 0; + $total_convenience_fee_te = 0; + foreach ($roomRelatedSellingTypes as $sellingType) { + $total_convenience_fee_ti += $order->getTotalProductsWithTaxes(false, false, $sellingType, 1, Product::PRICE_ADDITION_TYPE_INDEPENDENT); + $total_convenience_fee_te += $order->getTotalProductsWithoutTaxes(false, false, $sellingType, 1, Product::PRICE_ADDITION_TYPE_INDEPENDENT); + } $total_convenience_fee_tax = $total_convenience_fee_ti - $total_convenience_fee_te; // service products - $standalone_products_price_tax_excl = $order->getTotalProductsWithoutTaxes(false, false, Product::SELLING_PREFERENCE_STANDALONE); - $standalone_products_price_tax_incl = $order->getTotalProductsWithTaxes(false, false, Product::SELLING_PREFERENCE_STANDALONE); - $hotel_standalone_products_price_tax_excl = $order->getTotalProductsWithoutTaxes(false, false, Product::SELLING_PREFERENCE_HOTEL_STANDALONE); - $hotel_standalone_products_price_tax_incl = $order->getTotalProductsWithTaxes(false, false, Product::SELLING_PREFERENCE_HOTEL_STANDALONE); - - $service_products_tax = ($standalone_products_price_tax_incl + $hotel_standalone_products_price_tax_incl) - ($standalone_products_price_tax_excl + $hotel_standalone_products_price_tax_excl); + $all_services_price_tax_incl = $order->getTotalProductsWithTaxes(false, false); + $all_services_price_tax_excl = $order->getTotalProductsWithoutTaxes(false, false); + $room_linked_services_price_tax_incl = $order->getTotalProductsWithTaxes(false, false, null, null, null, null, Order::SERVICE_PRODUCT_CONTEXT_ROOM_LINKED); + $room_linked_services_price_tax_excl = $order->getTotalProductsWithoutTaxes(false, false, null, null, null, null, Order::SERVICE_PRODUCT_CONTEXT_ROOM_LINKED); + $total_standard_products_tax_incl = $all_services_price_tax_incl - $room_linked_services_price_tax_incl; + $total_standard_products_tax_excl = $all_services_price_tax_excl - $room_linked_services_price_tax_excl; + $service_products_tax = $total_standard_products_tax_incl - $total_standard_products_tax_excl; $total_order_tax = $room_tax + $additional_service_tax + $total_convenience_fee_tax + $service_products_tax; @@ -1440,12 +1466,12 @@ abstract class PaymentModuleCore extends Module 'total_convenience_fee_te' => Tools::displayPrice($total_convenience_fee_te, $this->context->currency, false), 'total_convenience_fee_tax' => Tools::displayPrice($total_convenience_fee_tax, $this->context->currency, false), 'service_products_price_tax_excl' => Tools::displayPrice( - ($standalone_products_price_tax_excl + $hotel_standalone_products_price_tax_excl), + $total_standard_products_tax_excl, $this->context->currency, false ), 'service_products_price_tax_incl' => Tools::displayPrice( - ($standalone_products_price_tax_incl + $hotel_standalone_products_price_tax_incl), + $total_standard_products_tax_incl, $this->context->currency, false ), diff --git a/classes/pdf/HTMLTemplateInvoice.php b/classes/pdf/HTMLTemplateInvoice.php index 4b4754ca8..23839e4e8 100644 --- a/classes/pdf/HTMLTemplateInvoice.php +++ b/classes/pdf/HTMLTemplateInvoice.php @@ -679,17 +679,81 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate $footer['room_price_tax_incl'] = $this->order->getTotalProductsWithTaxes(false, true, null, null, null, $idsOrderDetail); foreach ($roomTypeSellingPreferenceTypes as $sellingPreferenceType) { - $footer['room_price_tax_excl'] += $this->order->getTotalProductsWithoutTaxes(false, false, $sellingPreferenceType, 1, Product::PRICE_ADDITION_TYPE_WITH_ROOM, $idsOrderDetail); - $footer['room_price_tax_incl'] += $this->order->getTotalProductsWithTaxes(false, false, $sellingPreferenceType, 1, Product::PRICE_ADDITION_TYPE_WITH_ROOM, $idsOrderDetail); - $footer['additional_service_price_tax_excl'] += $this->order->getTotalProductsWithoutTaxes(false, false, $sellingPreferenceType, 0, null, $idsOrderDetail); - $footer['additional_service_price_tax_incl'] += $this->order->getTotalProductsWithTaxes(false, false, $sellingPreferenceType, 0, null, $idsOrderDetail); - $footer['total_convenience_fee_te'] += $this->order->getTotalProductsWithoutTaxes(false, false, $sellingPreferenceType, 1, Product::PRICE_ADDITION_TYPE_INDEPENDENT, $idsOrderDetail); - $footer['total_convenience_fee_ti'] += $this->order->getTotalProductsWithTaxes(false, false, $sellingPreferenceType, 1, Product::PRICE_ADDITION_TYPE_INDEPENDENT, $idsOrderDetail); + $footer['room_price_tax_excl'] += $this->order->getTotalProductsWithoutTaxes( + false, + false, + $sellingPreferenceType, + 1, + Product::PRICE_ADDITION_TYPE_WITH_ROOM, + $idsOrderDetail, + Order::SERVICE_PRODUCT_CONTEXT_ROOM_LINKED + ); + $footer['room_price_tax_incl'] += $this->order->getTotalProductsWithTaxes( + false, + false, + $sellingPreferenceType, + 1, + Product::PRICE_ADDITION_TYPE_WITH_ROOM, + $idsOrderDetail, + Order::SERVICE_PRODUCT_CONTEXT_ROOM_LINKED + ); + $footer['additional_service_price_tax_excl'] += $this->order->getTotalProductsWithoutTaxes( + false, + false, + $sellingPreferenceType, + 0, + null, + $idsOrderDetail, + Order::SERVICE_PRODUCT_CONTEXT_ROOM_LINKED + ); + $footer['additional_service_price_tax_incl'] += $this->order->getTotalProductsWithTaxes( + false, + false, + $sellingPreferenceType, + 0, + null, + $idsOrderDetail, + Order::SERVICE_PRODUCT_CONTEXT_ROOM_LINKED + ); + $footer['total_convenience_fee_te'] += $this->order->getTotalProductsWithoutTaxes( + false, + false, + $sellingPreferenceType, + 1, + Product::PRICE_ADDITION_TYPE_INDEPENDENT, + $idsOrderDetail, + Order::SERVICE_PRODUCT_CONTEXT_ROOM_LINKED + ); + $footer['total_convenience_fee_ti'] += $this->order->getTotalProductsWithTaxes( + false, + false, + $sellingPreferenceType, + 1, + Product::PRICE_ADDITION_TYPE_INDEPENDENT, + $idsOrderDetail, + Order::SERVICE_PRODUCT_CONTEXT_ROOM_LINKED + ); } foreach ($serviceSellingPreferenceTypes as $sellingPreferenceType) { - $footer['service_products_price_tax_excl'] += $this->order->getTotalProductsWithoutTaxes(false, false, $sellingPreferenceType, false, false, $idsOrderDetail); - $footer['service_products_price_tax_incl'] += $this->order->getTotalProductsWithTaxes(false, false, $sellingPreferenceType, false, false, $idsOrderDetail); + $footer['service_products_price_tax_excl'] += $this->order->getTotalProductsWithoutTaxes( + false, + false, + $sellingPreferenceType, + false, + false, + $idsOrderDetail, + Order::SERVICE_PRODUCT_CONTEXT_NON_ROOM + ); + $footer['service_products_price_tax_incl'] += $this->order->getTotalProductsWithTaxes( + false, + false, + $sellingPreferenceType, + false, + false, + $idsOrderDetail, + Order::SERVICE_PRODUCT_CONTEXT_NON_ROOM + ); } $footer['additional_service_price_tax_excl'] += $totalDemandsPriceTE; diff --git a/classes/pdf/HTMLTemplateOrderSlip.php b/classes/pdf/HTMLTemplateOrderSlip.php index 16396243f..0c2a50c86 100644 --- a/classes/pdf/HTMLTemplateOrderSlip.php +++ b/classes/pdf/HTMLTemplateOrderSlip.php @@ -286,7 +286,7 @@ class HTMLTemplateOrderSlipCore extends HTMLTemplateInvoice $order_detail = array_filter($this->order->products, function($v) { return ((isset($v['is_booking_product']) && $v['is_booking_product']) || ((isset($v['product_auto_add']) && $v['product_auto_add']) - && $v['selling_preference_type'] == Product::SELLING_PREFERENCE_WITH_ROOM_TYPE + && Product::isSellableWithRoomType($v['selling_preference_type']) && $v['product_price_addition_type'] == ProductCore::PRICE_ADDITION_TYPE_WITH_ROOM) ); }); @@ -347,10 +347,14 @@ class HTMLTemplateOrderSlipCore extends HTMLTemplateInvoice // - 'total_amount' $breakdown = array(); $order_detail = array_filter($this->order->products, function($v) { - return (!$v['is_booking_product'] && ( - $v['selling_preference_type'] == Product::SELLING_PREFERENCE_STANDALONE - || $v['selling_preference_type'] == Product::SELLING_PREFERENCE_HOTEL_STANDALONE - )); + return ( + !$v['is_booking_product'] + && empty($v['id_htl_booking']) + && ( + Product::isSellableAsStandalone($v['selling_preference_type']) + || Product::isSellableWithHotel($v['selling_preference_type']) + ) + ); }); $details = $this->order->getProductTaxesDetails($order_detail, false); diff --git a/classes/webservice/WebserviceSpecificManagementBookings.php b/classes/webservice/WebserviceSpecificManagementBookings.php index 10e52dab0..bb9e3be7d 100644 --- a/classes/webservice/WebserviceSpecificManagementBookings.php +++ b/classes/webservice/WebserviceSpecificManagementBookings.php @@ -1015,7 +1015,15 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We } } - $serviceProductPrice = $objOrder->getTotalProductsWithTaxes(false, false, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE); + $serviceProductPrice = $objOrder->getTotalProductsWithTaxes( + false, + false, + null, + null, + null, + [], + Order::SERVICE_PRODUCT_CONTEXT_ROOM_LINKED + ); if ($demands = $objHotelBookingDemands->getExtraDemandsTaxesDetails($objOrder->id)) { $demandsPrice = array_sum(array_column($demands, 'total_price_tax_excl')); // Adding the tax diff --git a/controllers/admin/AdminImportController.php b/controllers/admin/AdminImportController.php index d2819efca..cf130c6e3 100644 --- a/controllers/admin/AdminImportController.php +++ b/controllers/admin/AdminImportController.php @@ -1901,7 +1901,7 @@ class AdminImportControllerCore extends AdminController } $objServiceProduct = new Product($idServiceProduct); - if (Product::SELLING_PREFERENCE_WITH_ROOM_TYPE == $objServiceProduct->selling_preference_type) { + if (Product::isSellableWithRoomType($objServiceProduct->selling_preference_type)) { $objRoomTypeServiceProduct->addRoomProductLink( $objServiceProduct->id, $product->id, @@ -2329,12 +2329,12 @@ class AdminImportControllerCore extends AdminController $info['shop'] = explode($this->multiple_value_separator, $info['shop']); RoomTypeServiceProduct::deleteRoomProductLink($product->id); - if (Product::SELLING_PREFERENCE_WITH_ROOM_TYPE == $product->selling_preference_type) { + if (Product::isSellableWithRoomType($product->selling_preference_type)) { $objRoomTypeServiceProduct = new RoomTypeServiceProduct(); if (isset($info['id_room_types']) && $info['id_room_types']) { $objRoomTypeServiceProduct->addRoomProductLink( $product->id, - $product->id_room_types, + $info['id_room_types'], RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE ); } diff --git a/controllers/front/GuestTrackingController.php b/controllers/front/GuestTrackingController.php index 596d54185..fd684953b 100644 --- a/controllers/front/GuestTrackingController.php +++ b/controllers/front/GuestTrackingController.php @@ -497,7 +497,7 @@ class GuestTrackingControllerCore extends FrontController $value['avg_price_diff_tax_excl'] = abs(Tools::ps_round($value['avg_paid_unit_price_tax_excl'] - $value['product_price_tax_excl'], 6)); $value['avg_price_diff_tax_incl'] = abs(Tools::ps_round($value['avg_paid_unit_price_tax_incl'] - $value['product_price_tax_incl'], 6)); } - } elseif ($type_value['selling_preference_type'] == Product::SELLING_PREFERENCE_WITH_ROOM_TYPE) { + } elseif (Product::isSellableWithRoomType($type_value['selling_preference_type'])) { if ($type_value['product_auto_add'] && $type_value['product_price_addition_type'] == Product::PRICE_ADDITION_TYPE_INDEPENDENT) { $total_convenience_fee_ti += $objServiceProductOrderDetail->getRoomTypeServiceProducts( $idOrder, @@ -524,7 +524,10 @@ class GuestTrackingControllerCore extends FrontController 1 ); } - } else if ($type_value['selling_preference_type'] == Product::SELLING_PREFERENCE_HOTEL_STANDALONE) { + } else if ( + Product::isSellableWithHotel($type_value['selling_preference_type']) + || Product::isSellableAsStandalone($type_value['selling_preference_type']) + ) { $cover_image_arr = $product->getCover($type_value['product_id']); if (!empty($cover_image_arr)) { @@ -532,21 +535,21 @@ class GuestTrackingControllerCore extends FrontController } else { $type_value['cover_img'] = $this->context->link->getImageLink($product->link_rewrite, $this->context->language->iso_code.'-default', 'small_default'); } - $hotelProducts = $objServiceProductOrderDetail->getServiceProductsInOrder($idOrder, $type_value['id_order_detail'], $type_value['product_id']); - foreach ($hotelProducts as $hotelProduct) { - $hotelServiceProducts[] = array_merge($type_value, $hotelProduct); - } - } else if ($type_value['selling_preference_type'] == Product::SELLING_PREFERENCE_STANDALONE) { - $cover_image_arr = $product->getCover($type_value['product_id']); - if (!empty($cover_image_arr)) { - $type_value['cover_img'] = $this->context->link->getImageLink($product->link_rewrite, $product->id.'-'.$cover_image_arr['id_image'], 'small_default'); - } else { - $type_value['cover_img'] = $this->context->link->getImageLink($product->link_rewrite, $this->context->language->iso_code.'-default', 'small_default'); - } - $standaloneProducts = $objServiceProductOrderDetail->getServiceProductsInOrder($idOrder, $type_value['id_order_detail'], $type_value['product_id']); - foreach ($standaloneProducts as $standaloneProduct) { - $standaloneServiceProducts[] = array_merge($type_value, $standaloneProduct); + $serviceProducts = $objServiceProductOrderDetail->getServiceProductsInOrder( + $idOrder, + $type_value['id_order_detail'], + $type_value['product_id'] + ); + foreach ($serviceProducts as $serviceProduct) { + $isStandaloneRow = empty($serviceProduct['id_hotel']) && empty($serviceProduct['id_htl_booking_detail']); + $isHotelRow = !empty($serviceProduct['id_hotel']) && empty($serviceProduct['id_htl_booking_detail']); + + if ($isHotelRow && Product::isSellableWithHotel($type_value['selling_preference_type'])) { + $hotelServiceProducts[] = array_merge($type_value, $serviceProduct); + } elseif ($isStandaloneRow && Product::isSellableAsStandalone($type_value['selling_preference_type'])) { + $standaloneServiceProducts[] = array_merge($type_value, $serviceProduct); + } } } } diff --git a/modules/blockcart/ajax-cart.js b/modules/blockcart/ajax-cart.js index ca2ad2695..85c34b47e 100644 --- a/modules/blockcart/ajax-cart.js +++ b/modules/blockcart/ajax-cart.js @@ -127,6 +127,51 @@ var ajaxCart = { dateFormat: 'DD-MM-YYYY', dateFormatFull: 'DD-MM-YYYY HH:mm:ss', nb_total_products: 0, + getSellingPreferenceChannels: function(sellingPreferenceType) { + var channels = { + with_room_type: false, + with_hotel: false, + standalone: false + }; + switch (parseInt(sellingPreferenceType)) { + case SELLING_PREFERENCE_WITH_ROOM_TYPE: + channels.with_room_type = true; + break; + case SELLING_PREFERENCE_HOTEL_STANDALONE: + channels.with_hotel = true; + break; + case SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE: + channels.with_room_type = true; + channels.with_hotel = true; + break; + case SELLING_PREFERENCE_STANDALONE: + channels.standalone = true; + break; + case SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_STANDALONE: + channels.with_hotel = true; + channels.standalone = true; + break; + case SELLING_PREFERENCE_STANDALONE_AND_WITH_ROOM_TYPE: + channels.with_room_type = true; + channels.standalone = true; + break; + case SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE: + channels.with_room_type = true; + channels.with_hotel = true; + channels.standalone = true; + break; + } + return channels; + }, + isSellableWithRoomType: function(sellingPreferenceType) { + return this.getSellingPreferenceChannels(sellingPreferenceType).with_room_type; + }, + isSellableWithHotel: function(sellingPreferenceType) { + return this.getSellingPreferenceChannels(sellingPreferenceType).with_hotel; + }, + isSellableAsStandalone: function(sellingPreferenceType) { + return this.getSellingPreferenceChannels(sellingPreferenceType).standalone; + }, _overrideButtonsInThePage: function () { //for every 'add' buttons... $(document).off('click', '.ajax_add_to_cart_button').on('click', '.ajax_add_to_cart_button', function (e) { @@ -703,15 +748,13 @@ var ajaxCart = { //try to know if the current product is still in the new list var stayInTheCart = false; + var isHotelRow = (typeof ids[3] != 'undefined' && parseInt(ids[3], 10) > 0); for (aProduct in jsonData.products) { //we've called the variable aProduct because IE6 bug if this variable is called product //if product has attributes - if ((parseInt(jsonData.products[aProduct]['selling_preference_type']) == SELLING_PREFERENCE_HOTEL_STANDALONE - || parseInt(jsonData.products[aProduct]['selling_preference_type']) == SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE) - && (typeof jsonData.products[aProduct]['hotel_wise_data'] != 'undefined' && jsonData.products[aProduct]['hotel_wise_data'].length) - ) { + if (isHotelRow && (typeof jsonData.products[aProduct]['hotel_wise_data'] != 'undefined' && jsonData.products[aProduct]['hotel_wise_data'].length)) { $.each(jsonData.products[aProduct]['hotel_wise_data'], function() { - if (!ids[3] || (ids[3] == this.id_hotel)) { + if (ids[3] == this.id_hotel) { stayInTheCart = true; } }); @@ -835,25 +878,37 @@ var ajaxCart = { $(jsonData.products).each(function(key, value) { //fix ie6 bug (one more item 'undefined' in IE6) if (this.id != undefined) { - if (!this.booking_product && parseInt(this.selling_preference_type) == SELLING_PREFERENCE_WITH_ROOM_TYPE) { - return; - } - //create a container for listing the products and hide the 'no product in the cart' message (only if the cart was empty) - if ($('.cart_block:first dl.products').length == 0) { - $('.cart_block_no_products').before('
'); - $('.cart_block_no_products').hide(); - } - - if (parseInt(this.selling_preference_type) == SELLING_PREFERENCE_HOTEL_STANDALONE - || parseInt(this.selling_preference_type) == SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE + if ( + this.booking_product + || ajaxCart.isSellableWithHotel(parseInt(this.selling_preference_type)) + || ajaxCart.isSellableAsStandalone(parseInt(this.selling_preference_type)) ) { - if (typeof value.hotel_wise_data != 'undefined') { - $(value.hotel_wise_data).each(function(i, val) { - ajaxCart.addProductRow(value, val); - }); + if ($('.cart_block:first dl.products').length == 0) { + $('.cart_block_no_products').before('
'); + $('.cart_block_no_products').hide(); + } + + var hasHotelRows = (typeof value.hotel_wise_data != 'undefined' && value.hotel_wise_data.length); + if (hasHotelRows) { + if (typeof value.hotel_wise_data != 'undefined') { + $(value.hotel_wise_data).each(function(i, val) { + ajaxCart.addProductRow(value, val); + }); + } + } + + var shouldShowStandaloneRow = this.booking_product + || ( + !ajaxCart.isSellableWithHotel(parseInt(this.selling_preference_type)) + && !ajaxCart.isSellableWithRoomType(parseInt(this.selling_preference_type)) + ) + || ( + ajaxCart.isSellableAsStandalone(parseInt(this.selling_preference_type)) + && parseInt(value.standalone_total_qty || 0, 10) > 0 + ); + if (shouldShowStandaloneRow) { + ajaxCart.addProductRow(value); } - } else { - ajaxCart.addProductRow(value); } } }); @@ -876,10 +931,7 @@ var ajaxCart = { content += '
'; content += '' + name + ''; content += '
'; - if ((parseInt(product.selling_preference_type) == SELLING_PREFERENCE_HOTEL_STANDALONE - || parseInt(product.selling_preference_type) == SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE) - && (typeof(hotel_wise_data) != 'undefined' && typeof(hotel_wise_data.hotel_name) != 'undefined') - ) { + if ((typeof(hotel_wise_data) != 'undefined' && typeof(hotel_wise_data.hotel_name) != 'undefined')) { content += '
' + hotel_wise_data.hotel_name + '
'; } @@ -893,10 +945,7 @@ var ajaxCart = { if (product.booking_product) { content += formatCurrency(parseFloat(product.bookingData.total_room_type_amount), currency_format, currency_sign, currency_blank); - }else if ((parseInt(product.selling_preference_type) == SELLING_PREFERENCE_HOTEL_STANDALONE - || parseInt(product.selling_preference_type) == SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE) - && (typeof(hotel_wise_data) != 'undefined') - ) { + } else if (typeof(hotel_wise_data) != 'undefined') { content += formatCurrency(parseFloat(hotel_wise_data.amount), currency_format, currency_sign, currency_blank); } else { content += formatCurrency(parseFloat(product.amount), currency_format, currency_sign, currency_blank); @@ -916,7 +965,7 @@ var ajaxCart = { if (typeof(hotel_wise_data) != 'undefined' && hotel_wise_data.total_qty) { content += hotel_wise_data.total_qty; } else { - content += product.cart_quantity; + content += (typeof product.standalone_total_qty != 'undefined' ? product.standalone_total_qty : product.cart_quantity); } } content += ''; @@ -976,16 +1025,11 @@ var ajaxCart = { content += '' + price_txt + ''; content += ' '; content += ''; - if (parseInt(product.selling_preference_type) == SELLING_PREFERENCE_HOTEL_STANDALONE - || parseInt(product.selling_preference_type) == SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE - ) { - if (hotel_wise_data.options !== 'undefined') { - var options = hotel_wise_data.options; - } - } else if (parseInt(product.selling_preference_type) == SELLING_PREFERENCE_STANDALONE) { - if (product.options !== 'undefined') { - var options = product.options; - } + var options = []; + if (typeof(hotel_wise_data) != 'undefined' && typeof(hotel_wise_data.options) != 'undefined') { + options = hotel_wise_data.options; + } else if (typeof(product.options) != 'undefined') { + options = product.options; } if (options !== 'undefined') { $.each(options, function(data_k, data_v) { @@ -1043,16 +1087,11 @@ var ajaxCart = { } else if (product.hasOptions) { $('dt[data-id="cart_block_product_' + productDomId + '"] .cart_prod_cont tr.product_option_row').remove(); var product_options_content = ''; - if (parseInt(product.selling_preference_type) == SELLING_PREFERENCE_HOTEL_STANDALONE - || parseInt(product.selling_preference_type) == SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE - ) { - if (hotel_wise_data.options !== 'undefined') { - var options = hotel_wise_data.options; - } - } else if (parseInt(product.selling_preference_type) == SELLING_PREFERENCE_STANDALONE) { - if (product.options !== 'undefined') { - var options = product.options; - } + var options = []; + if (typeof(hotel_wise_data) != 'undefined' && typeof(hotel_wise_data.options) != 'undefined') { + options = hotel_wise_data.options; + } else if (typeof(product.options) != 'undefined') { + options = product.options; } if (options !== 'undefined') { $.each(options, function(data_k, data_v) { @@ -1077,10 +1116,7 @@ var ajaxCart = { if (!product.is_gift) { if (product.booking_product) { $('dt[data-id="cart_block_product_' + productDomId + '"] .price').text(formatCurrency(parseFloat(product.bookingData.total_room_type_amount), currency_format, currency_sign, currency_blank)); - } else if ((parseInt(product.selling_preference_type) == SELLING_PREFERENCE_HOTEL_STANDALONE - || parseInt(product.selling_preference_type) == SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE) - && typeof(hotel_wise_data) != 'undefined' - ) { + } else if (typeof(hotel_wise_data) != 'undefined') { $('dt[data-id="cart_block_product_' + productDomId + '"] .price').text(formatCurrency(parseFloat(hotel_wise_data.amount), currency_format, currency_sign, currency_blank)); } else { $('dt[data-id="cart_block_product_' + productDomId + '"] .price').text(formatCurrency(parseFloat(product.amount), currency_format, currency_sign, currency_blank)); @@ -1091,15 +1127,16 @@ var ajaxCart = { //cart_booking_data[key].total_num_rooms argument sent to update num of rooms instead of quantity if (product.booking_product) { ajaxCart.updateProductQuantity(jsonProduct, product.bookingData.total_num_rooms); - } else if ((parseInt(product.selling_preference_type) == SELLING_PREFERENCE_HOTEL_STANDALONE - || parseInt(product.selling_preference_type) == SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE - ) - && typeof(hotel_wise_data) != 'undefined' + } else if ( + typeof(hotel_wise_data) != 'undefined' && hotel_wise_data.total_qty ) { ajaxCart.updateProductQuantity(jsonProduct, hotel_wise_data.total_qty, hotel_wise_data); } else { - ajaxCart.updateProductQuantity(jsonProduct, jsonProduct.cart_quantity); + ajaxCart.updateProductQuantity( + jsonProduct, + (typeof jsonProduct.standalone_total_qty != 'undefined' ? jsonProduct.standalone_total_qty : jsonProduct.cart_quantity) + ); } // Customized product diff --git a/modules/blockcart/blockcart.tpl b/modules/blockcart/blockcart.tpl index af73ec530..ec29d14f4 100644 --- a/modules/blockcart/blockcart.tpl +++ b/modules/blockcart/blockcart.tpl @@ -63,14 +63,15 @@
{foreach from=$products key=data_k item='product' name='myLoop'} {* only show products that are booking or global without room *} - {if $product.booking_product || ($product.selling_preference_type == Product::SELLING_PREFERENCE_STANDALONE)|| ($product.selling_preference_type == Product::SELLING_PREFERENCE_HOTEL_STANDALONE) || ($product.selling_preference_type == Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE)} - {if $product.selling_preference_type == Product::SELLING_PREFERENCE_HOTEL_STANDALONE || $product.selling_preference_type == Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE} - {if isset($product.hotel_wise_data) && $product.hotel_wise_data} - {foreach $product.hotel_wise_data as $hotel_wise_data} - {include file="./cartrow.tpl" hotel_wise_data=$hotel_wise_data} - {/foreach} - {/if} - {else} + {if $product.booking_product || Product::isSellableAsStandalone($product.selling_preference_type) || Product::isSellableWithHotel($product.selling_preference_type)} + {if isset($product.hotel_wise_data) && $product.hotel_wise_data} + {foreach $product.hotel_wise_data as $hotel_wise_data} + {include file="./cartrow.tpl" hotel_wise_data=$hotel_wise_data} + {/foreach} + {/if} + {if $product.booking_product + || (!Product::isSellableWithHotel($product.selling_preference_type) && !Product::isSellableWithRoomType($product.selling_preference_type)) + || (Product::isSellableAsStandalone($product.selling_preference_type) && $product.standalone_total_qty > 0)} {include file="./cartrow.tpl" hotel_wise_data=false} {/if} {/if} @@ -401,11 +402,13 @@ {addJsDef img_dir=$img_dir|escape:'quotes':'UTF-8'} {addJsDef generated_date=$smarty.now|intval} {addJsDef ajax_allowed=$ajax_allowed|boolval} - {addJsDef hasDeliveryAddress=(isset($cart->id_address_delivery) && $cart->id_address_delivery)} {addJsDef SELLING_PREFERENCE_WITH_ROOM_TYPE=Product::SELLING_PREFERENCE_WITH_ROOM_TYPE} {addJsDef SELLING_PREFERENCE_STANDALONE=Product::SELLING_PREFERENCE_STANDALONE} {addJsDef SELLING_PREFERENCE_HOTEL_STANDALONE=Product::SELLING_PREFERENCE_HOTEL_STANDALONE} {addJsDef SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE=Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE} + {addJsDef SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_STANDALONE=Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_STANDALONE} + {addJsDef SELLING_PREFERENCE_STANDALONE_AND_WITH_ROOM_TYPE=Product::SELLING_PREFERENCE_STANDALONE_AND_WITH_ROOM_TYPE} + {addJsDef SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE=Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE} {addJsDefL name=customizationIdMessage}{l s='Customization #' mod='blockcart' js=1}{/addJsDefL} {addJsDefL name=removingLinkText}{l s='remove this product from my cart' mod='blockcart' js=1}{/addJsDefL} diff --git a/modules/blockcart/cartrow.tpl b/modules/blockcart/cartrow.tpl index e909aaacf..68d0cbc96 100644 --- a/modules/blockcart/cartrow.tpl +++ b/modules/blockcart/cartrow.tpl @@ -11,7 +11,7 @@ {/block} {block name='blockcart_shopping_cart_hotel_name'} - {if $product.selling_preference_type == Product::SELLING_PREFERENCE_HOTEL_STANDALONE || $product.selling_preference_type == Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE} + {if Product::isSellableWithHotel($product.selling_preference_type)}
{$hotel_wise_data.hotel_name|escape:'html':'UTF-8'}
@@ -29,7 +29,7 @@ {if !isset($product.is_gift) || !$product.is_gift} {if $product.booking_product} {displayWtPrice p="`$product.bookingData.total_room_type_amount`"} - {else if $product.selling_preference_type == Product::SELLING_PREFERENCE_HOTEL_STANDALONE || $product.selling_preference_type == Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE} + {else if Product::isSellableWithHotel($product.selling_preference_type)} {if $priceDisplay == $smarty.const.PS_TAX_EXC}{displayWtPrice p="`$hotel_wise_data.total_price_tax_excl`"}{else}{displayWtPrice p="`$hotel_wise_data.total_price_tax_incl`"}{/if} {else} {if $priceDisplay == $smarty.const.PS_TAX_EXC}{displayWtPrice p="`$product.total_price_tax_excl`"}{else}{displayWtPrice p="`$product.total_price_tax_incl`"}{/if} @@ -53,9 +53,9 @@ {if $product.booking_product} {$product.bookingData['total_num_rooms']} {elseif $product.allow_multiple_quantity} - {if $product.selling_preference_type == Product::SELLING_PREFERENCE_HOTEL_STANDALONE || $product.selling_preference_type == Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE} + {if Product::isSellableWithHotel($product.selling_preference_type)} {$hotel_wise_data.total_qty} - {elseif $product.selling_preference_type == Product::SELLING_PREFERENCE_STANDALONE} + {elseif Product::isSellableAsStandalone($product.selling_preference_type)} {$product.cart_quantity} {/if} {/if} @@ -99,9 +99,9 @@ {/block} {else if $product.hasOptions} {block name='blockcart_shopping_cart_options'} - {if $product.selling_preference_type == Product::SELLING_PREFERENCE_HOTEL_STANDALONE || $product.selling_preference_type == Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE} + {if Product::isSellableWithHotel($product.selling_preference_type)} {assign var='options' value=$hotel_wise_data.options} - {else if $product.selling_preference_type == Product::SELLING_PREFERENCE_STANDALONE} + {else if Product::isSellableAsStandalone($product.selling_preference_type)} {assign var='options' value=$product.options} {/if}
diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php index fac60d468..b86558c85 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php @@ -625,9 +625,9 @@ class AdminHotelRoomsBookingController extends ModuleAdminController if (!$product->id || !$product->active) { $this->errors[] = $this->l('This product is no longer available.'); } - if ($product->booking_product || ($product->selling_preference_type != Product::SELLING_PREFERENCE_STANDALONE)) { + if ($product->booking_product || !Product::isSellableAsStandalone($product->selling_preference_type)) { // cannot be added without room type or is a booking product. - $this->errors[] = $this->l('This product is either a room type or additional service and cannot be added thorugh this method.'); + $this->errors[] = $this->l('This product is either a room type or additional service and cannot be added through this method.'); } elseif (!$product->allow_multiple_quantity) { // check if product already exists in cart. if ($id_cart) {