diff --git a/admin/themes/default/template/controllers/normal_products/informations.tpl b/admin/themes/default/template/controllers/normal_products/informations.tpl index 3bf54bd1b..b1d0b9f72 100644 --- a/admin/themes/default/template/controllers/normal_products/informations.tpl +++ b/admin/themes/default/template/controllers/normal_products/informations.tpl @@ -231,21 +231,34 @@ {* Code For Standard product working *}
-
- - + + +
+ +
+
+ +
+
+ +
diff --git a/admin/themes/default/template/controllers/orders/modals/_extra_services_facilities_tab_content.tpl b/admin/themes/default/template/controllers/orders/modals/_extra_services_facilities_tab_content.tpl index 3537d8dd2..e4f40435a 100644 --- a/admin/themes/default/template/controllers/orders/modals/_extra_services_facilities_tab_content.tpl +++ b/admin/themes/default/template/controllers/orders/modals/_extra_services_facilities_tab_content.tpl @@ -51,7 +51,7 @@ {$currencySign} {if $demand['price_calc_method'] == HotelRoomTypeGlobalDemand::WK_PRICE_CALC_METHOD_EACH_DAY} - {l s='/ night'} + {l s='/ day'} {/if}
@@ -122,7 +122,7 @@ {/if} {if $demand['price_calc_method'] == HotelRoomTypeGlobalDemand::WK_PRICE_CALC_METHOD_EACH_DAY} - {l s='/ night'} + {l s='/ day'} {/if}
@@ -159,7 +159,7 @@ {displayPrice price=$demand['unit_price_tax_excl'] currency=$orderCurrency} {if $demand['price_calc_method'] == HotelRoomTypeGlobalDemand::WK_PRICE_CALC_METHOD_EACH_DAY} - {l s='/ night'} + {l s='/ day'} {/if} {displayPrice price=$demand['total_price_tax_excl'] currency=$orderCurrency} diff --git a/admin/themes/default/template/controllers/orders/modals/_extra_services_service_products_tab_content.tpl b/admin/themes/default/template/controllers/orders/modals/_extra_services_service_products_tab_content.tpl index 4f6ce1c58..d8d3ef96d 100644 --- a/admin/themes/default/template/controllers/orders/modals/_extra_services_service_products_tab_content.tpl +++ b/admin/themes/default/template/controllers/orders/modals/_extra_services_service_products_tab_content.tpl @@ -87,7 +87,7 @@ $additionalServices['date_from'], $additionalServices['date_to'] ) > 1} - {l s='/ night'} + {l s='/ day'} {/if} @@ -161,7 +161,7 @@ $additionalServices['date_from'], $additionalServices['date_to'] ) > 1} - {l s='/ night'} + {l s='/ day'} {/if} @@ -197,16 +197,26 @@
- - + + +
+ +
+
+ +
+
+ +
@@ -304,7 +314,7 @@ $additionalServices['date_from'], $additionalServices['date_to'] ) > 1} - {l s='/ night'} + {l s='/ day'} {/if} diff --git a/classes/Cart.php b/classes/Cart.php index ced44ff2d..d544f3cf9 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -827,7 +827,7 @@ class CartCore extends ObjectModel $serviceProducts = array(); $context = Context::getContext(); foreach ($productList as $key => $product) { - if (!$product['booking_product'] && Product::isSellableAsStandalone($product['selling_preference_type'])) { + if (!$product['booking_product'] && Product::isSellableAsStandalone($product['selling_preference_type'] && !Product::isSellableWithRoomType($product['selling_preference_type']))) { if (Validate::isLoadedObject( $objProduct = new Product($product['id_product'], false, $this->id_lang) )) { @@ -1756,124 +1756,102 @@ class CartCore extends ObjectModel $canSellWithRoomType = Product::isSellableWithRoomType($product['selling_preference_type']); $canSellWithHotel = Product::isSellableWithHotel($product['selling_preference_type']); $canSellAsStandalone = Product::isSellableAsStandalone($product['selling_preference_type']); + $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, + )); - if ($canSellAsStandalone - && (!$canSellWithHotel && !$canSellWithRoomType - || ($type == Cart::ONLY_STANDALONE_PRODUCTS && !$canSellWithHotel)) - ) { + if ($canSellAsStandalone && !$isRoomServiceTotalType) { $idHotelCartBooking = isset($product['id_hotel_cart_booking']) ? (int)$product['id_hotel_cart_booking'] : 0; $idHotel = isset($product['id_hotel']) ? (int)$product['id_hotel'] : 0; - if ($servicePorducts = $objServiceProductCartDetail->getServiceProductsInCart( + if ($serviceProducts = $objServiceProductCartDetail->getServiceProductsInCart( $this->id, [], - $idHotel, - $idHotelCartBooking, + 0, + 0, null, (int)$product['id_product'] )) { - foreach ($servicePorducts as $servicePorduct) { + foreach ($serviceProducts as $serviceProduct) { if ($with_taxes) { - $priceAdd = $servicePorduct['unit_price_tax_incl']; + $priceAdd = $serviceProduct['unit_price_tax_incl']; } else { - $priceAdd = $servicePorduct['unit_price_tax_excl']; + $priceAdd = $serviceProduct['unit_price_tax_excl']; } if ($ps_round_type == Order::ROUND_TOTAL) { - $products_total[$id_tax_rules_group.'_'.$id_address] += $priceAdd * (int)$servicePorduct['quantity']; + $products_total[$id_tax_rules_group.'_'.$id_address] += $priceAdd * (int)$serviceProduct['quantity']; } else { - $products_total[$id_tax_rules_group] += $priceAdd * (int)$servicePorduct['quantity']; + $products_total[$id_tax_rules_group] += $priceAdd * (int)$serviceProduct['quantity']; } + } } - } else if ($canSellWithHotel) { - $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 { - $priceAdd = $servicePorduct['total_price_tax_excl']; - } - - if ($ps_round_type == Order::ROUND_TOTAL) { - $products_total[$id_tax_rules_group.'_'.$id_address] += $priceAdd; - } else { - $products_total[$id_tax_rules_group] += $priceAdd; - } - } - } - } else if ($canSellWithRoomType) { - $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, - )); - - $idHotelCartBooking = null; - if ($param_product && isset($product['id_hotel_cart_booking'])) { - $idHotelCartBooking = (int)$product['id_hotel_cart_booking']; + } + 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 + ) { + $serviceProducts = $objServiceProductCartDetail->getServiceProductsInCart( + $this->id, + [], + 0, + null, + null, + (int)$product['id_product'] + ); } elseif ($type == Cart::ONLY_STANDALONE_PRODUCTS) { - $idHotelCartBooking = 0; + $serviceProducts = $objServiceProductCartDetail->getServiceProductsInCart( + $this->id, + [], + null, + 0, + null, + (int)$product['id_product'] + ); + } else { + $serviceProducts = $objServiceProductCartDetail->getServiceProductsInCart( + $this->id, + [], + isset($product['id_hotel']) ? $product['id_hotel'] : null, + null, + null, + (int)$product['id_product'] + ); } + if ($serviceProducts) { + foreach ($serviceProducts as $serviceProduct) { + if(!empty($serviceProduct['id_hotel']) && empty($serviceProduct['id_hotel_cart_booking'])) { + if ($with_taxes) { + $priceAdd = $serviceProduct['total_price_tax_incl']; + } else { + $priceAdd = $serviceProduct['total_price_tax_excl']; + } + + if ($ps_round_type == Order::ROUND_TOTAL) { + $products_total[$id_tax_rules_group.'_'.$id_address] += $priceAdd; + } else { + $products_total[$id_tax_rules_group] += $priceAdd; + } + } + } + } + } + if ($canSellWithRoomType && $type !== Cart::ONLY_STANDALONE_PRODUCTS) { + if ($servicesWithRoom = $objServiceProductCartDetail->getServiceProductsInCart( $this->id, [], 0, - $idHotelCartBooking, + null, null, (int)$product['id_product'], null, @@ -1883,27 +1861,19 @@ class CartCore extends ObjectModel (int)$product['price_addition_type'] )) { foreach ($servicesWithRoom as $service) { - if ($param_product && $idHotelCartBooking !== null) { - if (!$idHotelCartBooking && !empty($service['id_hotel_cart_booking'])) { - continue; + if(!empty($service['id_hotel_cart_booking']) && empty($service['id_hotel'])) { + if ($with_taxes) { + $servicePrice = $service['total_price_tax_incl']; + } else { + $servicePrice = $service['total_price_tax_excl']; } - if ($idHotelCartBooking && (int)$service['id_hotel_cart_booking'] !== $idHotelCartBooking) { - continue; - } - } elseif ($isRoomServiceTotalType && empty($service['id_hotel_cart_booking'])) { - continue; - } - if ($with_taxes) { - $servicePrice = $service['total_price_tax_incl']; - } else { - $servicePrice = $service['total_price_tax_excl']; - } - // Rounding as per configurations - if ($ps_round_type == Order::ROUND_TOTAL) { - $products_total[$id_tax_rules_group.'_'.$id_address] += $servicePrice; - } else { - $products_total[$id_tax_rules_group] += $servicePrice; + // Rounding as per configurations + if ($ps_round_type == Order::ROUND_TOTAL) { + $products_total[$id_tax_rules_group.'_'.$id_address] += $servicePrice; + } else { + $products_total[$id_tax_rules_group] += $servicePrice; + } } } } @@ -2495,16 +2465,12 @@ class CartCore extends ObjectModel 'id_hotel_cart_booking' => $selectedProduct['id_hotel_cart_booking'], ); } - if (Product::PRICE_CALCULATION_METHOD_PER_DAY == $selectedProduct['price_calculation_method']) { - $numDays = HotelHelper::getNumberOfDays( - $selectedProduct['date_from'], - $selectedProduct['date_to'] - ); - $array[$selectedProduct['id_room_type_hotel']]['quantity'] += ($selectedProduct['quantity'] * $numDays); - } else { - $array[$selectedProduct['id_room_type_hotel']]['quantity'] += $selectedProduct['quantity']; - - } + $numDays = Product::getPriceCalculationApplicableDays( + $selectedProduct['price_calculation_method'], + $selectedProduct['date_from'], + $selectedProduct['date_to'] + ); + $array[$selectedProduct['id_room_type_hotel']]['quantity'] += ($selectedProduct['quantity'] * $numDays); } if ($array) { @@ -2512,8 +2478,8 @@ class CartCore extends ObjectModel $product['cart_quantity'] = $selectedProduct['quantity']; $product['total'] = $selectedProduct['total_price_tax_excl']; $product['total_wt'] = $selectedProduct['total_price_tax_incl']; - $product['price_wt'] = $selectedProduct['total_price_tax_incl'] / $selectedProduct['quantity']; - $product['price'] = $selectedProduct['total_price_tax_excl'] / $selectedProduct['quantity']; + $product['price_wt'] = $selectedProduct['total_price_tax_incl'] / max($selectedProduct['quantity'], 1); + $product['price'] = $selectedProduct['total_price_tax_excl'] / max($selectedProduct['quantity'], 1); $product['id_hotel'] = $selectedProduct['id_hotel']; $product['id_room_type'] = $selectedProduct['id_room_type']; $product['id_hotel_cart_booking'] = $selectedProduct['id_hotel_cart_booking']; diff --git a/classes/PaymentModule.php b/classes/PaymentModule.php index a022f3484..43158862f 100644 --- a/classes/PaymentModule.php +++ b/classes/PaymentModule.php @@ -505,7 +505,6 @@ abstract class PaymentModuleCore extends Module $objMail = new Mail(); $objServiceProductCartDetail = new ServiceProductCartDetail(); $cart_rules = $this->context->cart->getCartRules(); - foreach ($order_detail_list as $key => $order_detail) { /** @var OrderDetail $order_detail */ @@ -541,7 +540,6 @@ abstract class PaymentModuleCore extends Module $product_var_tpl_list = array(); $orderServiceProducts = array(); - $processedServiceProductCartIds = array(); $objProduct = new Product(); foreach ($order->product_list as $product) { @@ -970,11 +968,9 @@ abstract class PaymentModuleCore extends Module $objServiceProductCartDetail = new ServiceProductCartDetail(); foreach ($normalProducts as $product) { $idProduct = $product['id_product']; - $canSellWithRoomType = Product::isSellableWithRoomType($product['selling_preference_type']); - $canSellWithHotel = Product::isSellableWithHotel($product['selling_preference_type']); - $canSellAsStandalone = Product::isSellableAsStandalone($product['selling_preference_type']); + $productSellingType = $product['selling_preference_type']; - if ($canSellWithRoomType && !$canSellWithHotel && !$canSellAsStandalone) { + if (Product::isSellableWithRoomType($productSellingType)) { if ($roomTypeServices = $objServiceProductCartDetail->getServiceProductsInCart( $this->context->cart->id, [], @@ -983,16 +979,10 @@ abstract class PaymentModuleCore extends Module null, $product['id_product'] )) { - $idOrderDetail = $objBookingDetail->getPsOrderDetailIdByIdProduct( - $idProduct, - $order->id, - $product['selling_preference_type'] - ); + + $idOrderDetail = $objBookingDetail->getPsOrderDetailIdByIdProduct($idProduct, $order->id, $product['selling_preference_type']); foreach ($roomTypeServices as $roomTypeService) { - if (!Validate::isDate($roomTypeService['date_from']) - || !Validate::isDate($roomTypeService['date_to']) - || !(int) $roomTypeService['id_room_type'] - ) { + if (!$roomTypeService['id_hotel_cart_booking']) { continue; } $roomBookingDetail = $objBookingDetail->getRowByIdOrderIdProductInDateRange( @@ -1002,9 +992,6 @@ abstract class PaymentModuleCore extends Module $roomTypeService['date_to'], $roomTypeService['id_room'] ); - if (empty($roomBookingDetail['id'])) { - continue; - } $objServiceProductOrderDetail = new ServiceProductOrderDetail(); $objServiceProductOrderDetail->id_product = $idProduct; $objServiceProductOrderDetail->id_order = $order->id; @@ -1021,7 +1008,7 @@ abstract class PaymentModuleCore extends Module $objServiceProductOrderDetail->save(); } } - } elseif ($canSellWithHotel && !$canSellWithRoomType && !$canSellAsStandalone) { + } elseif (Product::isSellableWithHotel($productSellingType)) { if ($hotelProducts = $objServiceProductCartDetail->getServiceProductsInCart( $this->context->cart->id, [], @@ -1030,11 +1017,7 @@ abstract class PaymentModuleCore extends Module null, $product['id_product'] )) { - $idOrderDetail = $objBookingDetail->getPsOrderDetailIdByIdProduct( - $idProduct, - $order->id, - $product['selling_preference_type'] - ); + $idOrderDetail = $objBookingDetail->getPsOrderDetailIdByIdProduct($idProduct, $order->id, $product['selling_preference_type']); foreach ($hotelProducts as $hotelProduct) { $objServiceProductOrderDetail = new ServiceProductOrderDetail(); $objServiceProductOrderDetail->id_product = $idProduct; @@ -1056,9 +1039,10 @@ abstract class PaymentModuleCore extends Module } $objServiceProductOrderDetail->quantity = $hotelProduct['quantity']; $objServiceProductOrderDetail->save(); + } } - } elseif ($canSellAsStandalone && !$canSellWithRoomType && !$canSellWithHotel) { + } elseif (Product::isSellableAsStandalone($productSellingType)) { if ($standaloneProducts = $objServiceProductCartDetail->getServiceProductsInCart( $this->context->cart->id, [], @@ -1067,11 +1051,7 @@ abstract class PaymentModuleCore extends Module null, $product['id_product'] )) { - $idOrderDetail = $objBookingDetail->getPsOrderDetailIdByIdProduct( - $idProduct, - $order->id, - $product['selling_preference_type'] - ); + $idOrderDetail = $objBookingDetail->getPsOrderDetailIdByIdProduct($idProduct, $order->id, $product['selling_preference_type']); foreach ($standaloneProducts as $standaloneProduct) { $objServiceProductOrderDetail = new ServiceProductOrderDetail(); $objServiceProductOrderDetail->id_product = $idProduct; @@ -1089,7 +1069,7 @@ abstract class PaymentModuleCore extends Module $objServiceProductOrderDetail->save(); } } - } + } } } diff --git a/classes/Product.php b/classes/Product.php index dcf55eb40..f88ec4917 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -569,12 +569,10 @@ class ProductCore extends ObjectModel const PRICE_ADDITION_TYPE_WITH_ROOM = 1; const PRICE_ADDITION_TYPE_INDEPENDENT = 2; - const PRICE_CALCULATION_METHOD_PER_DAY = 1; - const PRICE_CALCULATION_METHOD_ONLY_CHECKIN_DAY = 1; const PRICE_CALCULATION_METHOD_ONLY_CHECKOUT_DAY = 2; - const PRICE_CALCULATION_METHOD_ONLY_DURINGSTAY_DAY = 3; - const PRICE_CALCULATION_METHOD_CHECKIN_DAY_AND_CHECKOUT_DAY = 4; + const PRICE_CALCULATION_METHOD_ONLY_DURINGSTAY_DAY = 4; + const PRICE_CALCULATION_METHOD_CHECKIN_DAY_AND_CHECKOUT_DAY = 3; const PRICE_CALCULATION_METHOD_CHECKIN_AND_DURINGSTAY = 5; const PRICE_CALCULATION_METHOD_CHECKOUT_AND_DURINGSTAY = 6; const PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURINGSTAY = 7; @@ -6909,23 +6907,31 @@ class ProductCore extends ObjectModel return (int) $defaultDays; } + $checkin = 1; + $checkout = 1; + $duringStay = max($numNights - 1, 0); + switch ((int) $priceCalculationMethod) { case self::PRICE_CALCULATION_METHOD_ONLY_CHECKIN_DAY: + return $checkin; + case self::PRICE_CALCULATION_METHOD_ONLY_CHECKOUT_DAY: - return 1; + return $checkout; case self::PRICE_CALCULATION_METHOD_ONLY_DURINGSTAY_DAY: - return max($numNights - 1, 1); + return $duringStay; case self::PRICE_CALCULATION_METHOD_CHECKIN_DAY_AND_CHECKOUT_DAY: - return 2; + return $checkin + $checkout; case self::PRICE_CALCULATION_METHOD_CHECKIN_AND_DURINGSTAY: + return $checkin + $duringStay; + case self::PRICE_CALCULATION_METHOD_CHECKOUT_AND_DURINGSTAY: - return $numNights; + return $checkout + $duringStay; case self::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURINGSTAY: - return $numNights + 1; + return $checkin + $checkout + $duringStay; default: return $numNights; diff --git a/classes/order/Order.php b/classes/order/Order.php index 0ed9581a3..26ee52823 100644 --- a/classes/order/Order.php +++ b/classes/order/Order.php @@ -47,9 +47,6 @@ class OrderCore extends ObjectModel const ORDER_COMPLETE_CANCELLATION_OR_REFUND_REQUEST_FLAG = 3; - const SERVICE_PRODUCT_CONTEXT_ROOM_LINKED = 1; - const SERVICE_PRODUCT_CONTEXT_NON_ROOM = 2; - /** @var int Delivery address id */ public $id_address_delivery; @@ -2581,12 +2578,11 @@ class OrderCore extends ObjectModel )) { $totals = array_reduce($serviceProductDetail, function ($carry, $item) use ($order_detail) { $objHotelBookingDetail = new HotelBookingDetail((int) $item['id_htl_booking_detail']); - $numDays = 1; - if ((Product::PRICE_CALCULATION_METHOD_PER_DAY == $order_detail['product_price_calculation_method']) - && (!$numDays = HotelHelper::getNumberOfDays($objHotelBookingDetail->date_from, $objHotelBookingDetail->date_to)) - ) { - $numDays = 1; - } + $numDays = Product::getPriceCalculationApplicableDays( + $order_detail['product_price_calculation_method'], + $objHotelBookingDetail->date_from, + $objHotelBookingDetail->date_to + ); if (!empty($item['id_tax_rules_group'])) { $qty = isset($item['quantity']) ? $item['quantity'] : 0; @@ -2637,12 +2633,11 @@ class OrderCore extends ObjectModel // We are getting auto added service for specific room.There will be only on htl_booking_detail but can have multiple auto added service with room. // Note: All the auto added service with room have same id_tax_rule group $autoAddedServiceData = array_shift($autoAddedServiceData); - $numDays = 1; - if ((Product::PRICE_CALCULATION_METHOD_PER_DAY == $order_detail['product_price_calculation_method']) - && (!$numDays = HotelHelper::getNumberOfDays($autoAddedServiceData['date_from'], $autoAddedServiceData['date_to'])) - ) { - $numDays = 1; - } + $numDays = Product::getPriceCalculationApplicableDays( + $order_detail['product_price_calculation_method'], + $autoAddedServiceData['date_from'], + $autoAddedServiceData['date_to'] + ); $autoAddedServices = $autoAddedServiceData['additional_services']; // Calculate total quantity of auto-added services diff --git a/classes/order/OrderDetail.php b/classes/order/OrderDetail.php index 3f37eeb1d..4b28d23ff 100644 --- a/classes/order/OrderDetail.php +++ b/classes/order/OrderDetail.php @@ -450,12 +450,11 @@ class OrderDetailCore extends ObjectModel $taxGroupInfo['id_room_type'], )) { $serviceProductData = array_shift($serviceProductData); - $numDays = 1; - if ((Product::PRICE_CALCULATION_METHOD_PER_DAY == $this->product_price_calculation_method) - && (!$numDays = HotelHelper::getNumberOfDays($serviceProductData['date_from'], $serviceProductData['date_to'])) - ) { - $numDays = 1; - } + $numDays = Product::getPriceCalculationApplicableDays( + $this->product_price_calculation_method, + $serviceProductData['date_from'], + $serviceProductData['date_to'] + ); $unit_price_tax_excl = array_reduce($serviceProductData['additional_services'], function ($unitPriceTaxExcl, $item) { return $unitPriceTaxExcl + (isset($item['unit_price_tax_excl']) ? $item['unit_price_tax_excl'] : 0); @@ -488,12 +487,11 @@ class OrderDetailCore extends ObjectModel $serviceProductData = array_shift($serviceProductData); - $numDays = 1; - if ((Product::PRICE_CALCULATION_METHOD_PER_DAY == $this->product_price_calculation_method) - && (!$numDays = HotelHelper::getNumberOfDays($serviceProductData['date_from'], $serviceProductData['date_to'])) - ) { - $numDays = 1; - } + $numDays = Product::getPriceCalculationApplicableDays( + $this->product_price_calculation_method, + $serviceProductData['date_from'], + $serviceProductData['date_to'] + ); $quantity = $quantity * $numDays; } diff --git a/classes/order/OrderInvoice.php b/classes/order/OrderInvoice.php index f97c589fc..457a0baa9 100644 --- a/classes/order/OrderInvoice.php +++ b/classes/order/OrderInvoice.php @@ -483,7 +483,7 @@ class OrderInvoiceCore extends ObjectModel return (!$v['is_booking_product'] && !$v['product_auto_add'] && Product::isSellableWithRoomType($v['selling_preference_type'])); }); - $details = $order->getProductTaxesDetails($order_detail, false); + $details = $order->getProductTaxesDetails($order_detail, false,Product::SELLING_PREFERENCE_WITH_ROOM_TYPE); if ($sum_composite_taxes) { $grouped_details = array(); @@ -550,7 +550,7 @@ class OrderInvoiceCore extends ObjectModel ); }); - $details = $order->getProductTaxesDetails($order_detail, false); + $details = $order->getProductTaxesDetails($order_detail, false, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE); if ($sum_composite_taxes) { $grouped_details = array(); @@ -609,8 +609,6 @@ class OrderInvoiceCore extends ObjectModel // - 'total_price_tax_excl' // - 'total_amount' $breakdown = array(); - $order_detail = array(); - $products = $this->getProducts(); $order_detail = $this->getProducts(); $order_detail = array_filter($order_detail, function($v) { return (!$v['is_booking_product'] && ( diff --git a/classes/webservice/WebserviceSpecificManagementBookings.php b/classes/webservice/WebserviceSpecificManagementBookings.php index ad3586d3b..e234ef7fa 100644 --- a/classes/webservice/WebserviceSpecificManagementBookings.php +++ b/classes/webservice/WebserviceSpecificManagementBookings.php @@ -1015,15 +1015,7 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We } } - $serviceProductPrice = $objOrder->getTotalProductsWithTaxes( - false, - false, - null, - null, - null, - [], - Order::SERVICE_PRODUCT_CONTEXT_ROOM_LINKED - ); + $serviceProductPrice = $objOrder->getTotalProductsWithTaxes(false, false, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE); if ($demands = $objHotelBookingDemands->getExtraDemandsTaxesDetails($objOrder->id)) { $demandsPrice = array_sum(array_column($demands, 'total_price_tax_excl')); // Adding the tax @@ -1187,12 +1179,11 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We $objOrderDetail = new OrderDetail($service['id_order_detail']); $objServiceProductOrderDetail = new ServiceProductOrderDetail($service['id_service_product_order_detail']); $quantity = $objServiceProductOrderDetail->quantity; - if ($objOrderDetail->product_price_calculation_method == Product::PRICE_CALCULATION_METHOD_PER_DAY) { - $quantity = $quantity * HotelHelper::getNumberOfDays( - $objHotelBookingDetail->date_from, - $objHotelBookingDetail->date_to - ); - } + $quantity *= Product::getPriceCalculationApplicableDays( + $objOrderDetail->product_price_calculation_method, + $objHotelBookingDetail->date_from, + $objHotelBookingDetail->date_to + ); if (isset($this->wsRequestedRoomTypes[$dateRoomJoinKey]['services'][$service['id_product']])) { $oldPriceTaxExcl = $objServiceProductOrderDetail->total_price_tax_excl; diff --git a/controllers/admin/AdminCartsController.php b/controllers/admin/AdminCartsController.php index c38b6d896..2b8115761 100644 --- a/controllers/admin/AdminCartsController.php +++ b/controllers/admin/AdminCartsController.php @@ -1211,33 +1211,39 @@ class AdminCartsControllerCore extends AdminController $objProduct->getServiceProducts(true, Product::SELLING_PREFERENCE_STANDALONE_AND_WITH_ROOM_TYPE), $objProduct->getServiceProducts(true, Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE) ); + if ($serviceProducts) { + foreach ($serviceProducts as $key => $servProduct) { + if (!Product::isAvailableWhenOutOfStock(StockAvailable::outOfStock((int)$servProduct['id_product'])) + && Product::getQuantity((int)$servProduct['id_product']) <= 0 + ) { + unset($serviceProducts[$key]); + continue; + } + $numDays = Product::getPriceCalculationApplicableDays( + $servProduct['price_calculation_method'], + $dateFrom, + $dateTo + ); + + $serviceProducts[$key]['price_tax_exc'] = Product::getServiceProductPrice( + $servProduct['id_product'], + 0, + 0, + $idProduct, + false, + 1, + $dateFrom, + $dateTo, + $idCart + ) / max($numDays, 1); + } + } + } else { $objRoomTypeServiceProduct = new RoomTypeServiceProduct(); $serviceProducts = $objRoomTypeServiceProduct->getServiceProductsData($idProduct, 1, 0, false, 2, null); } - if ($serviceProducts) { - foreach ($serviceProducts as $key => $servProduct) { - $numDays = Product::getPriceCalculationApplicableDays( - $servProduct['price_calculation_method'], - $dateFrom, - $dateTo - ); - - $serviceProducts[$key]['price_tax_exc'] = Product::getServiceProductPrice( - $servProduct['id_product'], - 0, - 0, - $idProduct, - false, - 1, - $dateFrom, - $dateTo, - $idCart - )/$numDays; - } - } - $objServiceProductCartDetail = new ServiceProductCartDetail(); if ($selectedRoomServiceProduct = $objCartBookingData->getRoomRowByIdProductIdRoomInDateRange( $idCart, @@ -1381,6 +1387,7 @@ class AdminCartsControllerCore extends AdminController $idHotelCartBooking = Tools::getValue('id_hotel_cart_booking'); // valiadate services being added if (Validate::isLoadedObject($objHtlCartBooking = new HotelCartBookingData($idHotelCartBooking))) { + $objCart = new Cart($objHtlCartBooking->id_cart); $name = trim(Tools::getValue('new_service_name')); $price = Tools::getValue('new_service_price'); $priceCalcMethod = Tools::getValue('new_service_price_calc_method'); @@ -1415,6 +1422,15 @@ class AdminCartsControllerCore extends AdminController $response['hasError'] = true; $response['errors'][] = Tools::displayError('Invalid service name'); } + + if (empty($priceCalcMethod)) { + $response['hasError'] = true; + $response['errors'][] = Tools::displayError('Please select at least one price calculation method.'); + } elseif ( + !Validate::isUnsignedInt($priceCalcMethod)) { + $response['hasError'] = true; + $response['errors'][] = Tools::displayError('Invalid price calculation method.'); + } if (!isset($price)) { $response['hasError'] = true; @@ -1427,6 +1443,12 @@ class AdminCartsControllerCore extends AdminController // if no validation errors then add service if (!$response['hasError']) { // ======= START: Create Service product ========= + if ($objCart->id_currency != (int)Configuration::get('PS_CURRENCY_DEFAULT')) { + $currency = Currency::getCurrencyInstance($objCart->id_currency); + $price = Tools::ps_round($price/$currency->conversion_rate, 6); + $this->context->currency = new Currency((int) $objCart->id_currency); + } + $objServiceProduct = new Product(); $objServiceProduct->price_calculation_method = $priceCalcMethod; $objServiceProduct->selling_preference_type = Product::SELLING_PREFERENCE_WITH_ROOM_TYPE; @@ -1466,7 +1488,6 @@ class AdminCartsControllerCore extends AdminController RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE ); // If service product is create successfully the start adding the product in cart and order - $objCart = new Cart($objHtlCartBooking->id_cart); $objServiceProduct = new Product($objServiceProduct->id, false, $objCart->id_lang); $objServiceProductCartDetail = new ServiceProductCartDetail(); @@ -1539,16 +1560,32 @@ class AdminCartsControllerCore extends AdminController $objProduct->getServiceProducts(true, Product::SELLING_PREFERENCE_STANDALONE_AND_WITH_ROOM_TYPE), $objProduct->getServiceProducts(true, Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE) ); + if ($serviceProducts) { + foreach ($serviceProducts as $key => $servProduct) { + $numDays = Product::getPriceCalculationApplicableDays( + $servProduct['price_calculation_method'], + $objCartBookingData->date_from, + $objCartBookingData->date_to + ); + + $serviceProducts[$key]['price_tax_exc'] = Product::getServiceProductPrice( + $servProduct['id_product'], + 0, + 0, + $objCartBookingData->id_product, + false, + 1, + $objCartBookingData->date_from, + $objCartBookingData->date_to, + $objCartBookingData->id_cart + )/$numDays; + } + } } else { $objRoomTypeServiceProduct = new RoomTypeServiceProduct(); $serviceProducts = $objRoomTypeServiceProduct->getServiceProductsData($objCartBookingData->id_product, 1, 0, false, 2, null); } - if ($serviceProducts) { - foreach ($serviceProducts as $key => $servProduct) { - $serviceProducts[$key]['price_tax_exc'] = $servProduct['price']; - } - } $objServiceProductCartDetail = new ServiceProductCartDetail(); if ($selectedRoomServiceProduct = $objCartBookingData->getRoomRowByIdProductIdRoomInDateRange( @@ -1632,6 +1669,39 @@ class AdminCartsControllerCore extends AdminController $response['hasError'] = true; $response['errors'][] = Tools::displayError('Invalid unit price for service').': '.$objProduct->name; } + + if ($selected && $objProduct->allow_multiple_quantity + && isset($serviceQuantities[$idServiceProduct]) + && Validate::isUnsignedInt($serviceQuantities[$idServiceProduct]) + ) { + $cartTotalQty = Cart::getProductQtyInCart($objCart->id, $idServiceProduct); + + $qty = (int)$serviceQuantities[$idServiceProduct]; + $numDays = Product::getPriceCalculationApplicableDays( + $objProduct->price_calculation_method, + $objHotelCartBookingData->date_from, + $objHotelCartBookingData->date_to + ); + + $existingQty = 0; + $objSpCartDetail = new ServiceProductCartDetail(); + if ($idExistingDetail = $objSpCartDetail->alreadyExists( + $objCart->id, + $idServiceProduct, + $idCartBooking + )) { + $existingQty = (int)(new ServiceProductCartDetail($idExistingDetail))->quantity * $numDays; + } + + $finalQty = (int)$cartTotalQty - $existingQty + ($qty * $numDays); + if ($objProduct->max_quantity && $finalQty > $objProduct->max_quantity) { + $response['hasError'] = true; + $response['errors'][] = Tools::displayError(sprintf('Cannot add more than %d quantity.', $objProduct->max_quantity)).': '.$objProduct->name; + } elseif (!Product::isAvailableWhenOutOfStock(StockAvailable::outOfStock((int)$idServiceProduct)) && !$objProduct->checkQty($finalQty)) { + $response['hasError'] = true; + $response['errors'][] = Tools::displayError('There isn\'t enough product in stock.').': '.$objProduct->name; + } + } } else { $response['errors'][] = Tools::displayError('Some services not found. please try after refreshing the page'); } diff --git a/controllers/admin/AdminNormalProductsController.php b/controllers/admin/AdminNormalProductsController.php index ba3dbb220..7bea0215f 100644 --- a/controllers/admin/AdminNormalProductsController.php +++ b/controllers/admin/AdminNormalProductsController.php @@ -227,7 +227,7 @@ class AdminNormalProductsControllerCore extends AdminController LEFT JOIN `'._DB_PREFIX_.'htl_room_type` hrt ON (rsp.`id_element` = hrt.`id_product` AND rsp.`element_type` = '.(int)RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE.') '.HotelBranchInformation::addHotelRestriction(false, 'hrt'); - $this->_select .= ' IF(a.`auto_add_to_cart`, "'.$this->l('Yes').'", "'.$this->l('No').'") as auto_added, IF(a.`auto_add_to_cart`, 1, 0) as badge_success, IF(a.`show_at_front`, "'.$this->l('Yes').'", "'.$this->l('No').'") as show_at_front_txt, CASE a.`price_calculation_method` WHEN '.Product::PRICE_CALCULATION_METHOD_ONLY_CHECKIN_DAY.' THEN "'.$this->l('Only check-in day').'" WHEN '.Product::PRICE_CALCULATION_METHOD_ONLY_CHECKOUT_DAY.' THEN "'.$this->l('Only check-out day').'" WHEN '.Product::PRICE_CALCULATION_METHOD_ONLY_DURINGSTAY_DAY.' THEN "'.$this->l('Only during-stay days').'" WHEN '.Product::PRICE_CALCULATION_METHOD_CHECKIN_DAY_AND_CHECKOUT_DAY.' THEN "'.$this->l('Check-in and check-out days').'" WHEN '.Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_DURINGSTAY.' THEN "'.$this->l('Check-in | during-stay days').'" WHEN '.Product::PRICE_CALCULATION_METHOD_CHECKOUT_AND_DURINGSTAY.' THEN "'.$this->l('Check-out | during-stay days').'" WHEN '.Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURINGSTAY.' THEN "'.$this->l('Check-in | check-out | during-stay days').'" ELSE "'.$this->l('Only check-in day').'" END as price_calculation_method_txt, (SELECT COUNT(hri.`id`) FROM `'._DB_PREFIX_.'htl_room_information` hri WHERE hri.`id_product` = a.`id_product`) as num_rooms, '; + $this->_select .= ' IF(a.`auto_add_to_cart`, "'.$this->l('Yes').'", "'.$this->l('No').'") as auto_added, IF(a.`auto_add_to_cart`, 1, 0) as badge_success, IF(a.`show_at_front`, "'.$this->l('Yes').'", "'.$this->l('No').'") as show_at_front_txt, (SELECT COUNT(hri.`id`) FROM `'._DB_PREFIX_.'htl_room_information` hri WHERE hri.`id_product` = a.`id_product`) as num_rooms, '; $this->_select .= ' COUNT(hrt.`id_product`) as products_associated, '; $this->_select .= 'shop.`name` AS `shopname`, a.`id_shop_default`, '; $this->_select .= $alias_image.'.`id_image` AS `id_image`, cl.`name` AS `name_category`, '.$alias.'.`price`, 0 AS `price_final`, a.`is_virtual`, pd.`nb_downloadable`, sav.`quantity` AS `sav_quantity`, '.$alias.'.`active`, IF(sav.`quantity`<=0, 1, 0) AS `badge_danger`'; @@ -302,13 +302,14 @@ class AdminNormalProductsControllerCore extends AdminController 'callback' => 'getPriceDisplayPreference', 'list' => $priceAdditionType, ); - $this->fields_list['price_calculation_method_txt'] = array( + $this->fields_list['price_calculation_method'] = array( 'title' => $this->l('Price calculation method'), 'filter_key' => 'a!price_calculation_method', 'type' => 'select', 'list' => $priceCalculationMethod, 'visible_default' => true, 'optional' => true, + 'callback' => 'getPriceCalculationMethod', ); $this->servicesCategory = array(); $idServiceCategory = Configuration::get('PS_SERVICE_CATEGORY'); @@ -432,23 +433,29 @@ class AdminNormalProductsControllerCore extends AdminController public function getBuyingOption($selling_preference_type, $row) { - if ($selling_preference_type == Product::SELLING_PREFERENCE_WITH_ROOM_TYPE) { - return $this->l('With room type'); - } else if ($selling_preference_type == Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE) { - return $this->l('With hotel|room type'); - } else if ($selling_preference_type == Product::SELLING_PREFERENCE_STANDALONE) { - return $this->l('Standalone'); - } else if ($selling_preference_type == Product::SELLING_PREFERENCE_HOTEL_STANDALONE) { - return $this->l('With hotel'); - } else if ($selling_preference_type == Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_STANDALONE) { - return $this->l('With hotel|standalone'); - } else if ($selling_preference_type == Product::SELLING_PREFERENCE_STANDALONE_AND_WITH_ROOM_TYPE) { - return $this->l('With room type|standalone'); - } else if ($selling_preference_type == Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE) { - return $this->l('With hotel|room type|standalone'); + $list = $this->fields_list['selling_preference_type']['list']; + + if (!isset($list[$selling_preference_type])) { + return '--'; } - return '--'; + $this->context->smarty->assign('selected_options', array_map('trim', explode('|', $list[$selling_preference_type]))); + + return $this->context->smarty->fetch('controllers/normal_products/selected_option.tpl'); + } + + public function getPriceCalculationMethod($txt, $row) + { + $list = $this->fields_list['price_calculation_method']['list']; + $method = (int)$row['price_calculation_method']; + + if (!isset($list[$method])) { + return '--'; + } + + $this->context->smarty->assign('selected_options', array_map('trim', explode('|', $list[$method]))); + + return $this->context->smarty->fetch('controllers/normal_products/selected_option.tpl'); } public function getHotelName($hotelName, $row) @@ -480,7 +487,7 @@ class AdminNormalProductsControllerCore extends AdminController .'template')) { $bo_theme = 'default'; } - + $this->addJqueryUI('ui.tooltip', 'base', true); $this->addJs(__PS_BASE_URI__.$this->admin_webpath.'/themes/'.$bo_theme.'/js/jquery.iframe-transport.js'); $this->addJs(__PS_BASE_URI__.$this->admin_webpath.'/themes/'.$bo_theme.'/js/jquery.fileupload.js'); $this->addJs(__PS_BASE_URI__.$this->admin_webpath.'/themes/'.$bo_theme.'/js/jquery.fileupload-process.js'); @@ -2360,6 +2367,14 @@ class AdminNormalProductsControllerCore extends AdminController $this->errors[] = $this->l('This product must be in the default category.'); } + if (!Tools::getValue('selling_preference_type')) { + $this->errors[] = $this->l('Please select at least one buying option.'); + } + + if (!Tools::getValue('price_calculation_method')) { + $this->errors[] = $this->l('Please select at least one price calculation method.'); + } + // Tags foreach ($languages as $language) { if ($value = Tools::getValue('tags_'.$language['id_lang'])) { diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 4739ab5d1..05c7a4f3c 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -996,25 +996,56 @@ class AdminOrdersControllerCore extends AdminController $objProduct->getServiceProducts(true, Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE), $objProduct->getServiceProducts(true, Product::SELLING_PREFERENCE_STANDALONE_AND_WITH_ROOM_TYPE), $objProduct->getServiceProducts(true, Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE) - ); - } else { - $objRoomTypeServiceProduct = new RoomTypeServiceProduct(); - $serviceProducts = $objRoomTypeServiceProduct->getServiceProductsData($idProduct, 1, 0, false, 2, null); - } + ); + + if($serviceProducts) { + foreach ($serviceProducts as $key => $servProduct) { + if (!Product::isAvailableWhenOutOfStock(StockAvailable::outOfStock((int)$servProduct['id_product'])) + && Product::getQuantity((int)$servProduct['id_product']) <= 0 + ) { + unset($serviceProducts[$key]); + continue; + } + if (!empty($additionalServices[$productLineData['id']]) + && in_array($servProduct['id_product'], array_column($additionalServices[$productLineData['id']]['additional_services'], 'id_product')) + ) { + unset($serviceProducts[$key]); + } else { - if ($serviceProducts) { - foreach ($serviceProducts as $key => $servProduct) { - $serviceProducts[$key]['price_tax_exc'] = $servProduct['price']; - if (isset($additionalServices[$productLineData['id']]) - && in_array($servProduct['id_product'], array_column($additionalServices[$productLineData['id']]['additional_services'], 'id_product')) - ) { - unset($serviceProducts[$key]); + $numDays = Product::getPriceCalculationApplicableDays( + $servProduct['price_calculation_method'], + $dateFrom, + $dateTo + ); + $serviceProducts[$key]['price_tax_exc'] = Product::getServiceProductPrice( + $servProduct['id_product'], + 0, + 0, + $idProduct, + false, + 1, + $dateFrom, + $dateTo + ) / max($numDays, 1); + } } } + } else { + $objRoomTypeServiceProduct = new RoomTypeServiceProduct(); + if ($serviceProducts = $objRoomTypeServiceProduct->getServiceProductsData($idProduct, 1, 0, false, 2, null)) { + foreach ($serviceProducts as $key => $servProduct) { + if (isset($additionalServices[$productLineData['id']]) + && in_array($servProduct['id_product'], array_column($additionalServices[$productLineData['id']]['additional_services'], 'id_product')) + ) { + unset($serviceProducts[$key]); + } + } - $smartyVars['serviceProducts'] = $serviceProducts; + } } + + $smartyVars['serviceProducts'] = $serviceProducts; $objOrderReturn = new OrderReturn(); $refundReqBookings = $objOrderReturn->getOrderRefundRequestedBookings($objOrder->id, 0, 1); $smartyVars['refundReqBookings'] = $refundReqBookings; @@ -5469,7 +5500,7 @@ class AdminOrdersControllerCore extends AdminController 1, $objBookingDetail->date_from, $objBookingDetail->date_to - ) / $numDays; + ) / max($numDays, 1); $unitPriceTaxExcl = Product::getServiceProductPrice( (int) $service['id_product'], 0, @@ -5479,7 +5510,7 @@ class AdminOrdersControllerCore extends AdminController 1, $objBookingDetail->date_from, $objBookingDetail->date_to - ) / $numDays; + ) / max($numDays, 1); $objServiceProductOrderDetail = new ServiceProductOrderDetail(); $objServiceProductOrderDetail->id_product = $service['id_product']; @@ -6235,61 +6266,67 @@ class AdminOrdersControllerCore extends AdminController && count($orderServiceProduct['additional_services']) ) { foreach ($orderServiceProduct['additional_services'] as $serviceProduct) { - if ($serviceProduct['price_calculation_method'] == Product::PRICE_CALCULATION_METHOD_PER_DAY) { - $newNumDays = HotelHelper::getNumberOfDays($new_date_from, $new_date_to); - $objServiceProductOrderDetail = new ServiceProductOrderDetail((int) $serviceProduct['id_service_product_order_detail']); - $unitPriceTaxExcl = $objServiceProductOrderDetail->unit_price_tax_excl; - $unitPriceTaxIncl = $objServiceProductOrderDetail->unit_price_tax_incl; + $newNumDays = Product::getPriceCalculationApplicableDays( + $serviceProduct['price_calculation_method'], + $new_date_from, + $new_date_to + ); + $oldNumDays = Product::getPriceCalculationApplicableDays( + $serviceProduct['price_calculation_method'], + $old_date_from, + $old_date_to + ); + $objServiceProductOrderDetail = new ServiceProductOrderDetail((int) $serviceProduct['id_service_product_order_detail']); + $unitPriceTaxExcl = $objServiceProductOrderDetail->unit_price_tax_excl; + $unitPriceTaxIncl = $objServiceProductOrderDetail->unit_price_tax_incl; - $newTotalPriceTaxExcl = Tools::processPriceRounding( - ($newNumDays * $unitPriceTaxExcl), - $objServiceProductOrderDetail->quantity, - $order->round_type, - $order->round_mode - ); - $newTotalPriceTaxIncl = Tools::processPriceRounding( - ($newNumDays * $unitPriceTaxIncl), - $objServiceProductOrderDetail->quantity, - $order->round_type, - $order->round_mode - ); + $newTotalPriceTaxExcl = Tools::processPriceRounding( + ($newNumDays * $unitPriceTaxExcl), + $objServiceProductOrderDetail->quantity, + $order->round_type, + $order->round_mode + ); + $newTotalPriceTaxIncl = Tools::processPriceRounding( + ($newNumDays * $unitPriceTaxIncl), + $objServiceProductOrderDetail->quantity, + $order->round_type, + $order->round_mode + ); - $order->total_products -= $objServiceProductOrderDetail->total_price_tax_excl; - $order->total_products_wt -= $objServiceProductOrderDetail->total_price_tax_incl; + $order->total_products -= $objServiceProductOrderDetail->total_price_tax_excl; + $order->total_products_wt -= $objServiceProductOrderDetail->total_price_tax_incl; - // change order total - $order->total_products += $newTotalPriceTaxExcl; - $order->total_products_wt += $newTotalPriceTaxIncl; + // change order total + $order->total_products += $newTotalPriceTaxExcl; + $order->total_products_wt += $newTotalPriceTaxIncl; - $objOrderDetail = new OrderDetail((int) $serviceProduct['id_order_detail']); - $objOrderDetail->total_price_tax_excl -= $objServiceProductOrderDetail->total_price_tax_excl; - $objOrderDetail->total_price_tax_incl -= $objServiceProductOrderDetail->total_price_tax_incl; + $objOrderDetail = new OrderDetail((int) $serviceProduct['id_order_detail']); + $objOrderDetail->total_price_tax_excl -= $objServiceProductOrderDetail->total_price_tax_excl; + $objOrderDetail->total_price_tax_incl -= $objServiceProductOrderDetail->total_price_tax_incl; - $objOrderDetail->total_price_tax_excl += $newTotalPriceTaxExcl; - $objOrderDetail->total_price_tax_incl += $newTotalPriceTaxIncl; + $objOrderDetail->total_price_tax_excl += $newTotalPriceTaxExcl; + $objOrderDetail->total_price_tax_incl += $newTotalPriceTaxIncl; - $oldNumDays = HotelHelper::getNumberOfDays($old_date_from, $old_date_to); - $oldProductQuantity = $objServiceProductOrderDetail->quantity * $oldNumDays; - $newProductQuantity = $objServiceProductOrderDetail->quantity * $newNumDays; - $objOrderDetail->product_quantity += ($newProductQuantity - $oldProductQuantity); + $oldProductQuantity = $objServiceProductOrderDetail->quantity * $oldNumDays; + $newProductQuantity = $objServiceProductOrderDetail->quantity * $newNumDays; + $objOrderDetail->product_quantity += ($newProductQuantity - $oldProductQuantity); - $objOrderDetail->save(); - $this->context->cart = new Cart($objServiceProductOrderDetail->id_cart); - $objOrderDetail->updateTaxAmount($order); + $objOrderDetail->save(); + $this->context->cart = new Cart($objServiceProductOrderDetail->id_cart); + $objOrderDetail->updateTaxAmount($order); - if (isset($order_invoice)) { - $order_invoice->total_paid_tax_excl -= $objServiceProductOrderDetail->total_price_tax_excl; - $order_invoice->total_paid_tax_incl -= $objServiceProductOrderDetail->total_price_tax_incl; + if (isset($order_invoice)) { + $order_invoice->total_paid_tax_excl -= $objServiceProductOrderDetail->total_price_tax_excl; + $order_invoice->total_paid_tax_incl -= $objServiceProductOrderDetail->total_price_tax_incl; - $order_invoice->total_paid_tax_excl += (float)$newTotalPriceTaxExcl; - $order_invoice->total_paid_tax_incl += (float)$newTotalPriceTaxIncl; - } - $objServiceProductOrderDetail->unit_price_tax_excl = $unitPriceTaxExcl; - $objServiceProductOrderDetail->unit_price_tax_incl = $unitPriceTaxIncl; - $objServiceProductOrderDetail->total_price_tax_excl = $newTotalPriceTaxExcl; - $objServiceProductOrderDetail->total_price_tax_incl = $newTotalPriceTaxIncl; - $objServiceProductOrderDetail->save(); + $order_invoice->total_paid_tax_excl += (float)$newTotalPriceTaxExcl; + $order_invoice->total_paid_tax_incl += (float)$newTotalPriceTaxIncl; } + $objServiceProductOrderDetail->unit_price_tax_excl = $unitPriceTaxExcl; + $objServiceProductOrderDetail->unit_price_tax_incl = $unitPriceTaxIncl; + $objServiceProductOrderDetail->total_price_tax_excl = $newTotalPriceTaxExcl; + $objServiceProductOrderDetail->total_price_tax_incl = $newTotalPriceTaxIncl; + $objServiceProductOrderDetail->save(); } } } @@ -6766,15 +6803,6 @@ class AdminOrdersControllerCore extends AdminController $order_invoice->total_discount_tax_excl = 0; $res &= $order_invoice->update(); } - - // If no rooms left in the order, Update Order total and discounts to 0 - $order->total_discounts = 0; - $order->total_discounts_tax_incl = 0; - $order->total_discounts_tax_excl = 0; - $order->total_paid = 0; - $order->total_paid_tax_incl = 0; - $order->total_paid_tax_excl = 0; - $order->update(); } // Assign to smarty informations in order to show the new product line @@ -7479,17 +7507,48 @@ class AdminOrdersControllerCore extends AdminController $objProduct->getServiceProducts(true, Product::SELLING_PREFERENCE_STANDALONE_AND_WITH_ROOM_TYPE), $objProduct->getServiceProducts(true, Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE) ); + if ($serviceProducts) { + foreach ($serviceProducts as $key => $servProduct) { + if (!Product::isAvailableWhenOutOfStock(StockAvailable::outOfStock((int)$servProduct['id_product'])) + && Product::getQuantity((int)$servProduct['id_product']) <= 0 + ) { + unset($serviceProducts[$key]); + continue; + } + if (!empty($additionalServices[$idHtlBookingDetail]) + && in_array($servProduct['id_product'], array_column($additionalServices[$idHtlBookingDetail]['additional_services'], 'id_product')) + ) { + unset($serviceProducts[$key]); + } else { + + $numDays = Product::getPriceCalculationApplicableDays( + $servProduct['price_calculation_method'], + $dateFrom, + $dateTo + ); + + $serviceProducts[$key]['price_tax_exc'] = Product::getServiceProductPrice( + $servProduct['id_product'], + 0, + 0, + $idProduct, + false, + 1, + $dateFrom, + $dateTo + ) / max($numDays, 1); + } + } + } + } else { $objRoomTypeServiceProduct = new RoomTypeServiceProduct(); - $serviceProducts = $objRoomTypeServiceProduct->getServiceProductsData($idProduct, 1, 0, false, 2, null); - } - - if ($serviceProducts) { - foreach ($serviceProducts as $key => $servProduct) { - $serviceProducts[$key]['price_tax_exc'] = $servProduct['price']; - if (isset($additionalServices[$idHtlBookingDetail]) && $additionalServices[$idHtlBookingDetail]) { - if (in_array($servProduct['id_product'], array_column($additionalServices[$idHtlBookingDetail]['additional_services'], 'id_product'))) { - unset($serviceProducts[$key]); + if ($serviceProducts = $objRoomTypeServiceProduct->getServiceProductsData($idProduct, 1, 0, false, 2, null)) { + foreach ($serviceProducts as $key => $servProduct) { + if (!empty($additionalServices[$idHtlBookingDetail])) { + if (in_array($servProduct['id_product'], array_column($additionalServices[$idHtlBookingDetail]['additional_services'], 'id_product'))) { + unset($serviceProducts[$key]); + } } } } @@ -7643,13 +7702,11 @@ class AdminOrdersControllerCore extends AdminController $objServiceProductOrderDetail->quantity = $quantity; $objServiceProductOrderDetail->unit_price_tax_excl = $unitPrice; $objServiceProductOrderDetail->unit_price_tax_incl = $unitPrice * $oldTaxMultiplier; - $numDays = 1; - if ($objOrderDetail->product_price_calculation_method == Product::PRICE_CALCULATION_METHOD_PER_DAY) { - $numDays = HotelHelper::getNumberOfDays( - $objHotelBookingDetail->date_from, - $objHotelBookingDetail->date_to - ); - } + $numDays = Product::getPriceCalculationApplicableDays( + $objOrderDetail->product_price_calculation_method, + $objHotelBookingDetail->date_from, + $objHotelBookingDetail->date_to + ); $objServiceProductOrderDetail->total_price_tax_excl = Tools::processPriceRounding( ($objServiceProductOrderDetail->unit_price_tax_excl * $numDays), $quantity, @@ -7667,22 +7724,14 @@ class AdminOrdersControllerCore extends AdminController $priceDiffTaxExcl = $objServiceProductOrderDetail->total_price_tax_excl - $oldTotalPriceTaxExcl; $priceDiffTaxIncl = $objServiceProductOrderDetail->total_price_tax_incl - $oldTotalPriceTaxIncl; - if ($objOrderDetail->product_price_calculation_method == Product::PRICE_CALCULATION_METHOD_PER_DAY) { - $numDays = HotelHelper::getNumberOfDays( - $objHotelBookingDetail->date_from, - $objHotelBookingDetail->date_to - ); - $quantityDiff = ($objServiceProductOrderDetail->quantity - $oldQuantity)*$numDays; - } else { - $quantityDiff = $objServiceProductOrderDetail->quantity - $oldQuantity; - } + $quantityDiff = ($objServiceProductOrderDetail->quantity - $oldQuantity) * $numDays; $objOrderDetail->product_quantity += $quantityDiff; $objOrderDetail->total_price_tax_excl += $priceDiffTaxExcl; $objOrderDetail->total_price_tax_incl += $priceDiffTaxIncl; - $objOrderDetail->unit_price_tax_excl = ($objOrderDetail->total_price_tax_excl / $objOrderDetail->product_quantity); - $objOrderDetail->unit_price_tax_incl = ($objOrderDetail->total_price_tax_incl / $objOrderDetail->product_quantity); + $objOrderDetail->unit_price_tax_excl = ($objOrderDetail->total_price_tax_excl / max($objOrderDetail->product_quantity, 1)); + $objOrderDetail->unit_price_tax_incl = ($objOrderDetail->total_price_tax_incl / max($objOrderDetail->product_quantity, 1)); $result &= $objOrderDetail->updateTaxAmount($objOrder); @@ -7770,6 +7819,25 @@ class AdminOrdersControllerCore extends AdminController $response['hasError'] = true; $response['errors'][] = sprintf($this->l('Invalid unit price for %s.'), $objProduct->name); } + + if ($objProduct->allow_multiple_quantity && Validate::isUnsignedInt($qty[$service])) { + $finalQty = (int)$qty[$service]; + $numDays = Product::getPriceCalculationApplicableDays( + Product::getProductPriceCalculation($service), + $objHotelBookingDetail->date_from, + $objHotelBookingDetail->date_to + ); + $stockQty = $finalQty * $numDays; + + if ($objProduct->max_quantity && $finalQty > $objProduct->max_quantity) { + $response['hasError'] = true; + $response['errors'][] = sprintf($this->l('Cannot add more than %d quantity.'), $objProduct->max_quantity).': '.$objProduct->name; + } elseif (!Product::isAvailableWhenOutOfStock(StockAvailable::outOfStock((int)$service)) && !$objProduct->checkQty($stockQty)) { + $response['hasError'] = true; + $response['errors'][] = $this->l('There isn\'t enough product in stock.').': '.$objProduct->name; + } + } + $selectedServices[$key] = array( 'id' => $service, 'qty' => $qty[$service], @@ -7826,7 +7894,7 @@ class AdminOrdersControllerCore extends AdminController 1, $objHotelBookingDetail->date_from, $objHotelBookingDetail->date_to - ) / $numDays; + ) / max($numDays, 1); if ($initialServicePrice != $service['price']) { $specific_price = new SpecificPrice(); @@ -7887,7 +7955,7 @@ class AdminOrdersControllerCore extends AdminController 1, null, $roomHtlCartInfo['id'] - ) / $numDays; + ) / max($numDays, 1); $unitPriceTaxIncl = Product::getServiceProductPrice( (int) $product['id_product'], 0, @@ -7902,7 +7970,7 @@ class AdminOrdersControllerCore extends AdminController 1, null, $roomHtlCartInfo['id'] - ) / $numDays; + ) / max($numDays, 1); $totalPriceChangeTaxExcl += $totalPriceTaxExcl = Tools::processPriceRounding( ($unitPriceTaxExcl * $numDays), @@ -8047,6 +8115,15 @@ class AdminOrdersControllerCore extends AdminController $response['errors'][] = Tools::displayError('Invalid service name'); } + if (empty($priceCalcMethod)) { + $response['hasError'] = true; + $response['errors'][] = Tools::displayError('Please select at least one price calculation method.'); + } elseif ( + !Validate::isUnsignedInt($priceCalcMethod)) { + $response['hasError'] = true; + $response['errors'][] = Tools::displayError('Invalid price calculation method.'); + } + if (!isset($price)) { $response['hasError'] = true; $response['errors'][] = Tools::displayError('Service price is required'); @@ -8054,7 +8131,6 @@ class AdminOrdersControllerCore extends AdminController $response['hasError'] = true; $response['errors'][] = Tools::displayError('Invalid service price'); } - // if no validation errors then add service if (!$response['hasError']) { // ======= START: Create Service product ========= @@ -8164,7 +8240,7 @@ class AdminOrdersControllerCore extends AdminController $objHotelBookingDetail->date_from, $objHotelBookingDetail->date_to, $objCart->id - ) / $numDays; + ) / max($numDays, 1); $unitPriceTaxIncl = Product::getServiceProductPrice( (int)$product['id_product'], 0, @@ -8175,7 +8251,7 @@ class AdminOrdersControllerCore extends AdminController $objHotelBookingDetail->date_from, $objHotelBookingDetail->date_to, $objCart->id - ) / $numDays; + ) / max($numDays, 1); $totalPriceChangeTaxExcl += $totalPriceTaxExcl = Tools::processPriceRounding( ($unitPriceTaxExcl * $numDays), @@ -8358,13 +8434,12 @@ class AdminOrdersControllerCore extends AdminController if ($res &= $objServiceProductOrderDetail->delete()) { $order = new Order($objServiceProductOrderDetail->id_order); - if ($objOrderDetail->product_price_calculation_method == Product::PRICE_CALCULATION_METHOD_PER_DAY) { - $numDays = HotelHelper::getNumberOfDays( - $objHotelBookingDetail->date_from, - $objHotelBookingDetail->date_to - ); - $quantity = $quantity * $numDays; - } + $numDays = Product::getPriceCalculationApplicableDays( + $objOrderDetail->product_price_calculation_method, + $objHotelBookingDetail->date_from, + $objHotelBookingDetail->date_to + ); + $quantity = $quantity * $numDays; if ($quantity >= $objOrderDetail->product_quantity) { $objOrderDetail->delete(); } else { diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 0a7acb76f..7c8c20efc 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -415,9 +415,12 @@ class AdminProductsControllerCore extends AdminController ); $objProduct = new Product(); - $hotelServiceProducts = $objProduct->getServiceProducts(null, Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE); - $roomTypeServiceProducts = $objProduct->getServiceProducts(null, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE); - $allServiceProducts = array_merge($roomTypeServiceProducts, $hotelServiceProducts); + $allServiceProducts = array_values(array_filter( + $objProduct->getServiceProducts(null), + function ($serviceProduct) { + return Product::isSellableWithRoomType($serviceProduct['selling_preference_type']); + } + )); $serviceProducts = array(); foreach ($allServiceProducts as $serviceProduct) { $serviceProducts[$serviceProduct['id_product']] = $serviceProduct['name']; @@ -3152,9 +3155,12 @@ class AdminProductsControllerCore extends AdminController $objRoomType = new HotelRoomType(); if ($hotelRoomType = $objRoomType->getRoomTypeInfoByIdProduct($obj->id)) { - $hotelServiceProducts = $obj->getServiceProducts(null, Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE); - $roomTypeServiceProducts = $obj->getServiceProducts(null, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE); - $allServiceProducts = array_merge($roomTypeServiceProducts, $hotelServiceProducts); + $allServiceProducts = array_values(array_filter( + $obj->getServiceProducts(null), + function ($serviceProduct) { + return Product::isSellableWithRoomType($serviceProduct['selling_preference_type']); + } + )); $objRoomTypeServiceProduct = new RoomTypeServiceProduct(); $objRoomTypeServiceProductPrice = new RoomTypeServiceProductPrice(); diff --git a/controllers/admin/AdminStatsController.php b/controllers/admin/AdminStatsController.php index ba6b3b371..95ee79919 100644 --- a/controllers/admin/AdminStatsController.php +++ b/controllers/admin/AdminStatsController.php @@ -2304,9 +2304,9 @@ class AdminStatsControllerCore extends AdminStatsTabController IFNULL(SUM( CASE WHEN od.`purchase_supplier_price` <> "0.000000" - THEN (od.`purchase_supplier_price` / (IF (od.`product_price_calculation_method` = '.Product::PRICE_CALCULATION_METHOD_PER_BOOKING.', DATEDIFF(hbd.`date_to`, hbd.`date_from`), 1))) + THEN (od.`purchase_supplier_price` / (IF (od.`product_price_calculation_method` = '.Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURINGSTAY.', DATEDIFF(hbd.`date_to`, hbd.`date_from`), 1))) WHEN od.`purchase_supplier_price` = "0.000000" - THEN ((od.`original_product_price` / o.`conversion_rate`) * '.(int)Configuration::get('CONF_AVERAGE_PRODUCT_MARGIN').' / 100) / (IF (od.`product_price_calculation_method` = '.Product::PRICE_CALCULATION_METHOD_PER_BOOKING.', DATEDIFF(hbd.`date_to`, hbd.`date_from`), 1)) + THEN ((od.`original_product_price` / o.`conversion_rate`) * '.(int)Configuration::get('CONF_AVERAGE_PRODUCT_MARGIN').' / 100) / (IF (od.`product_price_calculation_method` = '.Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURINGSTAY.', DATEDIFF(hbd.`date_to`, hbd.`date_from`), 1)) END ), 0) FROM `'._DB_PREFIX_.'service_product_order_detail` rtspod diff --git a/controllers/front/CartController.php b/controllers/front/CartController.php index 98fb6eaac..67ee06439 100644 --- a/controllers/front/CartController.php +++ b/controllers/front/CartController.php @@ -482,7 +482,11 @@ class CartControllerCore extends FrontController if ($product->allow_multiple_quantity) { $finalQuantity = $this->qty; if (isset($productCartDetail) && $productCartDetail) { - $finalQuantity += $productCartDetail['quantity']; + $quantityInCart = Cart::getProductQtyInCart( + $id_cart, + $this->id_product + ); + $finalQuantity += $quantityInCart; } if ($product->max_quantity && $finalQuantity > $product->max_quantity) { $this->errors[] = Tools::displayError(sprintf('You cannot add more than %d quantity for this product in the cart.', $product->max_quantity)); @@ -560,22 +564,24 @@ class CartControllerCore extends FrontController } } - // Check product quantity availability - if ($this->id_product_attribute) { - if (!Product::isAvailableWhenOutOfStock($product->out_of_stock) && !ProductAttribute::checkAttributeQty($this->id_product_attribute, $qty_to_check)) { + // Check product quantity availability only when no earlier validation error exists + if (!$this->errors) { + if ($this->id_product_attribute) { + if (!Product::isAvailableWhenOutOfStock($product->out_of_stock) && !ProductAttribute::checkAttributeQty($this->id_product_attribute, $qty_to_check)) { + $this->errors[] = Tools::displayError('There isn\'t enough product in stock.', !Tools::getValue('ajax')); + } + } elseif ($product->hasAttributes()) { + $minimumQuantity = ($product->out_of_stock == 2) ? !Configuration::get('PS_ORDER_OUT_OF_STOCK') : !$product->out_of_stock; + $this->id_product_attribute = Product::getDefaultAttribute($product->id, $minimumQuantity); + // @todo do something better than a redirect admin !! + if (!$this->id_product_attribute) { + Tools::redirectAdmin($this->context->link->getProductLink($product)); + } elseif (!Product::isAvailableWhenOutOfStock($product->out_of_stock) && !ProductAttribute::checkAttributeQty($this->id_product_attribute, $qty_to_check)) { + $this->errors[] = Tools::displayError('There isn\'t enough product in stock.', !Tools::getValue('ajax')); + } + } elseif (!$product->checkQty($qty_to_check)) { $this->errors[] = Tools::displayError('There isn\'t enough product in stock.', !Tools::getValue('ajax')); } - } elseif ($product->hasAttributes()) { - $minimumQuantity = ($product->out_of_stock == 2) ? !Configuration::get('PS_ORDER_OUT_OF_STOCK') : !$product->out_of_stock; - $this->id_product_attribute = Product::getDefaultAttribute($product->id, $minimumQuantity); - // @todo do something better than a redirect admin !! - if (!$this->id_product_attribute) { - Tools::redirectAdmin($this->context->link->getProductLink($product)); - } elseif (!Product::isAvailableWhenOutOfStock($product->out_of_stock) && !ProductAttribute::checkAttributeQty($this->id_product_attribute, $qty_to_check)) { - $this->errors[] = Tools::displayError('There isn\'t enough product in stock.', !Tools::getValue('ajax')); - } - } elseif (!$product->checkQty($qty_to_check)) { - $this->errors[] = Tools::displayError('There isn\'t enough product in stock.', !Tools::getValue('ajax')); } // If no errors, process product addition @@ -748,8 +754,20 @@ class CartControllerCore extends FrontController if ($objProduct->allow_multiple_quantity) { if (!Validate::isUnsignedInt($qty)) { $this->errors[] = Tools::displayError('The quantity you\'ve entered is invalid.'); - } elseif ($objProduct->max_quantity && $qty > $objProduct->max_quantity) { - $this->errors[] = Tools::displayError(sprintf('cannot add more than %d quantity.', $objProduct->max_quantity)); + } else { + $cartTotalQty = Cart::getProductQtyInCart((int)$this->context->cart->id,(int)$idServiceProduct); + $numDays = Product::getPriceCalculationApplicableDays( + $objProduct->price_calculation_method, + $objHotelCartBookingData->date_from, + $objHotelCartBookingData->date_to + ); + $currentQty = $qty * $numDays; + $finalQty = (int)$cartTotalQty + $currentQty; + if ($objProduct->max_quantity && $finalQty > $objProduct->max_quantity) { + $this->errors[] = Tools::displayError(sprintf('cannot add more than %d quantity.', $objProduct->max_quantity)); + } else if (!Product::isAvailableWhenOutOfStock($objProduct->out_of_stock) && !$objProduct->checkQty($finalQty)) { + $this->errors[] = Tools::displayError('There isn\'t enough product in stock.'); + } } } else { $qty = 1; diff --git a/controllers/front/GuestTrackingController.php b/controllers/front/GuestTrackingController.php index fd684953b..3b6fd2b2b 100644 --- a/controllers/front/GuestTrackingController.php +++ b/controllers/front/GuestTrackingController.php @@ -524,10 +524,7 @@ class GuestTrackingControllerCore extends FrontController 1 ); } - } else if ( - Product::isSellableWithHotel($type_value['selling_preference_type']) - || Product::isSellableAsStandalone($type_value['selling_preference_type']) - ) { + } else if (Product::isSellableWithHotel($type_value['selling_preference_type'])) { $cover_image_arr = $product->getCover($type_value['product_id']); if (!empty($cover_image_arr)) { @@ -535,21 +532,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 (Product::isSellableAsStandalone($type_value['selling_preference_type'])) { + $cover_image_arr = $product->getCover($type_value['product_id']); - $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); - } + 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); } } } diff --git a/controllers/front/OrderConfirmationController.php b/controllers/front/OrderConfirmationController.php index 44940f97d..e40a7bec0 100644 --- a/controllers/front/OrderConfirmationController.php +++ b/controllers/front/OrderConfirmationController.php @@ -149,6 +149,7 @@ class OrderConfirmationControllerCore extends FrontController $cart_standalone_service_products = array(); $cart_hotel_service_products = array(); $cart_htl_data = array(); + foreach ($cartOrders as $cartOrder) { $idOrder = $cartOrder['id_order']; $objCartOrder = new Order($idOrder); @@ -298,7 +299,7 @@ class OrderConfirmationControllerCore extends FrontController if (empty($cart_htl_data[$type_key]['date_diff'][$date_join]['additional_services_price_ti'])) { $cart_htl_data[$type_key]['date_diff'][$date_join]['additional_services_price_ti'] = 0; } - $additionalServicesPriceTI = $objServiceProductOrderDetail->getRoomTypeServiceProducts( + $cart_htl_data[$type_key]['date_diff'][$date_join]['additional_services_price_ti'] += $extraDemandPriceTI = $objServiceProductOrderDetail->getRoomTypeServiceProducts( $idOrder, 0, 0, @@ -310,12 +311,10 @@ class OrderConfirmationControllerCore extends FrontController 1, 0 ); - $cart_htl_data[$type_key]['date_diff'][$date_join]['additional_services_price_ti'] += $additionalServicesPriceTI; - $orderTotalInfo['total_services_ti'] += $additionalServicesPriceTI; if (empty($cart_htl_data[$type_key]['date_diff'][$date_join]['additional_services_price_te'])) { $cart_htl_data[$type_key]['date_diff'][$date_join]['additional_services_price_te'] = 0; } - $additionalServicesPriceTE = $objServiceProductOrderDetail->getRoomTypeServiceProducts( + $cart_htl_data[$type_key]['date_diff'][$date_join]['additional_services_price_te'] += $extraDemandPriceTE = $objServiceProductOrderDetail->getRoomTypeServiceProducts( $idOrder, 0, 0, @@ -327,13 +326,11 @@ class OrderConfirmationControllerCore extends FrontController 0, 0 ); - $cart_htl_data[$type_key]['date_diff'][$date_join]['additional_services_price_te'] += $additionalServicesPriceTE; - $orderTotalInfo['total_services_te'] += $additionalServicesPriceTE; // get auto added price to be displayed with room price if (empty($cart_htl_data[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_ti'])) { $cart_htl_data[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_ti'] = 0; } - $autoAddedServicesPriceTI = $objServiceProductOrderDetail->getRoomTypeServiceProducts( + $cart_htl_data[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_ti'] += $objServiceProductOrderDetail->getRoomTypeServiceProducts( $idOrder, 0, 0, @@ -346,12 +343,10 @@ class OrderConfirmationControllerCore extends FrontController 1, Product::PRICE_ADDITION_TYPE_WITH_ROOM ); - $cart_htl_data[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_ti'] += $autoAddedServicesPriceTI; - $orderTotalInfo['total_auto_add_services_ti'] += $autoAddedServicesPriceTI; if (empty($cart_htl_data[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_te'])) { $cart_htl_data[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_te'] = 0; } - $autoAddedServicesPriceTE = $objServiceProductOrderDetail->getRoomTypeServiceProducts( + $cart_htl_data[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_te'] += $objServiceProductOrderDetail->getRoomTypeServiceProducts( $idOrder, 0, 0, @@ -364,16 +359,10 @@ class OrderConfirmationControllerCore extends FrontController 1, Product::PRICE_ADDITION_TYPE_WITH_ROOM ); - $cart_htl_data[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_te'] += $autoAddedServicesPriceTE; - $orderTotalInfo['total_auto_add_services_te'] += $autoAddedServicesPriceTE; $totalRoomsBooked += 1; } - } else { - $canSellWithRoomType = Product::isSellableWithRoomType($type_value['selling_preference_type']); - $canSellWithHotel = Product::isSellableWithHotel($type_value['selling_preference_type']); - $canSellAsStandalone = Product::isSellableAsStandalone($type_value['selling_preference_type']); - + } else if (Product::isSellableWithHotel($type_value['selling_preference_type'])) { $cover_image_arr = $product->getCover($type_value['product_id']); if (!empty($cover_image_arr)) { @@ -383,43 +372,36 @@ class OrderConfirmationControllerCore extends FrontController } $serviceProducts = $objServiceProductOrderDetail->getServiceProductsInOrder($idOrder, $type_value['id_order_detail'], $type_value['product_id']); foreach ($serviceProducts as $serviceProduct) { - $idHotel = (int)$serviceProduct['id_hotel']; - $isRoomLinked = !empty($serviceProduct['id_htl_booking_detail']); + $type_value['total_price_tax_excl'] = $serviceProduct['total_price_tax_excl']; + $type_value['total_price_tax_incl'] = $serviceProduct['total_price_tax_incl']; + $type_value['product_quantity'] = $serviceProduct['quantity']; + $type_value['option_name'] = $serviceProduct['option_name']; + $type_value['location'] = $serviceProduct['option_name']; - $serviceLine = $type_value; - $serviceLine['unit_price_tax_excl'] = $serviceProduct['unit_price_tax_excl']; - $serviceLine['unit_price_tax_incl'] = $serviceProduct['unit_price_tax_incl']; - $serviceLine['total_price_tax_excl'] = $serviceProduct['total_price_tax_excl']; - $serviceLine['total_price_tax_incl'] = $serviceProduct['total_price_tax_incl']; - $serviceLine['product_quantity'] = $serviceProduct['quantity']; - $serviceLine['option_name'] = $serviceProduct['option_name']; - - if ( - $canSellWithRoomType - && (int)$type_value['product_auto_add'] == 1 - && (int)$type_value['product_price_addition_type'] == Product::PRICE_ADDITION_TYPE_INDEPENDENT - ) { - $orderTotalInfo['total_convenience_fee_ti'] += $serviceLine['total_price_tax_incl']; - $orderTotalInfo['total_convenience_fee_te'] += $serviceLine['total_price_tax_excl']; - continue; + if ($hotelInfo = $objHtlBranchInfo->hotelBranchesInfo($this->context->language->id, 2, 1, $serviceProduct['id_hotel'])) { + $type_value['hotel_location'] = $hotelInfo['hotel_name'].', '.$hotelInfo['city']. + ($hotelInfo['state_name']?', '.$hotelInfo['state_name']:'').', '. + $hotelInfo['country_name'].', '.$hotelInfo['postcode']; } + $cart_hotel_service_products[] = $type_value; + } + } else if (Product::isSellableAsStandalone($type_value['selling_preference_type'])) { + $cover_image_arr = $product->getCover($type_value['product_id']); - if ($canSellWithHotel && $idHotel) { - $serviceLine['location'] = $serviceProduct['option_name']; - if ($hotelInfo = $objHtlBranchInfo->hotelBranchesInfo($this->context->language->id, 2, 1, $idHotel)) { - $serviceLine['hotel_location'] = $hotelInfo['hotel_name'].', '.$hotelInfo['city']. - ($hotelInfo['state_name']?', '.$hotelInfo['state_name']:'').', '. - $hotelInfo['country_name'].', '.$hotelInfo['postcode']; - } - $cart_hotel_service_products[] = $serviceLine; - } elseif ($canSellAsStandalone && !$idHotel && !$isRoomLinked) { - $cart_standalone_service_products[] = $serviceLine; - } else { - continue; - } - - $orderTotalInfo['total_standalone_products_ti'] += $serviceLine['total_price_tax_incl']; - $orderTotalInfo['total_standalone_products_te'] += $serviceLine['total_price_tax_excl']; + 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'); + } + $serviceProducts = $objServiceProductOrderDetail->getServiceProductsInOrder($idOrder, $type_value['id_order_detail'], $type_value['product_id']); + foreach ($serviceProducts as $serviceProduct) { + $type_value['unit_price_tax_excl'] = $serviceProduct['unit_price_tax_excl']; + $type_value['unit_price_tax_incl'] = $serviceProduct['unit_price_tax_incl']; + $type_value['total_price_tax_excl'] = $serviceProduct['total_price_tax_excl']; + $type_value['total_price_tax_incl'] = $serviceProduct['total_price_tax_incl']; + $type_value['product_quantity'] = $serviceProduct['quantity']; + $type_value['option_name'] = $serviceProduct['option_name']; + $cart_standalone_service_products[] = $type_value; } } } @@ -433,9 +415,17 @@ class OrderConfirmationControllerCore extends FrontController if (!$objCartOrder->hasInvoice()) { $orders_has_invoice = 0; } + $orderTotalInfo['total_standalone_products_ti'] += ($objCartOrder->getTotalProductsWithTaxes(false, false, Product::SELLING_PREFERENCE_HOTEL_STANDALONE)+$objCartOrder->getTotalProductsWithTaxes(false, false, Product::SELLING_PREFERENCE_STANDALONE)); + $orderTotalInfo['total_standalone_products_te'] += ($objCartOrder->getTotalProductsWithoutTaxes(false, false, Product::SELLING_PREFERENCE_HOTEL_STANDALONE)+$objCartOrder->getTotalProductsWithoutTaxes(false, false, Product::SELLING_PREFERENCE_STANDALONE)); $orderTotalInfo['total_wrapping'] += $objCartOrder->total_wrapping; $orderTotalInfo['total_rooms_te'] += $objCartOrder->getTotalProductsWithoutTaxes(false, true); $orderTotalInfo['total_rooms_ti'] += $objCartOrder->getTotalProductsWithTaxes(false, true); + $orderTotalInfo['total_auto_add_services_te'] += $objCartOrder->getTotalProductsWithoutTaxes(false, false, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE, 1, Product::PRICE_ADDITION_TYPE_WITH_ROOM); + $orderTotalInfo['total_auto_add_services_ti'] += $objCartOrder->getTotalProductsWithTaxes(false, false, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE, 1, Product::PRICE_ADDITION_TYPE_WITH_ROOM); + $orderTotalInfo['total_services_te'] += $objCartOrder->getTotalProductsWithoutTaxes(false, false, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE, 0); + $orderTotalInfo['total_services_ti'] += $objCartOrder->getTotalProductsWithTaxes(false, false, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE, 0); + $orderTotalInfo['total_convenience_fee_te'] += $objCartOrder->getTotalProductsWithoutTaxes(false, false, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE, 1, Product::PRICE_ADDITION_TYPE_INDEPENDENT); + $orderTotalInfo['total_convenience_fee_ti'] += $objCartOrder->getTotalProductsWithTaxes(false, false, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE, 1, Product::PRICE_ADDITION_TYPE_INDEPENDENT); $orderTotalInfo['total_discounts'] += $objCartOrder->total_discounts; $orderTotalInfo['total_discounts_te'] += $objCartOrder->total_discounts_tax_excl; @@ -481,6 +471,7 @@ class OrderConfirmationControllerCore extends FrontController $this->setTemplate(_PS_THEME_DIR_.'order-confirmation.tpl'); } + /** * Execute the hook displayPaymentReturn */ diff --git a/controllers/front/OrderDetailController.php b/controllers/front/OrderDetailController.php index 98e979865..c71439dab 100644 --- a/controllers/front/OrderDetailController.php +++ b/controllers/front/OrderDetailController.php @@ -101,7 +101,6 @@ class OrderDetailControllerCore extends FrontController $total_convenience_fee_te = 0; $total_convenience_fee_ti = 0; $roomTypes = array(); - $processedConvenienceFeeProducts = array(); $objOrderReturn = new OrderReturn(); $refundedAmount = 0; $refundedAmount = $objOrderReturn->getRefundedAmount($order->id); @@ -359,17 +358,8 @@ class OrderDetailControllerCore 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)); } - } else { - $canSellWithRoomType = Product::isSellableWithRoomType($type_value['selling_preference_type']); - $canSellWithHotel = Product::isSellableWithHotel($type_value['selling_preference_type']); - $canSellAsStandalone = Product::isSellableAsStandalone($type_value['selling_preference_type']); - - if ($canSellWithRoomType - && $type_value['product_auto_add'] - && $type_value['product_price_addition_type'] == Product::PRICE_ADDITION_TYPE_INDEPENDENT - && !isset($processedConvenienceFeeProducts[$type_value['product_id']]) - ) { - $processedConvenienceFeeProducts[$type_value['product_id']] = true; + } else if (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( $id_order, $type_value['product_id'], @@ -395,50 +385,37 @@ class OrderDetailControllerCore extends FrontController 1 ); } - - if ($canSellWithHotel || $canSellAsStandalone) { - $serviceProducts = $objServiceProductOrderDetail->getServiceProductsInOrder( - $id_order, - $type_value['id_order_detail'], - $type_value['product_id'] - ); - - foreach ($serviceProducts as $serviceProduct) { - $idHotel = (int)$serviceProduct['id_hotel']; - $isRoomLinked = !empty($serviceProduct['id_htl_booking_detail']); - - // Room-linked rows are already included in room detail block. - if ($isRoomLinked) { - continue; - } - - if ($canSellWithHotel && $idHotel) { - $hotelProduct = array_merge($type_value, $serviceProduct); - $hotelServiceProducts[] = $hotelProduct; - $formattedProduct = $serviceProduct; - $formattedProduct['refund_denied'] = 0; - if (isset($serviceProduct['refund_info']) - && ($serviceProduct['refund_info']['refunded'] && !$serviceProduct['refund_info']['id_customization']) - ) { - $formattedProduct['refund_denied'] = 1; - } - } elseif ($canSellAsStandalone && !$idHotel) { - $standaloneProduct = array_merge($type_value, $serviceProduct); - $standaloneServiceProducts[] = $standaloneProduct; - $formattedProduct = $serviceProduct; - } else { - continue; - } - - if (!isset($serviceProductsFormatted[$serviceProduct['id_product']])) { - $serviceProductsFormatted[$serviceProduct['id_product']] = array( - 'id_product' => $serviceProduct['id_product'], - 'name' => $serviceProduct['name'], - 'options' => array() - ); - } - $serviceProductsFormatted[$serviceProduct['id_product']]['options'][] = $formattedProduct; + } else if (Product::isSellableWithHotel($type_value['selling_preference_type'])) { + $hotelProducts = $objServiceProductOrderDetail->getServiceProductsInOrder($id_order, $type_value['id_order_detail'], $type_value['product_id']); + foreach ($hotelProducts as $hotelProduct) { + $hotelServiceProducts[] = array_merge($type_value, $hotelProduct); + if (!isset($serviceProductsFormatted[$hotelProduct['id_product']])) { + $serviceProductsFormatted[$hotelProduct['id_product']] = array( + 'id_product' => $hotelProduct['id_product'], + 'name' => $hotelProduct['name'], + 'options' => array() + ); } + $hotelProduct['refund_denied'] = 0; + if (isset($hotelProduct['refund_info']) + && ($hotelProduct['refund_info']['refunded'] && !$hotelProduct['refund_info']['id_customization']) + ) { + $hotelProduct['refund_denied'] = 1; + } + $serviceProductsFormatted[$hotelProduct['id_product']]['options'][] = $hotelProduct; + } + } else if (Product::isSellableAsStandalone($type_value['selling_preference_type'])) { + $standaloneProducts = $objServiceProductOrderDetail->getServiceProductsInOrder($id_order, $type_value['id_order_detail'], $type_value['product_id']); + foreach ($standaloneProducts as $standaloneProduct) { + $standaloneServiceProducts[] = array_merge($type_value, $standaloneProduct); + if (!isset($serviceProductsFormatted[$standaloneProduct['id_product']])) { + $serviceProductsFormatted[$standaloneProduct['id_product']] = array( + 'id_product' => $standaloneProduct['id_product'], + 'name' => $standaloneProduct['name'], + 'options' => array() + ); + } + $serviceProductsFormatted[$standaloneProduct['id_product']]['options'][] = $standaloneProduct; } } $roomTypes[$type_value['id_product']] = $type_value; diff --git a/js/admin.js b/js/admin.js index 48507c79a..06665a2df 100644 --- a/js/admin.js +++ b/js/admin.js @@ -1749,3 +1749,15 @@ function closeRecommendation() } }); } + +function applyPriceCalcMethodValue() +{ + var ci = $('#pcm_checkin').is(':checked') ? 1 : 0; + var co = $('#pcm_checkout').is(':checked') ? 2 : 0; + var ds = $('#pcm_duringstay').is(':checked') ? 4 : 0; + $('#price_calculation_method').val(ci + co + ds); +} +$(document).on('change','#pcm_checkin, #pcm_checkout, #pcm_duringstay', function() { + applyPriceCalcMethodValue(); +}); +applyPriceCalcMethodValue(); \ No newline at end of file diff --git a/js/admin/normal_products.js b/js/admin/normal_products.js index 9826b146f..6b283d882 100644 --- a/js/admin/normal_products.js +++ b/js/admin/normal_products.js @@ -565,34 +565,21 @@ product_tabs['Informations'] = new function(){ function applySellingPreferenceUIState() { - var sellingPreference = parseInt($('#selling_preference_type').val(), 10); - var showHotelTree = $.inArray(sellingPreference, [ - SELLING_PREFERENCE_HOTEL_STANDALONE, - SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE, - SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_STANDALONE, - SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE - ]) !== -1; - var showRoomTypeTree = $.inArray(sellingPreference, [ - 0, - SELLING_PREFERENCE_WITH_ROOM_TYPE, - SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE, - SELLING_PREFERENCE_STANDALONE_AND_WITH_ROOM_TYPE, - SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE - ]) !== -1; - var showAutoAddToCart = $.inArray(sellingPreference, [ - 0, - SELLING_PREFERENCE_WITH_ROOM_TYPE, - SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE, - SELLING_PREFERENCE_STANDALONE_AND_WITH_ROOM_TYPE, - SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE - ]) !== -1; + var withRoomType = $('#sp_with_room_type').is(':checked'); + var withHotel = $('#sp_with_hotel').is(':checked'); + var standalone = $('#sp_standalone').is(':checked'); + + // Bitmask: Room Type=1, Hotel=2, Standalone=4 + var sellingPreference = (withRoomType ? 1 : 0) + (withHotel ? 2 : 0) + (standalone ? 4 : 0); + $('#selling_preference_type').val(sellingPreference); + var $autoAddOff = $('#auto_add_to_cart_off'); var $autoAddCheckedInput; - toggleAssociationFieldNames('#associated_hotel_tree', showHotelTree); - toggleAssociationFieldNames('#associated_hotel_rooms_tree', showRoomTypeTree); + toggleAssociationFieldNames('#associated_hotel_tree', withHotel); + toggleAssociationFieldNames('#associated_hotel_rooms_tree', withRoomType); - if (showAutoAddToCart) { + if (withRoomType) { $('#auto_add_to_cart_container').show('fast'); $autoAddCheckedInput = $('input[name="auto_add_to_cart"]:checked'); if (!$autoAddCheckedInput.length) { @@ -609,12 +596,12 @@ product_tabs['Informations'] = new function(){ $('#product_options').show('fast'); } - $('#selling_preference_type').on('change',function(){ + $('#sp_with_room_type, #sp_with_hotel, #sp_standalone').on('change', function(){ setTimeout(function() { applySellingPreferenceUIState(); }, 0); }); - $('#selling_preference_type').trigger('change'); + applySellingPreferenceUIState(); $('#simple_product').attr('checked', true); $('input[name="type_product"]').on('click', function(e) diff --git a/modules/blockcart/ajax-cart.js b/modules/blockcart/ajax-cart.js index 85c34b47e..a7cdbe2e3 100644 --- a/modules/blockcart/ajax-cart.js +++ b/modules/blockcart/ajax-cart.js @@ -748,11 +748,12 @@ 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); + var isHotelRow = (typeof ids[3] != 'undefined' && parseInt(ids[3]) > 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 (isHotelRow && (typeof jsonData.products[aProduct]['hotel_wise_data'] != 'undefined' && jsonData.products[aProduct]['hotel_wise_data'].length)) { + if (isHotelRow && jsonData.products[aProduct]['id'] == ids[0] + && (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] == this.id_hotel) { stayInTheCart = true; @@ -760,7 +761,20 @@ var ajaxCart = { }); } else { if (jsonData.products[aProduct]['id'] == ids[0] && (!ids[1] || jsonData.products[aProduct]['idCombination'] == ids[1])) { - stayInTheCart = true; + var productType = parseInt(jsonData.products[aProduct]['selling_preference_type']); + var isStandaloneRow = (typeof ids[3] == 'undefined' || parseInt(ids[3]) === 0); + + if (!isStandaloneRow) { + } else if ( + ajaxCart.isSellableAsStandalone(productType) + && (ajaxCart.isSellableWithHotel(productType) || ajaxCart.isSellableWithRoomType(productType)) + ) { + if (parseInt(jsonData.products[aProduct]['standalone_total_qty']) > 0) { + stayInTheCart = true; + } + } else { + stayInTheCart = true; + } // update the product customization display (when the product is still in the cart) ajaxCart.hideOldProductCustomizations(jsonData.products[aProduct], productDomId); } diff --git a/modules/hotelreservationsystem/classes/HotelCartBookingData.php b/modules/hotelreservationsystem/classes/HotelCartBookingData.php index 86b46ddd7..4a8565923 100644 --- a/modules/hotelreservationsystem/classes/HotelCartBookingData.php +++ b/modules/hotelreservationsystem/classes/HotelCartBookingData.php @@ -1027,6 +1027,25 @@ class HotelCartBookingData extends ObjectModel } } } + + // Check available stock: remove if cart quantity exceeds what is in stock. + if (!$toRemoveService) { + $availableQty = Product::getQuantity((int)$service['id_product']); + $totalQty = Cart::getProductQtyInCart((int)$service['id_cart'],(int)$service['id_product']); + if (!Product::isAvailableWhenOutOfStock(StockAvailable::outOfStock((int)$service['id_product'])) + && $availableQty !== false + && $availableQty < (int)$totalQty + ) { + $toRemoveService = 1; + } + } + + // Check max quantity: remove if cart quantity exceeds the product's configured maximum. + if (!$toRemoveService && $product->allow_multiple_quantity && (int)$product->max_quantity > 0) { + if ((int)$service['quantity'] > (int)$product->max_quantity) { + $toRemoveService = 1; + } + } } if ($toRemoveService) { diff --git a/modules/hotelreservationsystem/classes/HotelHelper.php b/modules/hotelreservationsystem/classes/HotelHelper.php index 709a9b23a..afc2a0735 100644 --- a/modules/hotelreservationsystem/classes/HotelHelper.php +++ b/modules/hotelreservationsystem/classes/HotelHelper.php @@ -2187,7 +2187,7 @@ class HotelHelper 'price' => '250', 'auto_add_to_cart' => 1, 'show_at_front' => 0, - 'price_calculation_method' => Product::PRICE_CALCULATION_METHOD_PER_BOOKING, + 'price_calculation_method' => Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURINGSTAY, 'price_addition_type' => Product::PRICE_ADDITION_TYPE_INDEPENDENT, 'en' => array( 'name' => 'Internet Handling Charges', diff --git a/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php b/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php index 9bac1f873..06bcd0079 100644 --- a/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php +++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php @@ -200,7 +200,12 @@ class RoomTypeServiceProduct extends ObjectModel $subCategory )) { $serviceProducts = Product::getProductsProperties($idLang, $serviceProducts); - foreach($serviceProducts as &$serviceProduct) { + foreach($serviceProducts as $key => &$serviceProduct) { + if (!$serviceProduct['allow_oosp'] && $serviceProduct['quantity'] <= 0) { + unset($serviceProducts[$key]); + continue; + } + $serviceProduct['price_tax_exc'] = Product::getServiceProductPrice( (int)$serviceProduct['id_product'], 0, diff --git a/modules/hotelreservationsystem/classes/ServiceProductCartDetail.php b/modules/hotelreservationsystem/classes/ServiceProductCartDetail.php index f7456863e..512e12b6b 100644 --- a/modules/hotelreservationsystem/classes/ServiceProductCartDetail.php +++ b/modules/hotelreservationsystem/classes/ServiceProductCartDetail.php @@ -95,7 +95,9 @@ class ServiceProductCartDetail extends ObjectModel $objHotelCartBookingData->date_from, $objHotelCartBookingData->date_to ); - $updateQty *= $numdays; + if($numdays){ + $updateQty *= $numdays; + } if ($objServiceProductCartDetail->delete()) { $objCart = new Cart($product['id_cart']); if (isset(Context::getContext()->controller->controller_type)) { @@ -269,7 +271,7 @@ class ServiceProductCartDetail extends ObjectModel 1, null, $product['htl_cart_booking_id'] - )/$numDays; + ) / max($numDays, 1); $priceTaxExcl = Product::getServiceProductPrice( $objProduct->id, $product['id_product_option'], @@ -284,7 +286,7 @@ class ServiceProductCartDetail extends ObjectModel 1, null, $product['htl_cart_booking_id'] - )/$numDays; + ) / max($numDays, 1); $optionDetails = false; if (ServiceProductOption::productHasOptions($product['id_product'])) { @@ -461,9 +463,11 @@ class ServiceProductCartDetail extends ObjectModel $objHotelCartBooking->date_from, $objHotelCartBooking->date_to ); - $quantity = $objServiceProductCartDetail->quantity * $numDays; + if($numDays){ + $quantity = $quantity * $numDays; + } } - + $objCart = new Cart($idCart); return $objCart->updateQty($quantity, $idProduct); } @@ -514,6 +518,16 @@ class ServiceProductCartDetail extends ObjectModel $updateQunatity = $objServiceProductCartDetail->delete(); } if ($updateQunatity) { + if (Validate::isLoadedObject($objHotelCartBooking = new HotelCartBookingData($product['id_hotel_cart_booking']))) { + $objProduct = new Product((int) $product['id_product']); + $numDays = Product::getPriceCalculationApplicableDays( + $objProduct->price_calculation_method, + $objHotelCartBooking->date_from, + $objHotelCartBooking->date_to + ); + $removedQuantity = $removedQuantity * $numDays; + } + $objCart = new Cart($idCart); if (isset(Context::getContext()->controller->controller_type)) { $controllerType = Context::getContext()->controller->controller_type; diff --git a/modules/hotelreservationsystem/views/templates/admin/order_refund_requests/helpers/view/view.tpl b/modules/hotelreservationsystem/views/templates/admin/order_refund_requests/helpers/view/view.tpl index d8cadf9e9..3a181b149 100644 --- a/modules/hotelreservationsystem/views/templates/admin/order_refund_requests/helpers/view/view.tpl +++ b/modules/hotelreservationsystem/views/templates/admin/order_refund_requests/helpers/view/view.tpl @@ -372,7 +372,7 @@
diff --git a/modules/qlostatsserviceproducts/qlostatsserviceproducts.php b/modules/qlostatsserviceproducts/qlostatsserviceproducts.php index fd72eb7e3..684cf15f9 100644 --- a/modules/qlostatsserviceproducts/qlostatsserviceproducts.php +++ b/modules/qlostatsserviceproducts/qlostatsserviceproducts.php @@ -179,24 +179,25 @@ class QloStatsServiceProducts extends ModuleGrid public function setQueryForServices($dateBetween) { + $numNightsSql = 'IFNULL(DATEDIFF(hbd.`date_to`, hbd.`date_from`), 0)'; + $applicableDaysSql = 'CASE + WHEN spod.`id_htl_booking_detail` IS NULL OR spod.`id_htl_booking_detail` = 0 THEN 1 + WHEN od.`product_price_calculation_method` IN ('.(int)Product::PRICE_CALCULATION_METHOD_ONLY_CHECKIN_DAY.', '.(int)Product::PRICE_CALCULATION_METHOD_ONLY_CHECKOUT_DAY.') THEN 1 + WHEN od.`product_price_calculation_method` = '.(int)Product::PRICE_CALCULATION_METHOD_ONLY_DURINGSTAY_DAY.' THEN GREATEST('.$numNightsSql.' - 1, 1) + WHEN od.`product_price_calculation_method` = '.(int)Product::PRICE_CALCULATION_METHOD_CHECKIN_DAY_AND_CHECKOUT_DAY.' THEN 2 + WHEN od.`product_price_calculation_method` IN ('.(int)Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_DURINGSTAY.', '.(int)Product::PRICE_CALCULATION_METHOD_CHECKOUT_AND_DURINGSTAY.') THEN GREATEST('.$numNightsSql.', 1) + WHEN od.`product_price_calculation_method` = '.(int)Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURINGSTAY.' THEN GREATEST('.$numNightsSql.' + 1, 1) + ELSE GREATEST('.$numNightsSql.', 1) + END'; + $this->query = '(SELECT od.`product_name` as `display_name`, p.`active`, od.`product_auto_add` as auto_add_to_cart, od.`product_price_addition_type` as price_addition_type, ROUND(IFNULL(SUM(spod.`total_price_tax_excl` / o.`conversion_rate`), 0), 2) / SUM( - IF(od.`product_price_calculation_method` = '.(int)Product::PRICE_CALCULATION_METHOD_PER_DAY.', - (IF(spod.`id_htl_booking_detail`, - DATEDIFF(hbd.`date_to`, hbd.`date_from`), - 1)) * spod.`quantity`, - spod.`quantity` - ) + ('.$applicableDaysSql.') * spod.`quantity` ) AS avgPriceSold, IFNULL(SUM( - IF(od.`product_price_calculation_method` = '.(int)Product::PRICE_CALCULATION_METHOD_PER_DAY.', - (IF(spod.`id_htl_booking_detail`, - DATEDIFF(hbd.`date_to`, hbd.`date_from`), - 1)) * spod.`quantity`, - spod.`quantity` - ) + ('.$applicableDaysSql.') * spod.`quantity` ), 0) AS totalQuantitySold, ROUND(IFNULL(SUM(spod.`total_price_tax_excl` / o.`conversion_rate`), 0), 2) AS totalPriceSold FROM '._DB_PREFIX_.'service_product_order_detail spod diff --git a/themes/hotel-reservation-theme/_partials/cart_booking_demands.tpl b/themes/hotel-reservation-theme/_partials/cart_booking_demands.tpl index 5a3db8aaa..b22722e4f 100644 --- a/themes/hotel-reservation-theme/_partials/cart_booking_demands.tpl +++ b/themes/hotel-reservation-theme/_partials/cart_booking_demands.tpl @@ -82,7 +82,7 @@

- {if isset($selected_adv_option) && isset($demand['adv_option'][$selected_adv_option]['price'])}{convertPrice price = $demand['adv_option'][$selected_adv_option]['price']|escape:'html':'UTF-8'}{else}{convertPrice price = $demand['price']|escape:'html':'UTF-8'}{/if}{if $demand['price_calc_method'] == HotelRoomTypeGlobalDemand::WK_PRICE_CALC_METHOD_EACH_DAY}{l s='/Night'}{/if} + {if isset($selected_adv_option) && isset($demand['adv_option'][$selected_adv_option]['price'])}{convertPrice price = $demand['adv_option'][$selected_adv_option]['price']|escape:'html':'UTF-8'}{else}{convertPrice price = $demand['price']|escape:'html':'UTF-8'}{/if}{if $demand['price_calc_method'] == HotelRoomTypeGlobalDemand::WK_PRICE_CALC_METHOD_EACH_DAY}{l s='/Day'}{/if}

@@ -156,7 +156,7 @@ $product.price_calculation_method, $cartRoom.date_from|default:'', $cartRoom.date_to|default:'' - ) > 1}{l s='/Night'}{/if} + ) > 1}{l s='/Day'}{/if} {/if} diff --git a/themes/hotel-reservation-theme/_partials/service-products-list-row.tpl b/themes/hotel-reservation-theme/_partials/service-products-list-row.tpl index 5a8896426..fa04edfea 100644 --- a/themes/hotel-reservation-theme/_partials/service-products-list-row.tpl +++ b/themes/hotel-reservation-theme/_partials/service-products-list-row.tpl @@ -59,7 +59,7 @@ $service_product.date_from|default:$date_from|default:'', $service_product.date_to|default:$date_to|default:'' ) > 1} - {l s='/Night'} + {l s='/Day'} {/if} {/block} {if $service_product.allow_multiple_quantity && $service_product.available_for_order && $service_product.max_quantity > 0} diff --git a/themes/hotel-reservation-theme/js/modules/blockcart/ajax-cart.js b/themes/hotel-reservation-theme/js/modules/blockcart/ajax-cart.js index 85c34b47e..a69ecd93f 100644 --- a/themes/hotel-reservation-theme/js/modules/blockcart/ajax-cart.js +++ b/themes/hotel-reservation-theme/js/modules/blockcart/ajax-cart.js @@ -748,11 +748,12 @@ 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); + var isHotelRow = (typeof ids[3] != 'undefined' && parseInt(ids[3]) > 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 (isHotelRow && (typeof jsonData.products[aProduct]['hotel_wise_data'] != 'undefined' && jsonData.products[aProduct]['hotel_wise_data'].length)) { + if (isHotelRow && jsonData.products[aProduct]['id'] == ids[0] + && (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] == this.id_hotel) { stayInTheCart = true; @@ -760,7 +761,20 @@ var ajaxCart = { }); } else { if (jsonData.products[aProduct]['id'] == ids[0] && (!ids[1] || jsonData.products[aProduct]['idCombination'] == ids[1])) { - stayInTheCart = true; + var productType = parseInt(jsonData.products[aProduct]['selling_preference_type']); + var isStandaloneRow = (typeof ids[3] == 'undefined' || parseInt(ids[3]) === 0); + + if (!isStandaloneRow) { + } else if ( + ajaxCart.isSellableAsStandalone(productType) + && (ajaxCart.isSellableWithHotel(productType) || ajaxCart.isSellableWithRoomType(productType)) + ) { + if (parseInt(jsonData.products[aProduct]['standalone_total_qty']) > 0) { + stayInTheCart = true; + } + } else { + stayInTheCart = true; + } // update the product customization display (when the product is still in the cart) ajaxCart.hideOldProductCustomizations(jsonData.products[aProduct], productDomId); } @@ -945,7 +959,7 @@ var ajaxCart = { if (product.booking_product) { content += formatCurrency(parseFloat(product.bookingData.total_room_type_amount), currency_format, currency_sign, currency_blank); - } else if (typeof(hotel_wise_data) != 'undefined') { + } else if (typeof(hotel_wise_data) != 'undefined' && ajaxCart.isSellableWithHotel(product.selling_preference_type)) { 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); diff --git a/themes/hotel-reservation-theme/modules/blockcart/blockcart.tpl b/themes/hotel-reservation-theme/modules/blockcart/blockcart.tpl index a45968365..182945dfe 100644 --- a/themes/hotel-reservation-theme/modules/blockcart/blockcart.tpl +++ b/themes/hotel-reservation-theme/modules/blockcart/blockcart.tpl @@ -64,7 +64,7 @@ {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::isSellableAsStandalone($product.selling_preference_type) || Product::isSellableWithHotel($product.selling_preference_type)} - {if isset($product.hotel_wise_data) && $product.hotel_wise_data} + {if Product::isSellableWithHotel($product.selling_preference_type) && 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} @@ -144,7 +144,7 @@ {/if} {/block} {block name='blockcart_shopping_cart_total_convenience_fee'} - {if isset($total_convenience_fee)} + {if isset($total_convenience_fee) && $total_convenience_fee}
{convertPrice price=$total_convenience_fee} {l s='Convenience Fees' mod='blockcart'} @@ -326,7 +326,7 @@
--> {block name='blockcart_layer_cart_total_convenience_fee'} - {if isset($total_convenience_fee)} + {if isset($total_convenience_fee) && $total_convenience_fee}
{l s='Convenience Fees' mod='blockcart'} diff --git a/themes/hotel-reservation-theme/order-confirmation.tpl b/themes/hotel-reservation-theme/order-confirmation.tpl index e8cc450cc..2297d556b 100644 --- a/themes/hotel-reservation-theme/order-confirmation.tpl +++ b/themes/hotel-reservation-theme/order-confirmation.tpl @@ -254,9 +254,9 @@
{l s='Unit Price'}
{if $group_use_tax} - {displayWtPriceWithCurrency price=$product.unit_price_tax_incl currency=$currency} + {displayWtPriceWithCurrency price=$product.unit_price_tax_incl currency=$objOrderCurrency} {else} - {displayWtPriceWithCurrency price=$product.unit_price_tax_excl currency=$currency} + {displayWtPriceWithCurrency price=$product.unit_price_tax_excl currency=$objOrderCurrency} {/if}
@@ -272,9 +272,9 @@
{l s='Total Pricing'}
{if $group_use_tax} - {displayWtPriceWithCurrency price=$product.total_price_tax_incl currency=$currency} + {displayWtPriceWithCurrency price=$product.total_price_tax_incl currency=$objOrderCurrency} {else} - {displayWtPriceWithCurrency price=$product.total_price_tax_excl currency=$currency} + {displayWtPriceWithCurrency price=$product.total_price_tax_excl currency=$objOrderCurrency} {/if}
@@ -328,9 +328,9 @@
{l s='Unit Price'}
{if $group_use_tax} - {displayWtPriceWithCurrency price=$product.unit_price_tax_incl currency=$currency} + {displayWtPriceWithCurrency price=$product.unit_price_tax_incl currency=$objOrderCurrency} {else} - {displayWtPriceWithCurrency price=$product.unit_price_tax_excl currency=$currency} + {displayWtPriceWithCurrency price=$product.unit_price_tax_excl currency=$objOrderCurrency} {/if}
@@ -346,9 +346,9 @@
{l s='Total Pricing'}
{if $group_use_tax} - {displayWtPriceWithCurrency price=$product.total_price_tax_incl currency=$currency} + {displayWtPriceWithCurrency price=$product.total_price_tax_incl currency=$objOrderCurrency} {else} - {displayWtPriceWithCurrency price=$product.total_price_tax_excl currency=$currency} + {displayWtPriceWithCurrency price=$product.total_price_tax_excl currency=$objOrderCurrency} {/if}
diff --git a/themes/hotel-reservation-theme/order-detail.tpl b/themes/hotel-reservation-theme/order-detail.tpl index d1682db6a..c0bc6432d 100644 --- a/themes/hotel-reservation-theme/order-detail.tpl +++ b/themes/hotel-reservation-theme/order-detail.tpl @@ -1133,7 +1133,7 @@ {addJsDefL name=pending_state_msg}{l s='Pending...' js=1}{/addJsDefL} {addJsDefL name=mail_sending_err}{l s='Some error occurred while sending mail to the customer' js=1}{/addJsDefL} {addJsDefL name=refund_request_sending_error}{l s='Some error occurred while processing request for booking cancellation.' js=1}{/addJsDefL} - {addJsDefL name=no_bookings_selected}{l s='Please select at least one room to proceed for cancellation.' js=1}{/addJsDefL} + {addJsDefL name=no_bookings_selected}{l s='Please select at least one room or service to proceed for cancellation.' js=1}{/addJsDefL} {addJsDefL name=refund_request_success_txt}{l s='Request for booking cancellation is successffully created.' js=1}{/addJsDefL} {addJsDefL name=order_message_choose_txt}{l s='-- Choose --' js=1}{/addJsDefL} {addJsDefL name=order_message_success_txt}{l s='Order message sent successfully.' js=1}{/addJsDefL} diff --git a/themes/hotel-reservation-theme/product.tpl b/themes/hotel-reservation-theme/product.tpl index 9492fbc86..70f6deb30 100644 --- a/themes/hotel-reservation-theme/product.tpl +++ b/themes/hotel-reservation-theme/product.tpl @@ -455,7 +455,7 @@ {/if}
-

{$demand['name']|escape:'html':'UTF-8'} {if $product->show_price && !isset($restricted_country_mode) && !$PS_CATALOG_MODE}{convertPrice price = $demand['price']}{if $demand['price_calc_method'] == $WK_PRICE_CALC_METHOD_EACH_DAY}{l s='/Night'}{/if}{/if}

+

{$demand['name']|escape:'html':'UTF-8'} {if $product->show_price && !isset($restricted_country_mode) && !$PS_CATALOG_MODE}{convertPrice price = $demand['price']}{if $demand['price_calc_method'] == $WK_PRICE_CALC_METHOD_EACH_DAY}{l s='/day'}{/if}{/if}

{if isset($demand['adv_option']) && $demand['adv_option']}