From aa484cc7f44707ce4fdc5d3833474a90d33c814b Mon Sep 17 00:00:00 2001 From: amit sharma Date: Tue, 18 Aug 2026 14:55:17 +0530 Subject: [PATCH] Fix: resolve service-product selling preferences and deduplicate price calculation UI Co-authored-by: Name --- .../controllers/normal_products/prices.tpl | 22 ++---- .../_add_order_extra_services_tab_content.tpl | 28 ++------ ..._services_service_products_tab_content.tpl | 70 ++++--------------- classes/Product.php | 23 +++++- controllers/admin/AdminCartsController.php | 3 + .../admin/AdminNormalProductsController.php | 39 +++++------ controllers/admin/AdminOrdersController.php | 3 + js/admin.js | 12 ---- .../_partials/cart_booking_demands.tpl | 21 +----- .../_partials/order-extra-services.tpl | 21 +----- .../_partials/service-products-list-row.tpl | 21 +----- 11 files changed, 78 insertions(+), 185 deletions(-) diff --git a/admin/themes/default/template/controllers/normal_products/prices.tpl b/admin/themes/default/template/controllers/normal_products/prices.tpl index d3ff42375..115c78469 100644 --- a/admin/themes/default/template/controllers/normal_products/prices.tpl +++ b/admin/themes/default/template/controllers/normal_products/prices.tpl @@ -213,34 +213,24 @@ $(document).ready(function () {
-
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 44f2672ca..3d87a0286 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 @@ -68,24 +68,9 @@
    - {if $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_ON_CHECKIN_DAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_DAY_AND_CHECKOUT_DAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_DURING_STAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURING_STAY} -
  • {l s='Check-in day'}
  • - {/if} - {if $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_ON_DURING_STAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_DURING_STAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKOUT_AND_DURING_STAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURING_STAY} -
  • {l s='During-stay days'}
  • - {/if} - {if $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_ON_CHECKOUT_DAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_DAY_AND_CHECKOUT_DAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKOUT_AND_DURING_STAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURING_STAY} -
  • {l s='Check-out day'}
  • - {/if} + {foreach from=Product::getPriceCalculationMethodDaysLabel($priceCalcMethod) item='pcmDayLabel'} +
  • {$pcmDayLabel}
  • + {/foreach}
{/capture} @@ -165,22 +150,21 @@
-
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 f98d22808..aa650fca3 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 @@ -60,24 +60,9 @@
    - {if $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_ON_CHECKIN_DAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_DAY_AND_CHECKOUT_DAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_DURING_STAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURING_STAY} -
  • {l s='Check-in day'}
  • - {/if} - {if $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_ON_DURING_STAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_DURING_STAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKOUT_AND_DURING_STAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURING_STAY} -
  • {l s='During-stay days'}
  • - {/if} - {if $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_ON_CHECKOUT_DAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_DAY_AND_CHECKOUT_DAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKOUT_AND_DURING_STAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURING_STAY} -
  • {l s='Check-out day'}
  • - {/if} + {foreach from=Product::getPriceCalculationMethodDaysLabel($priceCalcMethod) item='pcmDayLabel'} +
  • {$pcmDayLabel}
  • + {/foreach}
{/capture} @@ -170,24 +155,9 @@
    - {if $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_ON_CHECKIN_DAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_DAY_AND_CHECKOUT_DAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_DURING_STAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURING_STAY} -
  • {l s='Check-in day'}
  • - {/if} - {if $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_ON_DURING_STAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_DURING_STAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKOUT_AND_DURING_STAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURING_STAY} -
  • {l s='During-stay days'}
  • - {/if} - {if $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_ON_CHECKOUT_DAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_DAY_AND_CHECKOUT_DAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKOUT_AND_DURING_STAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURING_STAY} -
  • {l s='Check-out day'}
  • - {/if} + {foreach from=Product::getPriceCalculationMethodDaysLabel($priceCalcMethod) item='pcmDayLabel'} +
  • {$pcmDayLabel}
  • + {/foreach}
{/capture} @@ -256,22 +226,21 @@
-
@@ -356,24 +325,9 @@
    - {if $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_ON_CHECKIN_DAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_DAY_AND_CHECKOUT_DAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_DURING_STAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURING_STAY} -
  • {l s='Check-in day'}
  • - {/if} - {if $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_ON_DURING_STAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_DURING_STAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKOUT_AND_DURING_STAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURING_STAY} -
  • {l s='During-stay days'}
  • - {/if} - {if $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_ON_CHECKOUT_DAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_DAY_AND_CHECKOUT_DAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKOUT_AND_DURING_STAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURING_STAY} -
  • {l s='Check-out day'}
  • - {/if} + {foreach from=Product::getPriceCalculationMethodDaysLabel($priceCalcMethod) item='pcmDayLabel'} +
  • {$pcmDayLabel}
  • + {/foreach}
{/capture} diff --git a/classes/Product.php b/classes/Product.php index b72de541a..ddc01e52d 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -6931,7 +6931,28 @@ class ProductCore extends ObjectModel return $numNights; } } - + + public static function getPriceCalculationMethodDaysLabel($priceCalculationMethod) + { + $priceCalculationMethod = (int) $priceCalculationMethod; + $labels = array(); + static $module = null; + if (is_null($module)) { + $module = Module::getInstanceByName('hotelreservationsystem'); + } + if ($priceCalculationMethod & self::PRICE_CALCULATION_METHOD_ON_CHECKIN_DAY) { + $labels[] = $module->l('Check-in day'); + } + if ($priceCalculationMethod & self::PRICE_CALCULATION_METHOD_ON_DURING_STAY) { + $labels[] = $module->l('During-stay days'); + } + if ($priceCalculationMethod & self::PRICE_CALCULATION_METHOD_ON_CHECKOUT_DAY) { + $labels[] = $module->l('Check-out day'); + } + + return $labels; + } + public static function isSellableWithRoomType($idProduct) { return in_array((int) self::getSellingPreferenceType($idProduct), [ diff --git a/controllers/admin/AdminCartsController.php b/controllers/admin/AdminCartsController.php index 456976c9f..3e689f2d6 100644 --- a/controllers/admin/AdminCartsController.php +++ b/controllers/admin/AdminCartsController.php @@ -1399,6 +1399,9 @@ class AdminCartsControllerCore extends AdminController $name = trim(Tools::getValue('new_service_name')); $price = Tools::getValue('new_service_price'); $priceCalcMethod = Tools::getValue('new_service_price_calc_method'); + if (is_array($priceCalcMethod)) { + $priceCalcMethod = array_sum(array_map('intval', $priceCalcMethod)); + } $priceAdditionType = Tools::getValue('new_service_price_addition_type'); $productQty = Tools::getValue('new_service_qty'); $idTaxRuleGroup = Tools::getValue('new_service_price_tax_rule_group'); diff --git a/controllers/admin/AdminNormalProductsController.php b/controllers/admin/AdminNormalProductsController.php index c3486efe4..be9f8adb7 100644 --- a/controllers/admin/AdminNormalProductsController.php +++ b/controllers/admin/AdminNormalProductsController.php @@ -433,32 +433,23 @@ class AdminNormalProductsControllerCore extends AdminController public function getBuyingOption($selling_preference_type, $row) { - $list = $this->fields_list['selling_preference_type']['list']; - - if (empty($list[$selling_preference_type])) { - return '--'; - } - - $options = array_map('trim', explode('|', $list[$selling_preference_type])); - - $this->context->smarty->assign(array( - 'tooltip_items' => $options, - )); - - $tooltip = $this->context->smarty->fetch('helpers/tooltip.tpl'); - - return count($options) . ' ' . $this->l('Selected') . ' ' . $tooltip; + return $this->renderMultiSelectTooltip('selling_preference_type', $selling_preference_type); } public function getPriceCalculationMethod($price_calculation_method, $row) { - $list = $this->fields_list['price_calculation_method']['list']; + return $this->renderMultiSelectTooltip('price_calculation_method', $price_calculation_method); + } - if (empty($list[$price_calculation_method])) { + private function renderMultiSelectTooltip($fieldKey, $value) + { + $list = $this->fields_list[$fieldKey]['list']; + + if (empty($list[$value])) { return '--'; } - $options = array_map('trim', explode('|', $list[$price_calculation_method])); + $options = array_map('trim', explode('|', $list[$value])); $this->context->smarty->assign(array( 'tooltip_items' => $options, @@ -531,6 +522,9 @@ class AdminNormalProductsControllerCore extends AdminController */ protected function copyFromPost(&$object, $table) { + if (is_array(Tools::getValue('price_calculation_method'))) { + $_POST['price_calculation_method'] = array_sum(array_map('intval', Tools::getValue('price_calculation_method'))); + } parent::copyFromPost($object, $table); if (get_class($object) != 'Product') { return; @@ -2229,6 +2223,10 @@ class AdminNormalProductsControllerCore extends AdminController */ public function checkProduct() { + if (is_array(Tools::getValue('price_calculation_method'))) { + $_POST['price_calculation_method'] = array_sum(array_map('intval', Tools::getValue('price_calculation_method'))); + } + $className = 'Product'; // @todo : the call_user_func seems to contains only statics values (className = 'Product') $rules = call_user_func(array($this->className, 'getValidationRules'), $this->className); @@ -2384,10 +2382,7 @@ class AdminNormalProductsControllerCore extends AdminController $this->errors[] = $this->l('Please select at least one buying option.'); } - $priceCalculationMethod = Tools::getValue('price_calculation_method'); - $id = Tools::getValue('id_'.$this->table); - - if (isset($priceCalculationMethod, $id) && empty($priceCalculationMethod) && !empty($id)) { + if (!Tools::getValue('price_calculation_method')) { $this->errors[] = $this->l('Please select at least one price calculation method.'); } diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index d06f0288f..2394d5971 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -8185,6 +8185,9 @@ class AdminOrdersControllerCore extends AdminController $name = trim(Tools::getValue('new_service_name')); $price = Tools::getValue('new_service_price'); $priceCalcMethod = Tools::getValue('new_service_price_calc_method'); + if (is_array($priceCalcMethod)) { + $priceCalcMethod = array_sum(array_map('intval', $priceCalcMethod)); + } $priceAdditionType = Tools::getValue('new_service_price_addition_type'); $productQty = Tools::getValue('new_service_qty'); $idTaxRuleGroup = Tools::getValue('new_service_price_tax_rule_group'); diff --git a/js/admin.js b/js/admin.js index 37cc6fc89..b42e2e297 100644 --- a/js/admin.js +++ b/js/admin.js @@ -1764,15 +1764,3 @@ 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/themes/hotel-reservation-theme/_partials/cart_booking_demands.tpl b/themes/hotel-reservation-theme/_partials/cart_booking_demands.tpl index a93973d7c..29c049efe 100644 --- a/themes/hotel-reservation-theme/_partials/cart_booking_demands.tpl +++ b/themes/hotel-reservation-theme/_partials/cart_booking_demands.tpl @@ -140,24 +140,9 @@

{l s='Applied on:'}

    - {if $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_ON_CHECKIN_DAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_DAY_AND_CHECKOUT_DAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_DURING_STAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURING_STAY} -
  • {l s='Check-in day'}
  • - {/if} - {if $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_ON_DURING_STAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_DURING_STAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKOUT_AND_DURING_STAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURING_STAY} -
  • {l s='During-stay days'}
  • - {/if} - {if $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_ON_CHECKOUT_DAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_DAY_AND_CHECKOUT_DAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKOUT_AND_DURING_STAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURING_STAY} -
  • {l s='Check-out day'}
  • - {/if} + {foreach from=Product::getPriceCalculationMethodDaysLabel($priceCalcMethod) item='pcmDayLabel'} +
  • {$pcmDayLabel}
  • + {/foreach}
{/capture} diff --git a/themes/hotel-reservation-theme/_partials/order-extra-services.tpl b/themes/hotel-reservation-theme/_partials/order-extra-services.tpl index f764048e7..7d9717739 100644 --- a/themes/hotel-reservation-theme/_partials/order-extra-services.tpl +++ b/themes/hotel-reservation-theme/_partials/order-extra-services.tpl @@ -63,24 +63,9 @@

{l s='Applied on:'}

    - {if $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_ON_CHECKIN_DAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_DAY_AND_CHECKOUT_DAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_DURING_STAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURING_STAY} -
  • {l s='Check-in day'}
  • - {/if} - {if $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_ON_DURING_STAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_DURING_STAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKOUT_AND_DURING_STAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURING_STAY} -
  • {l s='During-stay days'}
  • - {/if} - {if $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_ON_CHECKOUT_DAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_DAY_AND_CHECKOUT_DAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKOUT_AND_DURING_STAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURING_STAY} -
  • {l s='Check-out day'}
  • - {/if} + {foreach from=Product::getPriceCalculationMethodDaysLabel($priceCalcMethod) item='pcmDayLabel'} +
  • {$pcmDayLabel}
  • + {/foreach}
{/capture} 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 ea97398e2..1a4db4d15 100644 --- a/themes/hotel-reservation-theme/_partials/service-products-list-row.tpl +++ b/themes/hotel-reservation-theme/_partials/service-products-list-row.tpl @@ -43,24 +43,9 @@

{l s='Applied on:'}

    - {if $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_ON_CHECKIN_DAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_DAY_AND_CHECKOUT_DAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_DURING_STAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURING_STAY} -
  • {l s='Check-in day'}
  • - {/if} - {if $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_ON_DURING_STAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_DURING_STAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKOUT_AND_DURING_STAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURING_STAY} -
  • {l s='During-stay days'}
  • - {/if} - {if $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_ON_CHECKOUT_DAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_DAY_AND_CHECKOUT_DAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKOUT_AND_DURING_STAY - || $priceCalcMethod == Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURING_STAY} -
  • {l s='Check-out day'}
  • - {/if} + {foreach from=Product::getPriceCalculationMethodDaysLabel($priceCalcMethod) item='pcmDayLabel'} +
  • {$pcmDayLabel}
  • + {/foreach}
{/capture}