From 67daa65ace1ba8feb3f7788115835e0a5b9158fb Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Tue, 21 Jan 2025 17:07:05 +0530 Subject: [PATCH 01/16] Added: feature to create Advanced price rules for multiple room types at once --- .../admin/AdminHotelFeaturePricesSettings.php | 230 +++++++++++++++++- .../helpers/form/form.tpl | 62 +++-- 2 files changed, 261 insertions(+), 31 deletions(-) diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php index 0652f90c7..e05c8b43f 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php @@ -189,8 +189,7 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController )) { - $this->errors[] = $this->l('An advanced price rule already exists in which some dates are common with this - plan. Please select a different date range.'); + $this->errors[] = $this->l('An advanced price rule already exists in which some dates are common with this plan. Please select a different date range.'); return ; } } @@ -202,17 +201,52 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController public function initToolbar() { parent::initToolbar(); - $this->page_header_toolbar_btn['new'] = array( - 'href' => self::$currentIndex.'&add'.$this->table.'&token='.$this->token, - 'desc' => $this->l('Add new rule'), - 'imgclass' => 'new' - ); + if (empty($this->display) || $this->display == 'list') { + $this->page_header_toolbar_btn['bulk_add'] = array( + 'href' => self::$currentIndex.'&add'.$this->table.'&bulkAdd'.$this->table.'=1&token='.$this->token, + 'desc' => $this->l('Bulk create rules'), + 'imgclass' => 'new' + ); + $this->page_header_toolbar_btn['new'] = array( + 'href' => self::$currentIndex.'&add'.$this->table.'&token='.$this->token, + 'desc' => $this->l('Add new rule'), + 'imgclass' => 'new' + ); + } + $this->toolbar_btn = array(); + } + + public function initToolbarTitle() + { + parent::initToolbarTitle(); + if (Tools::getValue('bulkAdd'.$this->table)) { + $this->toolbar_title[] = $this->l('Bulk Create', null, null, false); + $this->addMetaTitle($this->l('Bulk Create', null, null, false)); + } + } + + public function initProcess() + { + parent::initProcess(); + if (Tools::getValue('bulkAdd'.$this->table)) { + self::$currentIndex = self::$currentIndex.'&bulkAdd'.$this->table.'=1'; + } + + if (Tools::isSubmit('submitBulkAdd'.$this->table)) { + if ($this->tabAccess['add'] === '1') { + $this->action = 'bulkSave'; + $this->display = 'list'; + } else { + $this->errors[] = Tools::displayError('You do not have permission to add this.'); + } + } } public function renderList() { $this->addRowAction('edit'); $this->addRowAction('delete'); + return parent::renderList(); } @@ -246,10 +280,28 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController $smartyVars['feature_price_groups'] = $objFeaturePrice->getGroups($idFeaturePrice); } + $smartyVars['defaultcurrency_sign'] = $currencySign; $smartyVars['date_from'] = $dateFrom; $smartyVars['date_to'] = $dateTo; $smartyVars['groups'] = Group::getGroups($this->context->language->id); + $smartyVars['bulk_add'] = Tools::getValue('bulkAdd'.$this->table); + + if ($smartyVars['bulk_add']) { + $tree = new HelperTree('hotels-tree'); + $tree->setData(HotelHelper::generateTreeData([ + 'rootNode' => HotelHelper::NODE_HOTEL, + 'leafNode' => HotelHelper::NODE_ROOM_TYPE, + 'selectedElements' => array( + 'room_type' => Tools::getValue('room_type_box', array()) + ) + ])) + ->setUseCheckBox(true) + ->setAutoSelectChildren(true) + ->setUseBulkActions(true) + ->setUseSearch(true); + $smartyVars['hotel_tree'] = $tree->render(); + } $this->context->smarty->assign($smartyVars); $this->fields_form = array( 'submit' => array( @@ -374,8 +426,7 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController ); } if ($isPlanTypeExists) { - $this->errors[] = $this->l('An advanced price rule already exists in which some dates are common with this - plan. Please select a different date range.'); + $this->errors[] = $this->l('An advanced price rule already exists in which some dates are common with this plan. Please select a different date range.'); } else { if (!$roomTypeId) { $this->errors[] = $this->l('Room is not selected. Please try again.'); @@ -497,6 +548,167 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController } } + public function processBulkSave() + { + $enableFeaturePrice = Tools::getValue('enable_feature_price'); + $roomTypeIds = Tools::getValue('room_type_box'); + $dateFrom = Tools::getValue('date_from'); + $dateTo = Tools::getValue('date_to'); + $isSpecialDaysExists = Tools::getValue('is_special_days_exists'); + $specialDays = Tools::getValue('special_days'); + $priceImpactWay = Tools::getValue('price_impact_way'); + $priceImpactType = Tools::getValue('price_impact_type'); + $impactValue = Tools::getValue('impact_value'); + $dateSelectionType = Tools::getValue('date_selection_type'); + $specificDate = date('Y-m-d', strtotime(Tools::getValue('specific_date'))); + $groups = Tools::getValue('groupBox'); + $jsonSpecialDays = json_encode($specialDays); + $defaultLangId = Configuration::get('PS_LANG_DEFAULT'); + + $objFeaturePricing = new HotelRoomTypeFeaturePricing(); + + if ($priceImpactWay == HotelRoomTypeFeaturePricing::IMPACT_WAY_FIX_PRICE) { + $priceImpactType = HotelRoomTypeFeaturePricing::IMPACT_TYPE_FIXED_PRICE; + } + + $languages = Language::getLanguages(false); + $objDefaultLang = new language($defaultLangId); + $featurePricingName = array(); + + if ($dateSelectionType == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC) { + $dateFrom = $specificDate; + $dateTo = date('Y-m-d', strtotime("+1 day", strtotime($specificDate))); + } + $isPlanTypeExists = 0; + + if (empty($roomTypeIds)) { + $this->errors[] = $this->l('Please select at least one room type for bulk creation.'); + } else { + if ($isSpecialDaysExists && $jsonSpecialDays == 'false') { + $this->errors[] = $this->l('Please select at least one day for week days restriction.'); + } else { + foreach ($roomTypeIds as $roomTypeId) { + $isPlanTypeExists = $this->validateExistingFeaturePrice( + $dateSelectionType, + $roomTypeId, + $dateFrom, + $dateTo, + $groups, + 0, + $isSpecialDaysExists, + $jsonSpecialDays + ); + + if ($isPlanTypeExists) { + $objProduct = new Product((int) $roomTypeId, false, $this->context->language->id); + $this->errors[] = sprintf($this->l('An advanced price rule already exists for "%s" for the selected date range. Please select a different date range.'), $objProduct->name); + } + } + } + + if (!Tools::getValue('feature_price_name_'.$defaultLangId)) { + $this->errors[] = sprintf( + $this->l('Advanced price rule name is required at least in %s'), + $objDefaultLang->name + ); + } + + $validateRules = call_user_func( + array('HotelRoomTypeFeaturePricing', 'getValidationRules'), + 'HotelRoomTypeFeaturePricing' + ); + foreach ($languages as $language) { + if (!Validate::isCatalogName(Tools::getValue('feature_price_name_'.$language['id_lang']))) { + $this->errors[] = $this->l('Advanced price rule name is invalid in ').$language['name']; + } elseif (Tools::strlen(Tools::getValue('feature_price_name_'.$language['id_lang'])) > $validateRules['sizeLang']['feature_price_name']) { + sprintf( + $this->l('Advanced price rule Name field is too long (%2$d chars max).'), + $validateRules['sizeLang']['feature_price_name'] + ); + } + + if (Tools::getValue('feature_price_name_'.$language['id_lang'])) { + $featurePricingName[$language['id_lang']] = Tools::getValue('feature_price_name_'.$language['id_lang']); + } else { + $featurePricingName[$language['id_lang']] = Tools::getValue('feature_price_name_'.$defaultLangId); + } + } + + if ($dateSelectionType == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE) { + if ($dateFrom == '') { + $this->errors[] = $this->l('Please choose Date from for the advanced price rule.'); + } + if ($dateTo == '') { + $this->errors[] = $this->l('Please choose Date to for the advanced price rule.'); + } + $dateFrom = date('Y-m-d', strtotime($dateFrom)); + $dateTo = date('Y-m-d', strtotime($dateTo)); + if (!Validate::isDate($dateFrom)) { + $this->errors[] = $this->l('Invalid Date From.'); + } + if (!Validate::isDate($dateTo)) { + $this->errors[] = $this->l('Invalid Date To.'); + } + if ($dateTo < $dateFrom) { + $this->errors[] = $this->l('Date To must be a date after Date From.'); + } + if ($isSpecialDaysExists) { + if (!isset($specialDays) || !$specialDays) { + $this->errors[] = $this->l('Please select at least one day for week days restriction.'); + } + } + } else { + if ($specificDate == '') { + $this->errors[] = $this->l('Please choose Date from for the advanced price rule.'); + } + $specificDate = date('Y-m-d', strtotime($specificDate)); + if (!Validate::isDate($specificDate)) { + $this->errors[] = $this->l('Invalid Date From.'); + } + } + + if (!$impactValue) { + $this->errors[] = $this->l('Please enter a valid impact value.'); + } else { + if (!Validate::isPrice($impactValue)) { + $this->errors[] = $this->l('Invalid value of impact value.'); + } + } + + if (!(bool)$groups) { + $this->errors[] = $this->l('Please select at least one group for the group access'); + } + + if (empty($this->errors)) { + $res = true; + foreach ($roomTypeIds as $roomTypeId) { + $objFeaturePricing = new HotelRoomTypeFeaturePricing(); + $objFeaturePricing->id_product = $roomTypeId; + $objFeaturePricing->feature_price_name = $featurePricingName; + $objFeaturePricing->date_selection_type = $dateSelectionType; + $objFeaturePricing->date_from = $dateFrom; + $objFeaturePricing->date_to = $dateTo; + $objFeaturePricing->impact_way = $priceImpactWay; + $objFeaturePricing->is_special_days_exists = $isSpecialDaysExists; + $objFeaturePricing->special_days = $jsonSpecialDays; + $objFeaturePricing->impact_type = $priceImpactType; + $objFeaturePricing->impact_value = $impactValue; + $objFeaturePricing->active = $enableFeaturePrice; + + // set the values of the groups for this feature price + $objFeaturePricing->groupBox = $groups; + $res &= $objFeaturePricing->save(); + } + + Tools::redirectAdmin(self::$currentIndex.'&conf=4&token='.$this->token); + } + } + + if (!empty($this->errors)) { + $this->display = 'add'; + } + } + public function ajaxProcessSearchProductByName() { $productName = Tools::getValue('room_type_name'); diff --git a/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/form/form.tpl b/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/form/form.tpl index d1191997d..e40b26f10 100644 --- a/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/form/form.tpl +++ b/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/form/form.tpl @@ -19,7 +19,9 @@
- {if isset($edit)} + {if isset($bulk_add) && $bulk_add} +  {l s='Bulk Create Advanced Price Rule' mod='hotelreservationsystem'} + {else if isset($edit)}  {l s='Edit Advanced Price Rule' mod='hotelreservationsystem'} {else}  {l s='Add New Advanced Price Rule' mod='hotelreservationsystem'} @@ -57,23 +59,33 @@ {/if}
-
- -
- - - - -
- {l s='Enter room type name and select the room for which you are going to create this advanced price rule.' mod='hotelreservationsystem'} + {if isset($bulk_add) && $bulk_add} +
+ +
+ {$hotel_tree}
- -
+ {else} +
+ +
+ + + + +
+ {l s='Enter room type name and select the room for which you are going to create this advanced price rule.' mod='hotelreservationsystem'} +
+
+
+ {/if}
From 7340afe6cee239b1f2d7cfccdb5e183ee34b11e5 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Wed, 5 Feb 2025 19:21:43 +0530 Subject: [PATCH 02/16] Optimized: the room search flow, and validation process before process save --- .../admin/AdminHotelFeaturePricesSettings.php | 366 +++++++++--------- .../helpers/form/form.tpl | 6 +- 2 files changed, 185 insertions(+), 187 deletions(-) diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php index e05c8b43f..7cd48a1ee 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php @@ -203,7 +203,7 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController parent::initToolbar(); if (empty($this->display) || $this->display == 'list') { $this->page_header_toolbar_btn['bulk_add'] = array( - 'href' => self::$currentIndex.'&add'.$this->table.'&bulkAdd'.$this->table.'=1&token='.$this->token, + 'href' => self::$currentIndex.'&add'.$this->table.'&bulkAdd'.$this->table.'&token='.$this->token, 'desc' => $this->l('Bulk create rules'), 'imgclass' => 'new' ); @@ -219,7 +219,7 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController public function initToolbarTitle() { parent::initToolbarTitle(); - if (Tools::getValue('bulkAdd'.$this->table)) { + if (Tools::isSubmit('bulkAdd'.$this->table)) { $this->toolbar_title[] = $this->l('Bulk Create', null, null, false); $this->addMetaTitle($this->l('Bulk Create', null, null, false)); } @@ -228,8 +228,8 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController public function initProcess() { parent::initProcess(); - if (Tools::getValue('bulkAdd'.$this->table)) { - self::$currentIndex = self::$currentIndex.'&bulkAdd'.$this->table.'=1'; + if (Tools::isSubmit('bulkAdd'.$this->table)) { + self::$currentIndex = self::$currentIndex.'&bulkAdd'.$this->table.''; } if (Tools::isSubmit('submitBulkAdd'.$this->table)) { @@ -285,23 +285,32 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController $smartyVars['date_from'] = $dateFrom; $smartyVars['date_to'] = $dateTo; $smartyVars['groups'] = Group::getGroups($this->context->language->id); - $smartyVars['bulk_add'] = Tools::getValue('bulkAdd'.$this->table); - - if ($smartyVars['bulk_add']) { + if (Tools::isSubmit('bulkAdd'.$this->table)) { + $this->submit_action = 'submitBulkAdd'.$this->table; + $smartyVars['bulk_add'] = true; $tree = new HelperTree('hotels-tree'); - $tree->setData(HotelHelper::generateTreeData([ - 'rootNode' => HotelHelper::NODE_HOTEL, - 'leafNode' => HotelHelper::NODE_ROOM_TYPE, - 'selectedElements' => array( - 'room_type' => Tools::getValue('room_type_box', array()) - ) - ])) + if ($treeData = HotelHelper::generateTreeData([ + 'rootNode' => HotelHelper::NODE_HOTEL, + 'leafNode' => HotelHelper::NODE_ROOM_TYPE, + 'selectedElements' => array( + 'room_type' => Tools::getValue('room_type_box', array()) + ) + ])) { + foreach ($treeData as $idHotel => $data) { + if (!isset($data['children']) || empty($data['children'])) { + unset($treeData[$idHotel]); + } + } + } + + $tree->setData($treeData) ->setUseCheckBox(true) ->setAutoSelectChildren(true) ->setUseBulkActions(true) ->setUseSearch(true); $smartyVars['hotel_tree'] = $tree->render(); } + $this->context->smarty->assign($smartyVars); $this->fields_form = array( 'submit' => array( @@ -405,15 +414,84 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController $languages = Language::getLanguages(false); $objDefaultLang = new language($defaultLangId); + if (!Tools::getValue('feature_price_name_'.$defaultLangId)) { + $this->errors[] = sprintf( + $this->l('Advanced price rule name is required at least in %s'), + $objDefaultLang->name + ); + } + $validateRules = call_user_func( + array('HotelRoomTypeFeaturePricing', 'getValidationRules'), + 'HotelRoomTypeFeaturePricing' + ); + foreach ($languages as $language) { + if (!Validate::isCatalogName(Tools::getValue('feature_price_name_'.$language['id_lang']))) { + $this->errors[] = $this->l('Advanced price rule name is invalid in ').$language['name']; + } elseif (Tools::strlen(Tools::getValue('feature_price_name_'.$language['id_lang'])) > $validateRules['sizeLang']['feature_price_name']) { + sprintf( + $this->l('Advanced price rule Name field is too long (%2$d chars max).'), + $validateRules['sizeLang']['feature_price_name'] + ); + } + } + + if (!$roomTypeId) { + $this->errors[] = $this->l('Room is not selected. Please try again.'); + } + if ($dateSelectionType == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC) { $dateFrom = $specificDate; $dateTo = date('Y-m-d', strtotime("+1 day", strtotime($specificDate))); + } else if ($dateSelectionType == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE) { + if ($dateFrom == '') { + $this->errors[] = $this->l('Please choose Date from for the advanced price rule.'); + } + if ($dateTo == '') { + $this->errors[] = $this->l('Please choose Date to for the advanced price rule.'); + } + $dateFrom = date('Y-m-d', strtotime($dateFrom)); + $dateTo = date('Y-m-d', strtotime($dateTo)); + if (!Validate::isDate($dateFrom)) { + $this->errors[] = $this->l('Invalid Date From.'); + } + if (!Validate::isDate($dateTo)) { + $this->errors[] = $this->l('Invalid Date To.'); + } + if ($dateTo < $dateFrom) { + $this->errors[] = $this->l('Date To must be a date after Date From.'); + } + if ($isSpecialDaysExists) { + if (!isset($specialDays) || !$specialDays) { + $this->errors[] = $this->l('Please select at least one day for week days restriction.'); + } + } + } else { + if ($specificDate == '') { + $this->errors[] = $this->l('Please choose Date from for the advanced price rule.'); + } + $specificDate = date('Y-m-d', strtotime($specificDate)); + if (!Validate::isDate($specificDate)) { + $this->errors[] = $this->l('Invalid Date From.'); + } } + if (!$impactValue) { + $this->errors[] = $this->l('Please enter a valid impact value.'); + } else { + if (!Validate::isPrice($impactValue)) { + $this->errors[] = $this->l('Invalid value of impact value.'); + } + } + + if (!(bool)$groups) { + $this->errors[] = $this->l('Please select at least one group for the group access'); + } + + $isPlanTypeExists = 0; if ($isSpecialDaysExists && $jsonSpecialDays == 'false') { $this->errors[] = $this->l('Please select at least one day for week days restriction.'); - } else { + } else if (empty($this->errors)) { $isPlanTypeExists = $this->validateExistingFeaturePrice( $dateSelectionType, $roomTypeId, @@ -428,75 +506,6 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController if ($isPlanTypeExists) { $this->errors[] = $this->l('An advanced price rule already exists in which some dates are common with this plan. Please select a different date range.'); } else { - if (!$roomTypeId) { - $this->errors[] = $this->l('Room is not selected. Please try again.'); - } - if (!Tools::getValue('feature_price_name_'.$defaultLangId)) { - $this->errors[] = sprintf( - $this->l('Advanced price rule name is required at least in %s'), - $objDefaultLang->name - ); - } - $validateRules = call_user_func( - array('HotelRoomTypeFeaturePricing', 'getValidationRules'), - 'HotelRoomTypeFeaturePricing' - ); - foreach ($languages as $language) { - if (!Validate::isCatalogName(Tools::getValue('feature_price_name_'.$language['id_lang']))) { - $this->errors[] = $this->l('Advanced price rule name is invalid in ').$language['name']; - } elseif (Tools::strlen(Tools::getValue('feature_price_name_'.$language['id_lang'])) > $validateRules['sizeLang']['feature_price_name']) { - sprintf( - $this->l('Advanced price rule Name field is too long (%2$d chars max).'), - $validateRules['sizeLang']['feature_price_name'] - ); - } - } - - if ($dateSelectionType == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE) { - if ($dateFrom == '') { - $this->errors[] = $this->l('Please choose Date from for the advanced price rule.'); - } - if ($dateTo == '') { - $this->errors[] = $this->l('Please choose Date to for the advanced price rule.'); - } - $dateFrom = date('Y-m-d', strtotime($dateFrom)); - $dateTo = date('Y-m-d', strtotime($dateTo)); - if (!Validate::isDate($dateFrom)) { - $this->errors[] = $this->l('Invalid Date From.'); - } - if (!Validate::isDate($dateTo)) { - $this->errors[] = $this->l('Invalid Date To.'); - } - if ($dateTo < $dateFrom) { - $this->errors[] = $this->l('Date To must be a date after Date From.'); - } - if ($isSpecialDaysExists) { - if (!isset($specialDays) || !$specialDays) { - $this->errors[] = $this->l('Please select at least one day for week days restriction.'); - } - } - } else { - if ($specificDate == '') { - $this->errors[] = $this->l('Please choose Date from for the advanced price rule.'); - } - $specificDate = date('Y-m-d', strtotime($specificDate)); - if (!Validate::isDate($specificDate)) { - $this->errors[] = $this->l('Invalid Date From.'); - } - } - - if (!$impactValue) { - $this->errors[] = $this->l('Please enter a valid impact value.'); - } else { - if (!Validate::isPrice($impactValue)) { - $this->errors[] = $this->l('Invalid value of impact value.'); - } - } - - if (!(bool)$groups) { - $this->errors[] = $this->l('Please select at least one group for the group access'); - } - if (!count($this->errors)) { if ($idFeaturePrice) { $objFeaturePricing = new HotelRoomTypeFeaturePricing($idFeaturePrice); @@ -574,16 +583,85 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController $languages = Language::getLanguages(false); $objDefaultLang = new language($defaultLangId); $featurePricingName = array(); + if (!Tools::getValue('feature_price_name_'.$defaultLangId)) { + $this->errors[] = sprintf( + $this->l('Advanced price rule name is required at least in %s'), + $objDefaultLang->name + ); + } + $validateRules = call_user_func( + array('HotelRoomTypeFeaturePricing', 'getValidationRules'), + 'HotelRoomTypeFeaturePricing' + ); + foreach ($languages as $language) { + if (!Validate::isCatalogName(Tools::getValue('feature_price_name_'.$language['id_lang']))) { + $this->errors[] = $this->l('Advanced price rule name is invalid in ').$language['name']; + } elseif (Tools::strlen(Tools::getValue('feature_price_name_'.$language['id_lang'])) > $validateRules['sizeLang']['feature_price_name']) { + sprintf( + $this->l('Advanced price rule Name field is too long (%2$d chars max).'), + $validateRules['sizeLang']['feature_price_name'] + ); + } + + if (Tools::getValue('feature_price_name_'.$language['id_lang'])) { + $featurePricingName[$language['id_lang']] = Tools::getValue('feature_price_name_'.$language['id_lang']); + } else { + $featurePricingName[$language['id_lang']] = Tools::getValue('feature_price_name_'.$defaultLangId); + } + } if ($dateSelectionType == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC) { $dateFrom = $specificDate; $dateTo = date('Y-m-d', strtotime("+1 day", strtotime($specificDate))); - } - $isPlanTypeExists = 0; - - if (empty($roomTypeIds)) { - $this->errors[] = $this->l('Please select at least one room type for bulk creation.'); + } else if ($dateSelectionType == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE) { + if ($dateFrom == '') { + $this->errors[] = $this->l('Please choose Date from for the advanced price rule.'); + } + if ($dateTo == '') { + $this->errors[] = $this->l('Please choose Date to for the advanced price rule.'); + } + $dateFrom = date('Y-m-d', strtotime($dateFrom)); + $dateTo = date('Y-m-d', strtotime($dateTo)); + if (!Validate::isDate($dateFrom)) { + $this->errors[] = $this->l('Invalid Date From.'); + } + if (!Validate::isDate($dateTo)) { + $this->errors[] = $this->l('Invalid Date To.'); + } + if ($dateTo < $dateFrom) { + $this->errors[] = $this->l('Date To must be a date after Date From.'); + } + if ($isSpecialDaysExists) { + if (!isset($specialDays) || !$specialDays) { + $this->errors[] = $this->l('Please select at least one day for week days restriction.'); + } + } } else { + if ($specificDate == '') { + $this->errors[] = $this->l('Please choose Date from for the advanced price rule.'); + } + $specificDate = date('Y-m-d', strtotime($specificDate)); + if (!Validate::isDate($specificDate)) { + $this->errors[] = $this->l('Invalid Date From.'); + } + } + + if (!$impactValue) { + $this->errors[] = $this->l('Please enter a valid impact value.'); + } else { + if (!Validate::isPrice($impactValue)) { + $this->errors[] = $this->l('Invalid value of impact value.'); + } + } + + if (!(bool)$groups) { + $this->errors[] = $this->l('Please select at least one group for the group access'); + } + + $isPlanTypeExists = 0; + if (empty($roomTypeIds)) { + $this->errors[] = $this->l('Please select at least one room type for bulk creation process.'); + } else if (empty($this->errors)) { if ($isSpecialDaysExists && $jsonSpecialDays == 'false') { $this->errors[] = $this->l('Please select at least one day for week days restriction.'); } else { @@ -606,79 +684,6 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController } } - if (!Tools::getValue('feature_price_name_'.$defaultLangId)) { - $this->errors[] = sprintf( - $this->l('Advanced price rule name is required at least in %s'), - $objDefaultLang->name - ); - } - - $validateRules = call_user_func( - array('HotelRoomTypeFeaturePricing', 'getValidationRules'), - 'HotelRoomTypeFeaturePricing' - ); - foreach ($languages as $language) { - if (!Validate::isCatalogName(Tools::getValue('feature_price_name_'.$language['id_lang']))) { - $this->errors[] = $this->l('Advanced price rule name is invalid in ').$language['name']; - } elseif (Tools::strlen(Tools::getValue('feature_price_name_'.$language['id_lang'])) > $validateRules['sizeLang']['feature_price_name']) { - sprintf( - $this->l('Advanced price rule Name field is too long (%2$d chars max).'), - $validateRules['sizeLang']['feature_price_name'] - ); - } - - if (Tools::getValue('feature_price_name_'.$language['id_lang'])) { - $featurePricingName[$language['id_lang']] = Tools::getValue('feature_price_name_'.$language['id_lang']); - } else { - $featurePricingName[$language['id_lang']] = Tools::getValue('feature_price_name_'.$defaultLangId); - } - } - - if ($dateSelectionType == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE) { - if ($dateFrom == '') { - $this->errors[] = $this->l('Please choose Date from for the advanced price rule.'); - } - if ($dateTo == '') { - $this->errors[] = $this->l('Please choose Date to for the advanced price rule.'); - } - $dateFrom = date('Y-m-d', strtotime($dateFrom)); - $dateTo = date('Y-m-d', strtotime($dateTo)); - if (!Validate::isDate($dateFrom)) { - $this->errors[] = $this->l('Invalid Date From.'); - } - if (!Validate::isDate($dateTo)) { - $this->errors[] = $this->l('Invalid Date To.'); - } - if ($dateTo < $dateFrom) { - $this->errors[] = $this->l('Date To must be a date after Date From.'); - } - if ($isSpecialDaysExists) { - if (!isset($specialDays) || !$specialDays) { - $this->errors[] = $this->l('Please select at least one day for week days restriction.'); - } - } - } else { - if ($specificDate == '') { - $this->errors[] = $this->l('Please choose Date from for the advanced price rule.'); - } - $specificDate = date('Y-m-d', strtotime($specificDate)); - if (!Validate::isDate($specificDate)) { - $this->errors[] = $this->l('Invalid Date From.'); - } - } - - if (!$impactValue) { - $this->errors[] = $this->l('Please enter a valid impact value.'); - } else { - if (!Validate::isPrice($impactValue)) { - $this->errors[] = $this->l('Invalid value of impact value.'); - } - } - - if (!(bool)$groups) { - $this->errors[] = $this->l('Please select at least one group for the group access'); - } - if (empty($this->errors)) { $res = true; foreach ($roomTypeIds as $roomTypeId) { @@ -700,7 +705,7 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController $res &= $objFeaturePricing->save(); } - Tools::redirectAdmin(self::$currentIndex.'&conf=4&token='.$this->token); + Tools::redirectAdmin($this->context->link->getAdminLink('AdminHotelFeaturePricesSettings').'&conf=4&token='.$this->token); } } @@ -711,15 +716,14 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController public function ajaxProcessSearchProductByName() { - $productName = Tools::getValue('room_type_name'); - if ($productName) { - $productsByName = Product::searchByName($this->context->language->id, $productName); - // filter room types as per accessed hotels - $productsByName = HotelBranchInformation::filterDataByHotelAccess( - $productsByName, - $this->context->employee->id_profile - ); - if ($productsByName) { + $response = array('status' => 'failed'); + if ($productName = Tools::getValue('room_type_name')) { + if ($productsByName = Product::searchByName($this->context->language->id, $productName)) { + $productsByName = HotelBranchInformation::filterDataByHotelAccess( + $productsByName, + $this->context->employee->id_profile + ); + // filter room types as per accessed hotels foreach ($productsByName as &$product) { $hotelRoomType = new HotelRoomType(); $roomInfoByIdProduct = $hotelRoomType->getRoomTypeInfoByIdProduct($product['id_product']); @@ -729,22 +733,16 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController $product['name'].= ' / '.$onjBranchInfo->hotel_name; } } - echo json_encode($productsByName, true); - die; + + $response = $productsByName; } else { - die( - json_encode( - array('status' => 'failed', 'msg' => $this->l('No match found for entered room type name.')) - ) - ); + $response['msg'] = $this->l('No match found for entered room type name.'); } } else { - die( - json_encode( - array('status' => 'failed', 'msg' => $this->l('No match found for entered room type name.')) - ) - ); + $response['msg'] = $this->l('No match found for entered room type name.'); } + + $this->ajaxDie(json_encode($response)); } public function setMedia() diff --git a/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/form/form.tpl b/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/form/form.tpl index e40b26f10..a9c3c89a8 100644 --- a/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/form/form.tpl +++ b/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/form/form.tpl @@ -19,7 +19,7 @@
- {if isset($bulk_add) && $bulk_add} + {if isset($bulk_add)}  {l s='Bulk Create Advanced Price Rule' mod='hotelreservationsystem'} {else if isset($edit)}  {l s='Edit Advanced Price Rule' mod='hotelreservationsystem'} @@ -59,7 +59,7 @@ {/if}
- {if isset($bulk_add) && $bulk_add} + {if isset($bulk_add)}
-
date_selection_type) && $objFeaturePrice->date_selection_type != HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC}style="display:none;"{/if}{else}style="display:none;"{/if}> +
date_selection_type) && $objFeaturePrice->date_selection_type != HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC)}style="display:none;"{else if !isset($edit) && !isset($smarty.post.date_selection_type)}style="display:none;"{/if}> @@ -112,24 +112,24 @@
-
date_selection_type) && $objFeaturePrice->date_selection_type == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC}style="display:none;"{/if}> +
date_selection_type) && $objFeaturePrice->date_selection_type == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC) || (isset($smarty.post.date_selection_type) && $smarty.post.date_selection_type != HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE)}style="display:none;"{/if}>
- +
-
date_selection_type) && $objFeaturePrice->date_selection_type == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC}style="display:none;"{/if}> +
date_selection_type) && $objFeaturePrice->date_selection_type == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC) || (isset($smarty.post.date_selection_type) && $smarty.post.date_selection_type != HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE)}style="display:none;"{/if}>
- +
-
date_selection_type) && $objFeaturePrice->date_selection_type == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC}style="display:none;"{/if}> +
date_selection_type) && $objFeaturePrice->date_selection_type == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC) || (isset($smarty.post.date_selection_type) && $smarty.post.date_selection_type != HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE)}style="display:none;"{/if}>
is_special_days_exists) && $objFeaturePrice->is_special_days_exists)}style="display:block;"{/if}> -
{/foreach}
From abfadf76bf43138bdcbc5a4e40098c0a5e20e4f8 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Fri, 25 Apr 2025 12:58:14 +0530 Subject: [PATCH 09/16] Added max char to the hotel short description textarea --- .../controllers/admin/AdminAddHotelController.php | 1 + .../views/templates/admin/add_hotel/helpers/form/form.tpl | 1 + 2 files changed, 2 insertions(+) diff --git a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php index 09e879372..0065efa52 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php @@ -123,6 +123,7 @@ class AdminAddHotelController extends ModuleAdminController $smartyVars['currentLang'] = Language::getLanguage((int) $currentLangId); $smartyVars['defaultCurrency'] = Configuration::get('PS_CURRENCY_DEFAULT'); + $smartyVars['PS_SHORT_DESC_LIMIT'] = Configuration::get('PS_SHORT_DESC_LIMIT'); $countries = Country::getCountries($this->context->language->id, true); $smartyVars['country_var'] = $countries; diff --git a/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl b/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl index 0a70e1433..68766826c 100644 --- a/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl +++ b/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl @@ -150,6 +150,7 @@
From 58a66a441d69f9277bdcf45f2ed434c2d154fa82 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Mon, 28 Apr 2025 19:22:02 +0530 Subject: [PATCH 10/16] optimized the multiple price rules creation flow --- .../admin/AdminHotelFeaturePricesSettings.php | 392 +++++------------- .../views/js/HotelReservationAdmin.js | 22 + .../helpers/form/form.tpl | 63 ++- 3 files changed, 179 insertions(+), 298 deletions(-) diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php index a3b83fab1..d3f61a5cb 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php @@ -202,11 +202,6 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController { parent::initToolbar(); if (empty($this->display) || $this->display == 'list') { - $this->page_header_toolbar_btn['bulk_add'] = array( - 'href' => self::$currentIndex.'&bulkAdd'.$this->table.'&token='.$this->token, - 'desc' => $this->l('Bulk create rules'), - 'imgclass' => 'new' - ); $this->page_header_toolbar_btn['new'] = array( 'href' => self::$currentIndex.'&add'.$this->table.'&token='.$this->token, 'desc' => $this->l('Add new rule'), @@ -216,34 +211,6 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController $this->toolbar_btn = array(); } - public function initToolbarTitle() - { - parent::initToolbarTitle(); - if (Tools::isSubmit('bulkAdd'.$this->table)) { - $this->toolbar_title[] = $this->l('Bulk Create', null, null, false); - $this->addMetaTitle($this->l('Bulk Create', null, null, false)); - } - } - - public function initProcess() - { - parent::initProcess(); - if (Tools::isSubmit('bulkAdd'.$this->table)) { - self::$currentIndex = self::$currentIndex.'&bulkAdd'.$this->table.''; - $this->action = 'new'; - $this->display = 'add'; - } - - if (Tools::isSubmit('submitBulkAdd'.$this->table)) { - if ($this->tabAccess['add'] === '1') { - $this->action = 'bulkSave'; - $this->display = 'list'; - } else { - $this->errors[] = Tools::displayError('You do not have permission to add this.'); - } - } - } - public function renderList() { $this->addRowAction('edit'); @@ -281,15 +248,7 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController $smartyVars['edit'] = 1; $smartyVars['feature_price_groups'] = $objFeaturePrice->getGroups($idFeaturePrice); - } - - $smartyVars['defaultcurrency_sign'] = $currencySign; - $smartyVars['date_from'] = $dateFrom; - $smartyVars['date_to'] = $dateTo; - $smartyVars['groups'] = Group::getGroups($this->context->language->id); - if (Tools::isSubmit('bulkAdd'.$this->table)) { - $this->submit_action = 'submitBulkAdd'.$this->table; - $smartyVars['bulk_add'] = true; + } else { $tree = new HelperTree('hotels-tree'); if ($treeData = HotelHelper::generateTreeData([ 'rootNode' => HotelHelper::NODE_HOTEL, @@ -313,12 +272,18 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController $smartyVars['hotel_tree'] = $tree->render(); } + $smartyVars['defaultcurrency_sign'] = $currencySign; + $smartyVars['date_from'] = $dateFrom; + $smartyVars['date_to'] = $dateTo; + $smartyVars['groups'] = Group::getGroups($this->context->language->id); + $this->context->smarty->assign($smartyVars); $this->fields_form = array( 'submit' => array( 'title' => $this->l('Save'), ), ); + return parent::renderForm(); } @@ -406,38 +371,66 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController $groups = Tools::getValue('groupBox'); $jsonSpecialDays = json_encode($specialDays); $defaultLangId = Configuration::get('PS_LANG_DEFAULT'); + $createMultiple = Tools::getValue('create_multiple'); + if (!$createMultiple) { + $roomTypeIds = array($roomTypeId); + } else { + $roomTypeIds = Tools::getValue('room_type_box'); + } $objFeaturePricing = new HotelRoomTypeFeaturePricing(); - if ($priceImpactWay == HotelRoomTypeFeaturePricing::IMPACT_WAY_FIX_PRICE) { $priceImpactType = HotelRoomTypeFeaturePricing::IMPACT_TYPE_FIXED_PRICE; } $languages = Language::getLanguages(false); $objDefaultLang = new language($defaultLangId); - - if (!Tools::getValue('feature_price_name_'.$defaultLangId)) { + if (!($priceRuleNameDefault = Tools::getValue('feature_price_name_'.$defaultLangId))) { $this->errors[] = sprintf( $this->l('Advanced price rule name is required at least in %s'), $objDefaultLang->name ); + } else { + if (preg_match('{room_type_name}', $priceRuleNameDefault)) { + $priceRuleNameDefault = str_replace('{room_type_name}', '%s', $priceRuleNameDefault); + } } + $validateRules = call_user_func( array('HotelRoomTypeFeaturePricing', 'getValidationRules'), 'HotelRoomTypeFeaturePricing' ); - foreach ($languages as $language) { - if (!Validate::isCatalogName(Tools::getValue('feature_price_name_'.$language['id_lang']))) { - $this->errors[] = $this->l('Advanced price rule name is invalid in ').$language['name']; - } elseif (Tools::strlen(Tools::getValue('feature_price_name_'.$language['id_lang'])) > $validateRules['sizeLang']['feature_price_name']) { - sprintf( - $this->l('Advanced price rule Name field is too long (%2$d chars max).'), - $validateRules['sizeLang']['feature_price_name'] - ); + $featurePricingName = array(); + if ($roomTypeIds) { + foreach ($roomTypeIds as $idRoomType) { + $objProduct = new Product((int) $idRoomType); + foreach ($languages as $lang) { + $priceRuleName = Tools::getValue('feature_price_name_'.$lang['id_lang']); + if ($priceRuleName) { + if (preg_match('{room_type_name}', $priceRuleName)) { + $priceRuleName = str_replace('{room_type_name}', $objProduct->name[$lang['id_lang']], $priceRuleName); + } + } + + if (!Validate::isCatalogName($priceRuleName)) { + $this->errors[] = $this->l('Advanced price rule name is invalid in ').$lang['name']; + } elseif (Tools::strlen($priceRuleName) > $validateRules['sizeLang']['feature_price_name']) { + $this->errors[] = sprintf( + $this->l('Advanced price rule Name field is too long (%d chars max).'), + $validateRules['sizeLang']['feature_price_name'] + ); + } + + if ($priceRuleName) { + $featurePricingName[$idRoomType][$lang['id_lang']] = $priceRuleName; + } else { + $featurePricingName[$idRoomType][$lang['id_lang']] = $priceRuleNameDefault; + } + } } } - if (!$roomTypeId) { + if (!$roomTypeId && !$createMultiple) { $this->errors[] = $this->l('Room is not selected. Please try again.'); } @@ -460,7 +453,7 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController $this->errors[] = $this->l('Invalid Date To.'); } if ($dateTo < $dateFrom) { - $this->errors[] = $this->l('Date To must be a date after Date From.'); + $this->errors[] = $this->l('Date To cannot be smaller than Date From.'); } if ($isSpecialDaysExists) { if (!isset($specialDays) || !$specialDays) { @@ -479,81 +472,87 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController if (!$impactValue) { $this->errors[] = $this->l('Please enter a valid impact value.'); - } else { - if (!Validate::isPrice($impactValue)) { - $this->errors[] = $this->l('Invalid value of impact value.'); - } else if ($priceImpactType == HotelRoomTypeFeaturePricing::IMPACT_TYPE_PERCENTAGE - && $impactValue > 100 // check if percentage added is greater then 100 - ) { - $this->errors[] = $this->l('Invalid value of impact value.'); - } + } else if (!Validate::isPrice($impactValue)) { + $this->errors[] = $this->l('Invalid value of impact value.'); + } else if ($priceImpactType == HotelRoomTypeFeaturePricing::IMPACT_TYPE_PERCENTAGE + && $impactValue > 100 // check if percentage added is greater then 100 + ) { + $this->errors[] = $this->l('Invalid value of impact value.'); } if (!(bool)$groups) { $this->errors[] = $this->l('Please select at least one group for the group access'); } - $isPlanTypeExists = 0; if ($isSpecialDaysExists && $jsonSpecialDays == 'false') { $this->errors[] = $this->l('Please select at least one day for week days restriction.'); - } else if (empty($this->errors)) { - $isPlanTypeExists = $this->validateExistingFeaturePrice( - $dateSelectionType, - $roomTypeId, - $dateFrom, - $dateTo, - $groups, - $idFeaturePrice, - $isSpecialDaysExists, - $jsonSpecialDays - ); } - if ($isPlanTypeExists) { - $this->errors[] = $this->l('An advanced price rule already exists in which some dates are common with this plan. Please select a different date range.'); - } else { - if (!count($this->errors)) { - if ($idFeaturePrice) { - $objFeaturePricing = new HotelRoomTypeFeaturePricing($idFeaturePrice); - } - $objFeaturePricing->id_product = $roomTypeId; - // lang fields - foreach ($languages as $language) { - if (Tools::getValue('feature_price_name_'.$language['id_lang'])) { - $objFeaturePricing->feature_price_name[$language['id_lang']] = Tools::getValue( - 'feature_price_name_'.$language['id_lang'] - ); - } else { - $objFeaturePricing->feature_price_name[$language['id_lang']] = Tools::getValue( - 'feature_price_name_'.$defaultLangId - ); - } - } - $objFeaturePricing->date_selection_type = $dateSelectionType; - $objFeaturePricing->date_from = $dateFrom; - $objFeaturePricing->date_to = $dateTo; - $objFeaturePricing->impact_way = $priceImpactWay; - $objFeaturePricing->is_special_days_exists = $isSpecialDaysExists; - $objFeaturePricing->special_days = $jsonSpecialDays; - $objFeaturePricing->impact_type = $priceImpactType; - $objFeaturePricing->impact_value = $impactValue; - $objFeaturePricing->active = $enableFeaturePrice; - // set the values of the groups for this feature price - $objFeaturePricing->groupBox = $groups; + if ($createMultiple && empty($roomTypeIds)) { + $this->errors[] = $this->l('Please select at least one room type for creating multiple price rules.'); + } else if (empty($this->errors)) { + foreach ($roomTypeIds as $idRoomType) { + $isPlanTypeExists = $this->validateExistingFeaturePrice( + $dateSelectionType, + $idRoomType, + $dateFrom, + $dateTo, + $groups, + $idFeaturePrice, + $isSpecialDaysExists, + $jsonSpecialDays + ); - if ($objFeaturePricing->save()) { - if (Tools::isSubmit('submitAdd'.$this->table.'AndStay')) { - Tools::redirectAdmin( - self::$currentIndex.'&id_feature_price='.(int) $objFeaturePricing->id. - '&update'.$this->table.'&conf=4&token='.$this->token - ); - } else { - Tools::redirectAdmin(self::$currentIndex.'&conf=4&token='.$this->token); - } + if ($isPlanTypeExists) { + $objProduct = new Product((int) $idRoomType, false, $this->context->language->id); + $this->errors[] = sprintf($this->l('An advanced price rule already exists for "%s" for the selected date range. Please select a different date range.'), $objProduct->name); + } + } + } + + if (!$isPlanTypeExists && !count($this->errors)) { + if ($idFeaturePrice) { + $objFeaturePricing = new HotelRoomTypeFeaturePricing($idFeaturePrice); + } + + // lang fields + $objFeaturePricing->date_selection_type = $dateSelectionType; + $objFeaturePricing->date_from = $dateFrom; + $objFeaturePricing->date_to = $dateTo; + $objFeaturePricing->impact_way = $priceImpactWay; + $objFeaturePricing->is_special_days_exists = $isSpecialDaysExists; + $objFeaturePricing->special_days = $jsonSpecialDays; + $objFeaturePricing->impact_type = $priceImpactType; + $objFeaturePricing->impact_value = $impactValue; + $objFeaturePricing->active = $enableFeaturePrice; + + // set the values of the groups for this feature price + $objFeaturePricing->groupBox = $groups; + $objFeaturePricing->id_product = $roomTypeId; + if ($createMultiple) { + foreach ($roomTypeIds as $idRoomType) { + $objFeaturePricing->id_product = $idRoomType; + $objFeaturePricing->feature_price_name = $featurePricingName[$idRoomType]; + $objFeaturePricing->add(); + } + + Tools::redirectAdmin(self::$currentIndex.'&conf=3&token='.$this->token); + } else { + $objFeaturePricing->feature_price_name = $featurePricingName[$roomTypeId]; + } + + if ($objFeaturePricing->save()) { + if (Tools::isSubmit('submitAdd'.$this->table.'AndStay')) { + Tools::redirectAdmin( + self::$currentIndex.'&id_feature_price='.(int) $objFeaturePricing->id. + '&update'.$this->table.'&conf=4&token='.$this->token + ); } else { - $this->errors[] = $this->l('Some error occured while saving advanced price rule.'); + Tools::redirectAdmin(self::$currentIndex.'&conf=4&token='.$this->token); } + } else { + $this->errors[] = $this->l('Some error occured while saving advanced price rule.'); } } if (isset($idFeaturePrice) && $idFeaturePrice) { @@ -563,167 +562,6 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController } } - public function processBulkSave() - { - $enableFeaturePrice = Tools::getValue('enable_feature_price'); - $roomTypeIds = Tools::getValue('room_type_box'); - $dateFrom = Tools::getValue('date_from'); - $dateTo = Tools::getValue('date_to'); - $isSpecialDaysExists = Tools::getValue('is_special_days_exists'); - $specialDays = Tools::getValue('special_days'); - $priceImpactWay = Tools::getValue('price_impact_way'); - $priceImpactType = Tools::getValue('price_impact_type'); - $impactValue = Tools::getValue('impact_value'); - $dateSelectionType = Tools::getValue('date_selection_type'); - $specificDate = date('Y-m-d', strtotime(Tools::getValue('specific_date'))); - $groups = Tools::getValue('groupBox'); - $jsonSpecialDays = json_encode($specialDays); - $defaultLangId = Configuration::get('PS_LANG_DEFAULT'); - - $objFeaturePricing = new HotelRoomTypeFeaturePricing(); - - if ($priceImpactWay == HotelRoomTypeFeaturePricing::IMPACT_WAY_FIX_PRICE) { - $priceImpactType = HotelRoomTypeFeaturePricing::IMPACT_TYPE_FIXED_PRICE; - } - - $languages = Language::getLanguages(false); - $objDefaultLang = new language($defaultLangId); - $featurePricingName = array(); - if (!Tools::getValue('feature_price_name_'.$defaultLangId)) { - $this->errors[] = sprintf( - $this->l('Advanced price rule name is required at least in %s'), - $objDefaultLang->name - ); - } - - $validateRules = call_user_func( - array('HotelRoomTypeFeaturePricing', 'getValidationRules'), - 'HotelRoomTypeFeaturePricing' - ); - foreach ($languages as $language) { - if (!Validate::isCatalogName(Tools::getValue('feature_price_name_'.$language['id_lang']))) { - $this->errors[] = $this->l('Advanced price rule name is invalid in ').$language['name']; - } elseif (Tools::strlen(Tools::getValue('feature_price_name_'.$language['id_lang'])) > $validateRules['sizeLang']['feature_price_name']) { - sprintf( - $this->l('Advanced price rule Name field is too long (%2$d chars max).'), - $validateRules['sizeLang']['feature_price_name'] - ); - } - - if (Tools::getValue('feature_price_name_'.$language['id_lang'])) { - $featurePricingName[$language['id_lang']] = Tools::getValue('feature_price_name_'.$language['id_lang']); - } else { - $featurePricingName[$language['id_lang']] = Tools::getValue('feature_price_name_'.$defaultLangId); - } - } - if ($dateSelectionType == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC) { - $dateFrom = $specificDate; - $dateTo = date('Y-m-d', strtotime("+1 day", strtotime($specificDate))); - } else if ($dateSelectionType == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE) { - if ($dateFrom == '') { - $this->errors[] = $this->l('Please choose Date from for the advanced price rule.'); - } - if ($dateTo == '') { - $this->errors[] = $this->l('Please choose Date to for the advanced price rule.'); - } - $dateFrom = date('Y-m-d', strtotime($dateFrom)); - $dateTo = date('Y-m-d', strtotime($dateTo)); - if (!Validate::isDate($dateFrom)) { - $this->errors[] = $this->l('Invalid Date From.'); - } - if (!Validate::isDate($dateTo)) { - $this->errors[] = $this->l('Invalid Date To.'); - } - if ($dateTo < $dateFrom) { - $this->errors[] = $this->l('Date To must be a date after Date From.'); - } - if ($isSpecialDaysExists) { - if (!isset($specialDays) || !$specialDays) { - $this->errors[] = $this->l('Please select at least one day for week days restriction.'); - } - } - } else { - if ($specificDate == '') { - $this->errors[] = $this->l('Please choose Date from for the advanced price rule.'); - } - $specificDate = date('Y-m-d', strtotime($specificDate)); - if (!Validate::isDate($specificDate)) { - $this->errors[] = $this->l('Invalid Date From.'); - } - } - - if (!$impactValue) { - $this->errors[] = $this->l('Please enter a valid impact value.'); - } else { - if (!Validate::isPrice($impactValue)) { - $this->errors[] = $this->l('Invalid value of impact value.'); - } else if ($priceImpactType == HotelRoomTypeFeaturePricing::IMPACT_TYPE_PERCENTAGE - && $impactValue > 100 // check if percentage added is greater then 100 - ) { - $this->errors[] = $this->l('Invalid value of impact value.'); - } - } - - if (!(bool)$groups) { - $this->errors[] = $this->l('Please select at least one group for the group access'); - } - - $isPlanTypeExists = 0; - if (empty($roomTypeIds)) { - $this->errors[] = $this->l('Please select at least one room type for bulk creation process.'); - } else if (empty($this->errors)) { - if ($isSpecialDaysExists && $jsonSpecialDays == 'false') { - $this->errors[] = $this->l('Please select at least one day for week days restriction.'); - } else { - foreach ($roomTypeIds as $roomTypeId) { - $isPlanTypeExists = $this->validateExistingFeaturePrice( - $dateSelectionType, - $roomTypeId, - $dateFrom, - $dateTo, - $groups, - 0, - $isSpecialDaysExists, - $jsonSpecialDays - ); - - if ($isPlanTypeExists) { - $objProduct = new Product((int) $roomTypeId, false, $this->context->language->id); - $this->errors[] = sprintf($this->l('An advanced price rule already exists for "%s" for the selected date range. Please select a different date range.'), $objProduct->name); - } - } - } - - if (empty($this->errors)) { - $res = true; - foreach ($roomTypeIds as $roomTypeId) { - $objFeaturePricing = new HotelRoomTypeFeaturePricing(); - $objFeaturePricing->id_product = $roomTypeId; - $objFeaturePricing->feature_price_name = $featurePricingName; - $objFeaturePricing->date_selection_type = $dateSelectionType; - $objFeaturePricing->date_from = $dateFrom; - $objFeaturePricing->date_to = $dateTo; - $objFeaturePricing->impact_way = $priceImpactWay; - $objFeaturePricing->is_special_days_exists = $isSpecialDaysExists; - $objFeaturePricing->special_days = $jsonSpecialDays; - $objFeaturePricing->impact_type = $priceImpactType; - $objFeaturePricing->impact_value = $impactValue; - $objFeaturePricing->active = $enableFeaturePrice; - - // set the values of the groups for this feature price - $objFeaturePricing->groupBox = $groups; - $res &= $objFeaturePricing->save(); - } - - Tools::redirectAdmin($this->context->link->getAdminLink('AdminHotelFeaturePricesSettings').'&conf=4&token='.$this->token); - } - } - - if (!empty($this->errors)) { - $this->display = 'add'; - } - } - public function ajaxProcessSearchProductByName() { $response = array('status' => 'failed'); diff --git a/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js b/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js index 1e3bc80b5..802a4d99c 100644 --- a/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js +++ b/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js @@ -569,6 +569,28 @@ $(document).ready(function() { /* ---- AdminHotelFeaturePricesSettingsController Admin ---- */ + if ($('input[name="create_multiple"]:checked').val() == 1) { + $('.room-type-name').hide(); + $('.room-type-name-tree').show(); + $('[name="submitAddhtl_room_type_feature_pricingAndStay"]').hide(); + } else { + $('.room-type-name').show(); + $('[name="submitAddhtl_room_type_feature_pricingAndStay"]').show(); + $('.room-type-name-tree').hide(); + } + + $(document).on('change', 'input[name="create_multiple"]', function() { + if ($('input[name="create_multiple"]:checked').val() == 1) { + $('.room-type-name').hide(); + $('.room-type-name-tree').show(); + $('[name="submitAddhtl_room_type_feature_pricingAndStay"]').hide(); + } else { + $('.room-type-name').show(); + $('[name="submitAddhtl_room_type_feature_pricingAndStay"]').show(); + $('.room-type-name-tree').hide(); + } + }); + $('#date_selection_type').on('change', function() { if ($('#date_selection_type').val() == date_selection_types.specific) { $(".specific_date_type").show(200); diff --git a/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/form/form.tpl b/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/form/form.tpl index ca2d0340e..ac5bac0b4 100644 --- a/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/form/form.tpl +++ b/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/form/form.tpl @@ -57,36 +57,57 @@
{/if} +
+ {l s='Use {room_type_name} to generate dynamic feature price names.' mod='hotelreservationsystem'} +
- {if isset($bulk_add)} -
-