diff --git a/classes/CartRule.php b/classes/CartRule.php index 634434e53..24d49acd6 100644 --- a/classes/CartRule.php +++ b/classes/CartRule.php @@ -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'); } diff --git a/modules/blocknewsletter/blocknewsletter.php b/modules/blocknewsletter/blocknewsletter.php index a7a0612d6..3ece0d252 100644 --- a/modules/blocknewsletter/blocknewsletter.php +++ b/modules/blocknewsletter/blocknewsletter.php @@ -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()) {