Skip to content

Commit

Permalink
Merge pull request #542 from lakshya-webkul/gli-1164
Browse files Browse the repository at this point in the history
Resolved: advance price rules validation issue
  • Loading branch information
rohit053 committed Mar 23, 2023
2 parents 4c2b105 + ca527d8 commit 1966ed0
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,20 @@ public function __construct()
$this->_join .= ' LEFT JOIN `'._DB_PREFIX_.'htl_room_type_feature_pricing_lang` fpl ON (a.id_feature_price = fpl.id_feature_price AND fpl.`id_lang` = '.(int) $this->context->language->id.')';
$this->_join .= ' LEFT JOIN `'._DB_PREFIX_.'htl_room_type` hrt ON (hrt.`id_product` = a.`id_product`)';
$this->_join .= ' LEFT JOIN `'._DB_PREFIX_.'htl_branch_info_lang` hbl ON (hbl.`id` = hrt.`id_hotel` AND hbl.`id_lang`='.(int) $this->context->language->id.')';
$this->_join .= ' LEFT JOIN `'._DB_PREFIX_.'htl_room_type_feature_pricing_group` hrtfpg ON (hrtfpg.`id_feature_price` = a.`id_feature_price`)';
$this->_join .= ' LEFT JOIN `'._DB_PREFIX_.'group_lang` gl ON (gl.`id_group` = hrtfpg.`id_group` AND gl.`id_lang` = '.(int) $this->context->language->id.')';

$this->_select .= ' fpl.`feature_price_name` as ftr_price_name, CONCAT(pl.`name`, " (#", a.`id_product`, ")") as product_name, hbl.`hotel_name`, IF(a.impact_type='.(int) HotelRoomTypeFeaturePricing::IMPACT_TYPE_PERCENTAGE.', CONCAT(round(a.impact_value, 2), " ", "%"), a.impact_value) AS impact_value';
$this->_select .= ' ,IF(a.impact_type='.(int) HotelRoomTypeFeaturePricing::IMPACT_TYPE_PERCENTAGE.', \''.$this->l('Percentage').'\', \''.$this->l('Fixed Amount').'\')
AS impact_type';
AS impact_type, count(hrtfpg.`id_feature_price`) AS group_access_count, group_concat(gl.`name` separator ", ") as group_names';
$this->_select .= ', CASE
WHEN a.`impact_way` = '.(int) HotelRoomTypeFeaturePricing::IMPACT_WAY_DECREASE.' THEN \''.$this->l('Decrease').'\'
WHEN a.`impact_way` = '.(int) HotelRoomTypeFeaturePricing::IMPACT_WAY_INCREASE.' THEN \''.$this->l('Increase').'\'
WHEN a.`impact_way` = '.(int) HotelRoomTypeFeaturePricing::IMPACT_WAY_FIX_PRICE.' THEN \''.$this->l('Fix').'\'
END AS `impact_way`';

$this->_group = 'GROUP BY a.`id_feature_price`';

$this->_where = ' AND a.`id_cart` = 0 AND a.`id_guest` = 0 AND a.`id_room` = 0';

$impactWays = array(1 => $this->l('Decrease'), 2 => $this->l('Increase'), 3 => $this->l('Fix'));
Expand Down Expand Up @@ -100,6 +104,13 @@ public function __construct()
'currency' => true,
'callback' => 'setOrderCurrency',
),
'group_access_count' => array(
'align' => 'center',
'title' => $this->l('Group Access'),
'type' => 'bool',
'callback' => 'setGroupAccessLabel',
'search' => false,
),
'date_from' => array(
'title' => $this->l('Date From'),
'align' => 'center',
Expand Down Expand Up @@ -149,12 +160,19 @@ public function getRoomTypeLink($productName, $row)
}

//A callback function for setting currency sign with amount
public static function setOrderCurrency($echo, $tr)
public static function setOrderCurrency($echo, $row)
{
$currency_default = Configuration::get('PS_CURRENCY_DEFAULT');
return Tools::displayPrice($echo, (int)$currency_default);
}

public function setGroupAccessLabel($echo, $row)
{
$this->context->smarty->assign('row' ,$row);
$tpl_path = 'hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/group_access_label.tpl';
return $this->context->smarty->fetch(_PS_MODULE_DIR_.$tpl_path);
}

public function initToolbar()
{
parent::initToolbar();
Expand Down Expand Up @@ -257,6 +275,10 @@ public function processSave()

$objFeaturePricing = new HotelRoomTypeFeaturePricing();

if ($priceImpactWay == HotelRoomTypeFeaturePricing::IMPACT_WAY_FIX_PRICE) {
$priceImpactType = HotelRoomTypeFeaturePricing::IMPACT_TYPE_FIXED_PRICE;
}

$languages = Language::getLanguages(false);
$objDefaultLang = new language($defaultLangId);
$isPlanTypeExists = 0;
Expand Down Expand Up @@ -366,6 +388,9 @@ public function processSave()
}
}

if (!(bool)Tools::getValue('groupBox')) {
$this->errors[] = $this->l('Please select at least one group for the group access');
}

if (!count($this->errors)) {
if ($idFeaturePrice) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{*
* 2010-2023 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through this link for complete license : https://store.webkul.com/license.html
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to https://store.webkul.com/customisation-guidelines/ for more information.
*
* @author Webkul IN <support@webkul.com>
* @copyright 2010-2023 Webkul IN
* @license https://store.webkul.com/license.html
*}

<span title="" data-toggle="tooltip" class="label-tooltip" data-html="true"
data-original-title="{$row['group_names']}" >
{$row['group_access_count']}&nbsp;
{if $row['group_access_count'] > 1}
{l s='Groups' mod='hotelreservationsystem'}
{else}
{l s='Group' mod='hotelreservationsystem'}
{/if}
</span>
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
{l s='Increase Price' mod='hotelreservationsystem'}
</option>
<option value="{HotelRoomTypeFeaturePricing::IMPACT_WAY_FIX_PRICE}" {if isset($objFeaturePrice->impact_way) && $objFeaturePrice->impact_way == HotelRoomTypeFeaturePricing::IMPACT_WAY_FIX_PRICE}selected = "selected"{/if}>
{l s='Fix Price' mod='hotelreservationsystem'}
{l s='Fixed Price' mod='hotelreservationsystem'}
</option>
</select>
</div>
Expand All @@ -223,10 +223,9 @@
{l s='Percentage' mod='hotelreservationsystem'}
</option>
<option value="{HotelRoomTypeFeaturePricing::IMPACT_TYPE_FIXED_PRICE}" {if isset($objFeaturePrice->impact_type) && $objFeaturePrice->impact_type == HotelRoomTypeFeaturePricing::IMPACT_TYPE_FIXED_PRICE}selected = "selected"{/if}>
{l s='Fixed Price' mod='hotelreservationsystem'}
{l s='Amount' mod='hotelreservationsystem'}
</option>
</select>
<input type="hidden" id="price_impact_type_input" name="price_impact_type" value="{if isset($objFeaturePrice->impact_type)}{$objFeaturePrice->impact_type}{/if}">
</div>
</div>

Expand Down Expand Up @@ -262,8 +261,8 @@

{* select group accesses *}
<div class="form-group">
<label class="control-label col-lg-3">
<span class="label-tooltip" data-toggle="tooltip" data-html="true" data-original-title="{l s='Select all the groups that you would like to apply to this advanced price rule.' mod='hotelreservationsystem'}">{l s='Group access' mod='hotelreservationsystem'}</span>
<label class="control-label required col-lg-3">
<span class="label-tooltip required" data-toggle="tooltip" data-html="true" data-original-title="{l s='Select all the groups that you would like to apply to this advanced price rule.' mod='hotelreservationsystem'}">{l s='Group access' mod='hotelreservationsystem'}</span>
</label>
<div class="col-lg-6">
<div class="table-responsive">
Expand All @@ -279,7 +278,13 @@
{foreach $groups as $group}
<tr>
<td class="text-center">
<input type="checkbox" name="groupBox[]" value="{$group['id_group']|escape:'html':'UTF-8'}" {if isset($feature_price_groups) && $feature_price_groups && $group['id_group']|in_array:$feature_price_groups}checked{/if}/>
<input type="checkbox" name="groupBox[]" value="{$group['id_group']|escape:'html':'UTF-8'}"
{if isset($feature_price_groups) && $feature_price_groups && $group['id_group']|in_array:$feature_price_groups}
checked
{elseif empty($objFeaturePrice->id)}
checked
{/if}
/>
</td>
<td class="text-center">{$group['name']|escape:'html':'UTF-8'}</td>
</tr>
Expand Down

0 comments on commit 1966ed0

Please sign in to comment.