Fixed: Welcome voucher is available for every customer

This commit is contained in:
Shreesh Arora
2024-06-07 12:27:59 +05:30
parent 7e897d134e
commit ee9de469d4
2 changed files with 39 additions and 1 deletions

View File

@@ -407,6 +407,8 @@ class CartRuleCore extends ObjectModel
}
unset($cart_rule);
Hook::exec('actionCartRulesAvailable', array('result' => &$result, 'id_customer' => (int)$id_customer));
return $result;
}
@@ -685,6 +687,10 @@ class CartRuleCore extends ObjectModel
}
}
if ($errors = Hook::exec('actionCheckCartRuleValid', array('cartRule' => $this))) {
return (!$display_error) ? false : Tools::displayError($errors);
}
if (!$nb_products) {
return (!$display_error) ? false : Tools::displayError('Cart is empty');
}

View File

@@ -84,7 +84,9 @@ class Blocknewsletter extends Module
'actionCustomerAccountAdd',
'registerGDPRConsent',
'actionExportGDPRData',
'actionDeleteGDPRCustomer'
'actionDeleteGDPRCustomer',
'actionCartRulesAvailable',
'actionCheckCartRuleValid',
)
);
}
@@ -111,6 +113,36 @@ class Blocknewsletter extends Module
}
}
public function hookActionCartRulesAvailable($params)
{
foreach($params['result'] as $key => $cartRule) {
if ($cartRule['code'] == Configuration::get('NW_VOUCHER_CODE')) {
if ($params['id_customer']) {
if (count(OrderCore::getCustomerOrders($params['id_customer']))) {
// remove welcome voucher
unset($params['result'][$key]);
}
} else {
// remove welcome voucher
unset($params['result'][$key]);
}
}
}
}
public function hookActionCheckCartRuleValid($params)
{
if ($params['cartRule']->code == Configuration::get('NW_VOUCHER_CODE')) {
if ($params['id_customer']) {
if (count(OrderCore::getCustomerOrders($params['id_customer']))) {
return $this->l('This voucher is not available for this booking.');
}
} else {
return $this->l('This voucher is not available for this booking.');
}
}
}
public function install()
{
if (!parent::install() || !$this->registerHooks() || !$this->callInstallTab()) {