Merge pull request #1148 from shreesh-webkul/gli-1869
Fixed: Welcome voucher is available for every customer and also for guest user
This commit is contained in:
@@ -410,6 +410,8 @@ class CartRuleCore extends ObjectModel
|
||||
}
|
||||
unset($cart_rule);
|
||||
|
||||
Hook::exec('actionCustomerCartRulesModifier', array('cart_rules' => &$result, 'id_customer' => (int)$id_customer));
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -518,6 +520,38 @@ class CartRuleCore extends ObjectModel
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* If null is provided, default validation will be processed. Useful if you want your own conditions,
|
||||
* but also want to retain functionality of the core.
|
||||
*
|
||||
* If true is provided, the validation ends here and the rule is VALID, ignoring the rest of core validation.
|
||||
*
|
||||
* If false is provided, the validation ends here and the rule is not VALID, ignoring the rest of core validation.
|
||||
* In this case, it's recommended to properly alter the isValidatedByModulesError error message so the user knows why.
|
||||
*/
|
||||
$isValidatedByModules = null;
|
||||
$isValidatedByModulesError = Tools::displayError('This voucher is not valid.');
|
||||
Hook::exec(
|
||||
'actionValidateCartRule',
|
||||
array(
|
||||
'cart_rule' => $this,
|
||||
'context' => $context,
|
||||
'alreadyInCart' => $alreadyInCart,
|
||||
'display_error' => $display_error,
|
||||
'check_carrier' => $check_carrier,
|
||||
'isValidatedByModules' => &$isValidatedByModules,
|
||||
'isValidatedByModulesError' => &$isValidatedByModulesError,
|
||||
)
|
||||
);
|
||||
|
||||
if ($isValidatedByModules === false) {
|
||||
return (!$display_error) ? false : $isValidatedByModulesError;
|
||||
}
|
||||
|
||||
if ($isValidatedByModules === true) {
|
||||
return (!$display_error) ? true : null;
|
||||
}
|
||||
|
||||
if (!$this->active) {
|
||||
return (!$display_error) ? false : Tools::displayError('This voucher is disabled');
|
||||
}
|
||||
|
||||
@@ -86,6 +86,8 @@ class Blocknewsletter extends Module
|
||||
'actionExportGDPRData',
|
||||
'actionObjectCustomerUpdateBefore',
|
||||
'actionDeleteGDPRCustomer',
|
||||
'actionCustomerCartRulesModifier',
|
||||
'actionValidateCartRule',
|
||||
'actionObjectCustomerDeleteAfter',
|
||||
)
|
||||
);
|
||||
@@ -133,6 +135,40 @@ class Blocknewsletter extends Module
|
||||
}
|
||||
}
|
||||
|
||||
public function hookActionCustomerCartRulesModifier($params)
|
||||
{
|
||||
$customer = new Customer($params['id_customer']);
|
||||
foreach($params['cart_rules'] as $key => $cartRule) {
|
||||
if ($cartRule['code'] == Configuration::get('NW_VOUCHER_CODE')) {
|
||||
if ($customer->id && !$customer->is_guest) {
|
||||
if (count(Order::getCustomerOrders($customer->id))) {
|
||||
// remove welcome voucher
|
||||
unset($params['cart_rules'][$key]);
|
||||
}
|
||||
} else {
|
||||
// remove welcome voucher
|
||||
unset($params['cart_rules'][$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function hookActionValidateCartRule($params)
|
||||
{
|
||||
$customer = new Customer($params['context']->cart->id_customer);
|
||||
if ($params['cart_rule']->code == Configuration::get('NW_VOUCHER_CODE')) {
|
||||
if ($customer->id && !$customer->is_guest) {
|
||||
if (count(Order::getCustomerOrders($customer->id))) {
|
||||
$params['isValidatedByModules'] = false;
|
||||
$params['isValidatedByModulesError'] = $this->l('This voucher is not available for this booking.');
|
||||
}
|
||||
} else {
|
||||
$params['isValidatedByModules'] = false;
|
||||
$params['isValidatedByModulesError'] = $this->l('This voucher is not available for this booking.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function install()
|
||||
{
|
||||
if (!parent::install() || !$this->registerHooks() || !$this->callInstallTab()) {
|
||||
|
||||
@@ -87,7 +87,12 @@
|
||||
<p data-html-only="1" style="border-bottom:1px solid #D6D4D4;margin:3px 0 7px;text-transform:uppercase;font-weight:500;font-size:18px;padding-bottom:10px">
|
||||
Newsletter subscription </p>
|
||||
<span style="color:#777">
|
||||
Regarding your newsletter subscription, we are pleased to offer you the following voucher: <span style="color:#333"><strong>{discount}</strong></span>
|
||||
Regarding your newsletter subscription, we are pleased to offer you the welcome voucher: <span style="color:#333"><strong>{discount}</strong></span>
|
||||
</span>
|
||||
<br>
|
||||
<br>
|
||||
<span style="color:#777">
|
||||
Please note that the voucher will be valid on your first order.
|
||||
</span>
|
||||
</font>
|
||||
</td>
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
Hi,
|
||||
|
||||
Regarding your newsletter subscription, we are pleased to offer
|
||||
you the following voucher: {discount}
|
||||
you the welcome voucher: {discount}
|
||||
|
||||
Please note that the voucher will be valid on your first order.
|
||||
|
||||
{shop_name} [/{shop_url}] powered by Webkul(tm)
|
||||
[https://webkul.com]
|
||||
|
||||
Reference in New Issue
Block a user