Skip to content

Add early exit for "fatal" errors like wrong usergroup, not valid yet, not valid anymore, etc. #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@
{
"name": "Andreas von Studnitz",
"email": "avs@integer-net.de"
},
{
"name": "Fabian Blechschmidt",
"email": "blechschmidt@fabian-blechschmidt.de"
}
],
"require": {
"php": "^7.0",
"magento-hackathon/magento-composer-installer": "*"
},
"require-dev": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,39 @@

class Hackathon_PromoCodeMessages_Model_Observer
{

/**
* Called on sales_quote_collect_totals_after. Ensure that the action is couponPost before continuing.
*
* @param Varien_Event_Observer $observer
*/
public function validateCode(Varien_Event_Observer $observer)
{
if (Mage::getStoreConfigFlag('checkout/promocodemessages/enabled')) {
$action = Mage::app()->getRequest()->getActionName();
if (!Mage::getStoreConfigFlag('checkout/promocodemessages/enabled')) {
return;
}

if ($action == 'couponPost') {
if (Mage::app()->getRequest()->getActionName() !== 'couponPost') {
return;
}

if (Mage::app()->getRequest()->getParam('remove') == 1) {
return;
}
if ((int)Mage::app()->getRequest()->getParam('remove') === 1) {
return;
}

$quote = $observer->getQuote();
$couponCode = $quote->getCouponCode();
$quote = $observer->getQuote();
$couponCode = $quote->getCouponCode();

if (!$couponCode || $couponCode == '') {
// parent validation has failed
$couponCode = (string)Mage::app()->getRequest()->getParam('coupon_code');
Mage::getModel('hackathon_promocodemessages/validator')->validate($couponCode, $quote);
}
if (!$couponCode) {
// parent validation has failed
$couponCode = (string)Mage::app()->getRequest()->getParam('coupon_code');
try {
Mage::getModel('hackathon_promocodemessages/validator')->validate($couponCode, $quote);
} catch (Mage_Core_Exception $e) {
$msg = Mage::helper('hackathon_promocodemessages')
->__('Your coupon "%s" could not be redeemed.', $couponCode);
$msg = "<p class=\"promo_error_intro\">$msg</p>";
$msg .= $e->getMessage();
throw new Mage_Core_Exception($msg, 0, $e);
}
}
}
Expand Down
Loading