Fixed: Welcome voucher is available for every customer
This commit is contained in:
@@ -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');
|
||||
}
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user