diff --git a/admin/themes/default/template/controllers/orders/_cart_booking_demands.tpl b/admin/themes/default/template/controllers/orders/_cart_booking_demands.tpl index bd695ea59..fad6ca46e 100644 --- a/admin/themes/default/template/controllers/orders/_cart_booking_demands.tpl +++ b/admin/themes/default/template/controllers/orders/_cart_booking_demands.tpl @@ -83,7 +83,7 @@ {if isset($selected_adv_option) && isset($demand['adv_option'][$selected_adv_option]['price_tax_excl'])}{convertPrice price = $demand['adv_option'][$selected_adv_option]['price_tax_excl']|escape:'html':'UTF-8'}{else if isset($demand['adv_option']) && $demand['adv_option']}{convertPrice price = $demand['adv_option'][$demand['adv_option']|@key]['price_tax_excl']}{else}{convertPrice price = $demand['price_tax_excl']|escape:'html':'UTF-8'}{/if} {if $demand['price_calc_method'] == HotelRoomTypeGlobalDemand::WK_PRICE_CALC_METHOD_EACH_DAY} - {l s='/ day'} + {l s='/ night'} {/if} diff --git a/admin/themes/default/template/controllers/orders/modals/_add_order_extra_services_tab_content.tpl b/admin/themes/default/template/controllers/orders/modals/_add_order_extra_services_tab_content.tpl index da29873a8..bb77c1095 100644 --- a/admin/themes/default/template/controllers/orders/modals/_add_order_extra_services_tab_content.tpl +++ b/admin/themes/default/template/controllers/orders/modals/_add_order_extra_services_tab_content.tpl @@ -99,7 +99,7 @@ $selectedRoomServiceProduct['date_from'], $selectedRoomServiceProduct['date_to'] ) > 1} - {l s='/ day'} + {l s='/ night'} {/if} {/if} 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 e4f40435a..3537d8dd2 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='/ day'} + {l s='/ night'} {/if} @@ -122,7 +122,7 @@ {/if} {if $demand['price_calc_method'] == HotelRoomTypeGlobalDemand::WK_PRICE_CALC_METHOD_EACH_DAY} - {l s='/ day'} + {l s='/ night'} {/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='/ day'} + {l s='/ night'} {/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 b322c7dde..de2af862f 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 @@ -89,7 +89,7 @@ $additionalServices['date_from'], $additionalServices['date_to'] ) > 1} - {l s='/ day'} + {l s='/ night'} {/if} @@ -164,7 +164,7 @@ $additionalServices['date_from'], $additionalServices['date_to'] ) > 1} - {l s='/ day'} + {l s='/ night'} {/if} @@ -320,7 +320,7 @@ $additionalServices['date_from'], $additionalServices['date_to'] ) > 1} - {l s='/ day'} + {l s='/ night'} {/if} diff --git a/classes/order/Order.php b/classes/order/Order.php index 26ee52823..412f4460b 100644 --- a/classes/order/Order.php +++ b/classes/order/Order.php @@ -2882,27 +2882,13 @@ class OrderCore extends ObjectModel } // check hotel linked products $objServiceProductOrderDetail = new ServiceProductOrderDetail(); - $serviceProducts = array(); - $sellingPreferenceTypes = array( - Product::SELLING_PREFERENCE_HOTEL_STANDALONE, - Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE, - Product::SELLING_PREFERENCE_STANDALONE, - Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_STANDALONE, - Product::SELLING_PREFERENCE_STANDALONE_AND_WITH_ROOM_TYPE, - Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE, - ); - foreach ($sellingPreferenceTypes as $sellingPreferenceType) { - $serviceProducts = array_merge( - $serviceProducts, - $objServiceProductOrderDetail->getServiceProductsInOrder($this->id, 0, 0, $sellingPreferenceType) - ); + if ($hotelProducts = $objServiceProductOrderDetail->getServiceProductsInOrder($this->id, 0, 0, Product::SELLING_PREFERENCE_HOTEL_STANDALONE)) { + $res &= $this->checkList($hotelProducts, $action, false); + $hasRoomsOrProducts = 1; } - $serviceProducts = array_filter($serviceProducts, function ($serviceProduct) { - return empty($serviceProduct['id_htl_booking_detail']); - }); - if ($serviceProducts) { - $res &= $this->checkList($serviceProducts, $action, false); + if ($standaloneProducts = $objServiceProductOrderDetail->getServiceProductsInOrder($this->id, 0, 0, Product::SELLING_PREFERENCE_STANDALONE)) { + $res &= $this->checkList($standaloneProducts, $action, false); $hasRoomsOrProducts = 1; } diff --git a/controllers/admin/AdminCartsController.php b/controllers/admin/AdminCartsController.php index 2b8115761..a30655767 100644 --- a/controllers/admin/AdminCartsController.php +++ b/controllers/admin/AdminCartsController.php @@ -354,12 +354,7 @@ class AdminCartsControllerCore extends AdminController $objServiceProductCartDetail = new ServiceProductCartDetail(); $hotelProducts = $objServiceProductCartDetail->getServiceProductsInCart( $cart->id, - [ - Product::SELLING_PREFERENCE_HOTEL_STANDALONE, - Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE, - Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_STANDALONE, - Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE - ], + [], $idHotel = null, 0, null, @@ -373,14 +368,15 @@ class AdminCartsControllerCore extends AdminController 1 ); + $hotelProducts = array_filter($hotelProducts, function ($product) { + return $product['id_hotel'] > 0 && $product['id_hotel_cart_booking'] == 0; + }); + $standaloneProducts = $objServiceProductCartDetail->getServiceProductsInCart( $cart->id, - [ - Product::SELLING_PREFERENCE_STANDALONE, - Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_STANDALONE, - Product::SELLING_PREFERENCE_STANDALONE_AND_WITH_ROOM_TYPE, - Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE - ] + [], + 0, + 0 ); if (count($standaloneProducts)) { @@ -1205,20 +1201,22 @@ class AdminCartsControllerCore extends AdminController if (Configuration::get('PS_ALLOW_ADD_ALL_SERVICES_IN_BOOKING')) { // get all services $objProduct = new Product(); - $serviceProducts = array_merge( - $objProduct->getServiceProducts(true, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE), - $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) - ); + $serviceProducts = array_values(array_filter( + $objProduct->getServiceProducts(null), + function ($serviceProduct) { + return Product::isSellableWithRoomType($serviceProduct['id_product']); + } + )); 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, @@ -1554,14 +1552,22 @@ class AdminCartsControllerCore extends AdminController if (Configuration::get('PS_ALLOW_ADD_ALL_SERVICES_IN_BOOKING')) { // get all services $objProduct = new Product(); - $serviceProducts = array_merge( - $objProduct->getServiceProducts(true, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE), - $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) - ); + $serviceProducts = array_values(array_filter( + $objProduct->getServiceProducts(null), + function ($serviceProduct) { + return Product::isSellableWithRoomType($serviceProduct['id_product']); + } + )); 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'], $objCartBookingData->date_from, @@ -1578,7 +1584,7 @@ class AdminCartsControllerCore extends AdminController $objCartBookingData->date_from, $objCartBookingData->date_to, $objCartBookingData->id_cart - )/$numDays; + )/ max($numDays, 1); } } } else { @@ -1742,7 +1748,7 @@ class AdminCartsControllerCore extends AdminController $idServiceProduct, $operator, $quantity, - false, + 0, $idCartBooking ))) { $originalPrice = Product::getPriceStatic($idServiceProduct, false); diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index fcf696f8a..d28c8fd23 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -992,12 +992,12 @@ class AdminOrdersControllerCore extends AdminController if (Configuration::get('PS_ALLOW_ADD_ALL_SERVICES_IN_BOOKING')) { // get all services $objProduct = new Product(); - $serviceProducts = array_merge( - $objProduct->getServiceProducts(true, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE), - $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) - ); + $serviceProducts = array_values(array_filter( + $objProduct->getServiceProducts(null), + function ($serviceProduct) { + return Product::isSellableWithRoomType($serviceProduct['id_product']); + } + )); if($serviceProducts) { foreach ($serviceProducts as $key => $servProduct) { @@ -1156,35 +1156,18 @@ class AdminOrdersControllerCore extends AdminController } $refundReqProducts = $objOrderReturn->getOrderRefundRequestedProducts($objOrder->id, 0, 1, 1); - $serviceProducts = array(); - $sellingPreferenceTypes = array( - Product::SELLING_PREFERENCE_HOTEL_STANDALONE, - Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE, - Product::SELLING_PREFERENCE_STANDALONE, - Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_STANDALONE, - Product::SELLING_PREFERENCE_STANDALONE_AND_WITH_ROOM_TYPE, - Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE, - ); - foreach ($sellingPreferenceTypes as $sellingPreferenceType) { - $serviceProducts = array_merge( - $serviceProducts, - $objServiceProductOrderDetail->getServiceProductsInOrder($objOrder->id, 0, 0, $sellingPreferenceType) - ); - } - - $hotelProducts = array(); - $standaloneProducts = array(); - foreach ($serviceProducts as $product) { + $hotelProducts = $objServiceProductOrderDetail->getServiceProductsInOrder($objOrder->id, 0, 0, Product::SELLING_PREFERENCE_HOTEL_STANDALONE); + foreach($hotelProducts as $key => $product) { if ((in_array($product['id_service_product_order_detail'], $refundReqProducts)) || $product['is_refunded']) { - continue; - } - if (!empty($product['id_hotel'])) { - $hotelProducts[] = $product; - } else if (!$product['id_hotel'] && !$product['id_htl_booking_detail']) { - $standaloneProducts[] = $product; + unset($hotelProducts[$key]); + } + } + $standaloneProducts = $objServiceProductOrderDetail->getServiceProductsInOrder($objOrder->id, 0, 0, Product::SELLING_PREFERENCE_STANDALONE); + foreach($standaloneProducts as $key => $product) { + if ((in_array($product['id_service_product_order_detail'], $refundReqProducts)) || $product['is_refunded']) { + unset($standaloneProducts[$key]); } } - $this->context->smarty->assign( array( @@ -2454,20 +2437,8 @@ class AdminOrdersControllerCore extends AdminController } } - $hotelProducts = array(); - $hotelSellingTypes = array( - Product::SELLING_PREFERENCE_HOTEL_STANDALONE, - Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE, - Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_STANDALONE, - Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE, - ); - foreach ($hotelSellingTypes as $sellingPreferenceType) { - $hotelProducts = array_merge( - $hotelProducts, - $objRoomTypeServProdOrderDtl->getServiceProductsInOrder($order->id, 0, 0, $sellingPreferenceType) - ); - } - if ($hotelProducts && is_array($hotelProducts)) { + + if ($hotelProducts = $objRoomTypeServProdOrderDtl->getServiceProductsInOrder($order->id, 0, 0, Product::SELLING_PREFERENCE_HOTEL_STANDALONE)) { foreach ($hotelProducts as $serviceProduct) { $objRoomTypeServProdOrderDtl = new ServiceProductOrderDetail($serviceProduct['id_service_product_order_detail']); foreach ($fields as $field) { @@ -2481,20 +2452,8 @@ class AdminOrdersControllerCore extends AdminController $objRoomTypeServProdOrderDtl->save(); } } - $standaloneProducts = array(); - $standaloneSellingTypes = array( - Product::SELLING_PREFERENCE_STANDALONE, - Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_STANDALONE, - Product::SELLING_PREFERENCE_STANDALONE_AND_WITH_ROOM_TYPE, - Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE, - ); - foreach ($standaloneSellingTypes as $sellingPreferenceType) { - $standaloneProducts = array_merge( - $standaloneProducts, - $objRoomTypeServProdOrderDtl->getServiceProductsInOrder($order->id, 0, 0, $sellingPreferenceType) - ); - } - if ($standaloneProducts && is_array($standaloneProducts)) { + + if ($standaloneProducts = $objRoomTypeServProdOrderDtl->getServiceProductsInOrder($order->id, 0, 0, Product::SELLING_PREFERENCE_STANDALONE)) { foreach ($standaloneProducts as $serviceProduct) { $objRoomTypeServProdOrderDtl = new ServiceProductOrderDetail($serviceProduct['id_service_product_order_detail']); foreach ($fields as $field) { @@ -2988,30 +2947,9 @@ class AdminOrdersControllerCore extends AdminController // if order has normal products the add kpi for total products $objServiceProductOrderDetail = new ServiceProductOrderDetail(); - $serviceProducts = array(); - $sellingPreferenceTypes = array( - Product::SELLING_PREFERENCE_HOTEL_STANDALONE, - Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE, - Product::SELLING_PREFERENCE_STANDALONE, - Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_STANDALONE, - Product::SELLING_PREFERENCE_STANDALONE_AND_WITH_ROOM_TYPE, - Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE, - ); - foreach ($sellingPreferenceTypes as $sellingPreferenceType) { - $serviceProducts = array_merge( - $serviceProducts, - $objServiceProductOrderDetail->getServiceProductsInOrder($objOrder->id, 0, 0, $sellingPreferenceType) - ); - } - $hotelProducts = array(); - $standaloneProducts = array(); - foreach ($serviceProducts as $serviceProduct) { - if (!empty($serviceProduct['id_hotel'])) { - $hotelProducts[] = $serviceProduct; - } else if (!$serviceProduct['id_hotel'] &&!$serviceProduct['id_htl_booking_detail']) { - $standaloneProducts[] = $serviceProduct; - } - } + $hotelProducts = $objServiceProductOrderDetail->getServiceProductsInOrder($objOrder->id, 0, 0, Product::SELLING_PREFERENCE_HOTEL_STANDALONE); + $standaloneProducts = $objServiceProductOrderDetail->getServiceProductsInOrder($objOrder->id, 0, 0, Product::SELLING_PREFERENCE_STANDALONE); + if ($hotelProducts || $standaloneProducts) { $helper = new HelperKpi(); $helper->id = 'box-total-products'; @@ -3357,16 +3295,16 @@ class AdminOrdersControllerCore extends AdminController } else { $product['image_link'] = $this->context->link->getImageLink($objProduct->link_rewrite, $this->context->language->iso_code.'-default', 'small_default'); } - if (Product::isSellableWithHotel($product['product_id']) - || Product::isSellableAsStandalone($product['product_id']) - ) { - $serviceProducts = $objServiceProductOrderDetail->getServiceProductsInOrder($order->id, $product['id_order_detail'], $product['product_id']); - foreach ($serviceProducts as $serviceProduct) { - if (!empty($serviceProduct['id_hotel']) && Product::isSellableWithHotel($product['product_id'])) { - $orderHotelServiceProducts[] = array_merge($product, $serviceProduct); - } elseif (!$serviceProduct['id_hotel'] && !$serviceProduct['id_htl_booking_detail'] && Product::isSellableAsStandalone($product['product_id'])) { - $orderStandaloneServiceProducts[] = array_merge($product, $serviceProduct); - } + if ($product['selling_preference_type'] == Product::SELLING_PREFERENCE_HOTEL_STANDALONE) { + $hotelProducts = $objServiceProductOrderDetail->getServiceProductsInOrder($order->id, $product['id_order_detail'], $product['product_id'], Product::SELLING_PREFERENCE_HOTEL_STANDALONE); + foreach ($hotelProducts as $hotelProduct) { + $orderHotelServiceProducts[] = array_merge($product, $hotelProduct); + } + } + if ($product['selling_preference_type'] == Product::SELLING_PREFERENCE_STANDALONE) { + $standaloneProducts = $objServiceProductOrderDetail->getServiceProductsInOrder($order->id, $product['id_order_detail'], $product['product_id'], Product::SELLING_PREFERENCE_STANDALONE); + foreach ($standaloneProducts as $standaloneProduct) { + $orderStandaloneServiceProducts[] = array_merge($product, $standaloneProduct); } } } @@ -3698,17 +3636,9 @@ class AdminOrdersControllerCore extends AdminController // send hotel standalone and standalone products $objProduct = new Product(); - $allServiceProducts = $objProduct->getServiceProducts(null); - $hotelStandaloneProducts = array(); - $standaloneProducts = array(); - foreach ($allServiceProducts as $serviceProduct) { - if (Product::isSellableWithHotel($serviceProduct['id_product'])) { - $hotelStandaloneProducts[] = $serviceProduct; - } - if (Product::isSellableAsStandalone($serviceProduct['id_product'])) { - $standaloneProducts[] = $serviceProduct; - } - } + $hotelStandaloneProducts = $objProduct->getServiceProducts(null, Product::SELLING_PREFERENCE_HOTEL_STANDALONE); + $standaloneProducts = $objProduct->getServiceProducts(null, Product::SELLING_PREFERENCE_STANDALONE); + $this->tpl_view_vars = array( 'hotelStandaloneProducts' => $hotelStandaloneProducts, 'standaloneProducts' => $standaloneProducts, @@ -7502,12 +7432,12 @@ class AdminOrdersControllerCore extends AdminController if (Configuration::get('PS_ALLOW_ADD_ALL_SERVICES_IN_BOOKING')) { // get all services $objProduct = new Product(); - $serviceProducts = array_merge( - $objProduct->getServiceProducts(true, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE), - $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) - ); + $serviceProducts = array_values(array_filter( + $objProduct->getServiceProducts(null), + function ($serviceProduct) { + return Product::isSellableWithRoomType($serviceProduct['id_product']); + } + )); if ($serviceProducts) { foreach ($serviceProducts as $key => $servProduct) { if (!Product::isAvailableWhenOutOfStock(StockAvailable::outOfStock((int)$servProduct['id_product']))