I am new to Magento, but I thought I got to it until today. Here is my problem.
I am writing a new Observer to add a coupon to the cart when the page loads. The coupon code is passed to the URL, and I want the code to go through ANY working URL.
For example: http: // magento /? Coupon = MYCOUPON
I caught the "controller_front_init_routers" event to capture the coupon code.
I have an observer, but if I already have the goods in the basket and I pass the coupon code, then my basket seems empty, this is how I add the coupon:
public function applyCoupon($observer){
$coupon_code = $observer->getEvent()->getData('front')->getRequest()->getParam('coupon');
if(!empty($coupon_code)){
Mage::getSingleton('checkout/session')->setData('coupon_code', $coupon_code);
Mage::getSingleton('checkout/cart')->getQuote()->setCouponCode($coupon_code)->save();
Mage::log('Coupon Code: '. $coupon_code);
}
}
It seems that at any time I call Mage :: getSingleton ("checkout / session") -> anything () I am losing the session for the basket.
, , , .
- , , ?