Merge pull request #925 from shreesh-webkul/gli-1754
Fixed: Multiple Advance Price Rule can be created with same conditions
This commit is contained in:
@@ -189,13 +189,13 @@ class HotelRoomTypeFeaturePricing extends ObjectModel
|
||||
if ($type == 'specific_date') {
|
||||
return Db::getInstance()->getRow(
|
||||
'SELECT * FROM `'._DB_PREFIX_.'htl_room_type_feature_pricing`
|
||||
WHERE `id_product`='.(int) $id_product.'
|
||||
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
|
||||
);
|
||||
} elseif ($type == 'special_day') {
|
||||
$featurePrice = Db::getInstance()->getRow(
|
||||
$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
|
||||
@@ -203,19 +203,21 @@ class HotelRoomTypeFeaturePricing extends ObjectModel
|
||||
AND `date_to` > \''.pSQL($date_from).'\'
|
||||
AND `id_feature_price`!='.(int) $id_feature_price
|
||||
);
|
||||
if ($featurePrice) {
|
||||
$specialDays = json_decode($featurePrice['special_days']);
|
||||
$currentSpecialDays = json_decode($current_Special_days);
|
||||
$commonValues = array_intersect($specialDays, $currentSpecialDays);
|
||||
if ($commonValues) {
|
||||
return $featurePrice;
|
||||
if ($featurePrices) {
|
||||
foreach ($featurePrices as $featurePrice) {
|
||||
$specialDays = json_decode($featurePrice['special_days']);
|
||||
$currentSpecialDays = json_decode($current_Special_days);
|
||||
$commonValues = array_intersect($specialDays, $currentSpecialDays);
|
||||
if ($commonValues) {
|
||||
return $featurePrice;
|
||||
}
|
||||
}
|
||||
}
|
||||
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.'
|
||||
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).'\'
|
||||
|
||||
@@ -173,6 +173,31 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController
|
||||
return $this->context->smarty->fetch(_PS_MODULE_DIR_.$tpl_path);
|
||||
}
|
||||
|
||||
public function processStatus()
|
||||
{
|
||||
$objFeaturePricing = $this->loadObject();
|
||||
if (!$objFeaturePricing->active) {
|
||||
if ($this->validateExistingFeaturePrice(
|
||||
$objFeaturePricing->date_selection_type,
|
||||
$objFeaturePricing->id_product,
|
||||
$objFeaturePricing->date_from,
|
||||
$objFeaturePricing->date_to,
|
||||
$objFeaturePricing->id,
|
||||
$objFeaturePricing->is_special_days_exists,
|
||||
$objFeaturePricing->special_days
|
||||
|
||||
|
||||
)) {
|
||||
$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 ;
|
||||
}
|
||||
}
|
||||
|
||||
return parent::processStatus();
|
||||
|
||||
}
|
||||
|
||||
public function initToolbar()
|
||||
{
|
||||
parent::initToolbar();
|
||||
@@ -253,6 +278,46 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController
|
||||
}
|
||||
}
|
||||
|
||||
public function validateExistingFeaturePrice(
|
||||
$dateSelectionType,
|
||||
$roomTypeId,
|
||||
$dateFrom,
|
||||
$dateTo,
|
||||
$idFeaturePrice,
|
||||
$isSpecialDaysExists = false,
|
||||
$jsonSpecialDays = "false"
|
||||
) {
|
||||
$objFeaturePricing = new HotelRoomTypeFeaturePricing();
|
||||
if ($dateSelectionType == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC) {
|
||||
return $objFeaturePricing->checkRoomTypeFeaturePriceExistance(
|
||||
$roomTypeId,
|
||||
$dateFrom,
|
||||
$dateTo,
|
||||
'specific_date',
|
||||
false,
|
||||
$idFeaturePrice
|
||||
);
|
||||
} elseif (isset($isSpecialDaysExists) && $isSpecialDaysExists && $jsonSpecialDays != "false") {
|
||||
return $objFeaturePricing->checkRoomTypeFeaturePriceExistance(
|
||||
$roomTypeId,
|
||||
$dateFrom,
|
||||
$dateTo,
|
||||
'special_day',
|
||||
$jsonSpecialDays,
|
||||
$idFeaturePrice
|
||||
);
|
||||
} else {
|
||||
return $objFeaturePricing->checkRoomTypeFeaturePriceExistance(
|
||||
$roomTypeId,
|
||||
$dateFrom,
|
||||
$dateTo,
|
||||
'date_range',
|
||||
false,
|
||||
$idFeaturePrice
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function processSave()
|
||||
{
|
||||
$idFeaturePrice = Tools::getValue('id_feature_price');
|
||||
@@ -281,40 +346,26 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController
|
||||
|
||||
$languages = Language::getLanguages(false);
|
||||
$objDefaultLang = new language($defaultLangId);
|
||||
$isPlanTypeExists = 0;
|
||||
|
||||
if ($dateSelectionType == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC) {
|
||||
$isPlanTypeExists = $objFeaturePricing->checkRoomTypeFeaturePriceExistance(
|
||||
$roomTypeId,
|
||||
$specificDate,
|
||||
date('Y-m-d', strtotime("+1 day", strtotime($specificDate))),
|
||||
'specific_date',
|
||||
false,
|
||||
$idFeaturePrice
|
||||
);
|
||||
} elseif (isset($isSpecialDaysExists) && $isSpecialDaysExists == 'on') {
|
||||
if ($jsonSpecialDays != "false") {
|
||||
$isPlanTypeExists = $objFeaturePricing->checkRoomTypeFeaturePriceExistance(
|
||||
$roomTypeId,
|
||||
$dateFrom,
|
||||
$dateTo,
|
||||
'special_day',
|
||||
$jsonSpecialDays,
|
||||
$idFeaturePrice
|
||||
);
|
||||
} else {
|
||||
$this->errors[] = $this->l('Please select at least one day for the special day selection.');
|
||||
}
|
||||
$dateFrom = $specificDate;
|
||||
$dateTo = date('Y-m-d', strtotime("+1 day", strtotime($specificDate)));
|
||||
}
|
||||
|
||||
$isPlanTypeExists = 0;
|
||||
if (isset($isSpecialDaysExists) && $isSpecialDaysExists == 'on' && $jsonSpecialDays == "false") {
|
||||
$this->errors[] = $this->l('Please select at least one day for the special day selection.');
|
||||
} else {
|
||||
$isPlanTypeExists = $objFeaturePricing->checkRoomTypeFeaturePriceExistance(
|
||||
$isPlanTypeExists = $this->validateExistingFeaturePrice(
|
||||
$dateSelectionType,
|
||||
$roomTypeId,
|
||||
$dateFrom,
|
||||
$dateTo,
|
||||
'date_range',
|
||||
false,
|
||||
$idFeaturePrice
|
||||
$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.');
|
||||
@@ -410,14 +461,8 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController
|
||||
}
|
||||
}
|
||||
$objFeaturePricing->date_selection_type = $dateSelectionType;
|
||||
|
||||
if ($dateSelectionType == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE) {
|
||||
$objFeaturePricing->date_from = $dateFrom;
|
||||
$objFeaturePricing->date_to = $dateTo;
|
||||
} else {
|
||||
$objFeaturePricing->date_from = $specificDate;
|
||||
$objFeaturePricing->date_to = date('Y-m-d', strtotime($specificDate) + 86400);
|
||||
}
|
||||
$objFeaturePricing->date_from = $dateFrom;
|
||||
$objFeaturePricing->date_to = $dateTo;
|
||||
$objFeaturePricing->impact_way = $priceImpactWay;
|
||||
$objFeaturePricing->is_special_days_exists = $isSpecialDaysExists;
|
||||
$objFeaturePricing->special_days = $jsonSpecialDays;
|
||||
|
||||
Reference in New Issue
Block a user