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('