Merge pull request #1114 from shreesh-webkul/gli-2028

Fixed: Admin cannot create different Advance price rule for different group for same date ranges
This commit is contained in:
Rohit Jain
2024-07-11 18:20:25 +05:30
committed by GitHub
2 changed files with 37 additions and 20 deletions

View File

@@ -180,6 +180,7 @@ class HotelRoomTypeFeaturePricing extends ObjectModel
$id_product,
$date_from,
$date_to,
$groups,
$type = 'date_range',
$current_Special_days = false,
$id_feature_price = 0
@@ -188,20 +189,26 @@ class HotelRoomTypeFeaturePricing extends ObjectModel
$date_to = date('Y-m-d', strtotime($date_to));
if ($type == 'specific_date') {
return Db::getInstance()->getRow(
'SELECT * FROM `'._DB_PREFIX_.'htl_room_type_feature_pricing`
WHERE `id_product`='.(int) $id_product.' AND `active`=1
AND `date_selection_type` = '.(int) self::DATE_SELECTION_TYPE_SPECIFIC.'
AND `date_from` = \''.pSQL($date_from).'\'
AND `id_feature_price`!='.(int) $id_feature_price
'SELECT * FROM `'._DB_PREFIX_.'htl_room_type_feature_pricing` rtfp
INNER JOIN `'._DB_PREFIX_.'htl_room_type_feature_pricing_group` rtfpg
ON (rtfp.`id_feature_price` = rtfpg.`id_feature_price`)
WHERE rtfp.`id_product`='.(int) $id_product.' AND rtfp.`active`=1
AND rtfp.`date_selection_type` = '.(int) self::DATE_SELECTION_TYPE_SPECIFIC.'
AND rtfp.`date_from` = \''.pSQL($date_from).'\'
AND rtfp.`id_feature_price`!='.(int) $id_feature_price.'
AND rtfpg.`id_group` IN ('.pSQL(implode(', ',$groups)).')'
);
} elseif ($type == 'special_day') {
$featurePrices = Db::getInstance()->executeS(
'SELECT * FROM `'._DB_PREFIX_.'htl_room_type_feature_pricing`
WHERE `id_product`='.(int) $id_product.'
AND `is_special_days_exists`=1 AND `active`=1
AND `date_from` < \''.pSQL($date_to).'\'
AND `date_to` > \''.pSQL($date_from).'\'
AND `id_feature_price`!='.(int) $id_feature_price
'SELECT * FROM `'._DB_PREFIX_.'htl_room_type_feature_pricing` rtfp
INNER JOIN `'._DB_PREFIX_.'htl_room_type_feature_pricing_group` rtfpg
ON (rtfp.`id_feature_price` = rtfpg.`id_feature_price`)
WHERE rtfp.`id_product`='.(int) $id_product.'
AND rtfp.`is_special_days_exists`=1 AND `active`=1
AND rtfp.`date_from` < \''.pSQL($date_to).'\'
AND rtfp.`date_to` > \''.pSQL($date_from).'\'
AND rtfp.`id_feature_price`!='.(int) $id_feature_price.'
AND rtfpg.`id_group` IN ('.pSQL(implode(', ',$groups)).')'
);
if ($featurePrices) {
foreach ($featurePrices as $featurePrice) {
@@ -216,13 +223,16 @@ class HotelRoomTypeFeaturePricing extends ObjectModel
return false;
} elseif ($type == 'date_range') {
return Db::getInstance()->getRow(
'SELECT * FROM `'._DB_PREFIX_.'htl_room_type_feature_pricing`
WHERE `id_product`='.(int) $id_product.' AND `active`=1
AND `date_selection_type` = '.(int) self::DATE_SELECTION_TYPE_RANGE.'
AND `is_special_days_exists`=0
AND `date_from` <= \''.pSQL($date_to).'\'
AND `date_to` >= \''.pSQL($date_from).'\'
AND `id_feature_price`!='.(int) $id_feature_price
'SELECT * FROM `'._DB_PREFIX_.'htl_room_type_feature_pricing` rtfp
INNER JOIN `'._DB_PREFIX_.'htl_room_type_feature_pricing_group` rtfpg
ON (rtfp.`id_feature_price` = rtfpg.`id_feature_price`)
WHERE rtfp.`id_product`='.(int) $id_product.' AND rtfp.`active`=1
AND rtfp.`date_selection_type` = '.(int) self::DATE_SELECTION_TYPE_RANGE.'
AND rtfp.`is_special_days_exists`=0
AND rtfp.`date_from` <= \''.pSQL($date_to).'\'
AND rtfp.`date_to` >= \''.pSQL($date_from).'\'
AND rtfp.`id_feature_price`!='.(int) $id_feature_price.'
AND rtfpg.`id_group` IN ('.pSQL(implode(', ',$groups)).')'
);
}
return false;

View File

@@ -182,6 +182,7 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController
$objFeaturePricing->id_product,
$objFeaturePricing->date_from,
$objFeaturePricing->date_to,
$objFeaturePricing->getGroups($objFeaturePricing->id),
$objFeaturePricing->id,
$objFeaturePricing->is_special_days_exists,
$objFeaturePricing->special_days
@@ -283,6 +284,7 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController
$roomTypeId,
$dateFrom,
$dateTo,
$group,
$idFeaturePrice,
$isSpecialDaysExists = false,
$jsonSpecialDays = "false"
@@ -293,6 +295,7 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController
$roomTypeId,
$dateFrom,
$dateTo,
$group,
'specific_date',
false,
$idFeaturePrice
@@ -302,6 +305,7 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController
$roomTypeId,
$dateFrom,
$dateTo,
$group,
'special_day',
$jsonSpecialDays,
$idFeaturePrice
@@ -311,6 +315,7 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController
$roomTypeId,
$dateFrom,
$dateTo,
$group,
'date_range',
false,
$idFeaturePrice
@@ -335,6 +340,7 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController
$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');
@@ -361,6 +367,7 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController
$roomTypeId,
$dateFrom,
$dateTo,
$groups,
$idFeaturePrice,
$isSpecialDaysExists,
$jsonSpecialDays
@@ -435,7 +442,7 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController
}
}
if (!(bool)Tools::getValue('groupBox')) {
if (!(bool)$groups) {
$this->errors[] = $this->l('Please select at least one group for the group access');
}
@@ -467,7 +474,7 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController
$objFeaturePricing->active = $enableFeaturePrice;
// set the values of the groups for this feature price
$objFeaturePricing->groupBox = Tools::getValue('groupBox');
$objFeaturePricing->groupBox = $groups;
if ($objFeaturePricing->save()) {
if (Tools::isSubmit('submitAdd'.$this->table.'AndStay')) {