-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathObserver.php
More file actions
62 lines (57 loc) · 2.11 KB
/
Observer.php
File metadata and controls
62 lines (57 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension
* to newer versions in the future.
*
* @category Hackathon
* @package Hackathon_PromoCodeMessages
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
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')) {
return;
}
if (Mage::app()->getRequest()->getActionName() !== 'couponPost') {
return;
}
if ((int)Mage::app()->getRequest()->getParam('remove') === 1) {
return;
}
$quote = $observer->getQuote();
$couponCode = $quote->getCouponCode();
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);
}
}
}
}