cancel
Showing results for 
Search instead for 
Did you mean: 

Coupon code still work after remove 1.9.3

Coupon code still work after remove 1.9.3

only is removed if i delete the cookie and still persist if I select another product with the same configuration for the code, the message when press cancel button is "coupon removed" but in the shopping cart still continue working, any ideas?

 

2 REPLIES 2

Re: Coupon code still work after remove 1.9.3

I had almost the same issue. I found a fix for my problem. The issue was with _setCartCouponCode() function in the \app\code\core\Mage\Checkout\Model\Type\Onepage.php file.In the function i replaced the line 

 if ($couponCode = $this->getCheckout()->getCartCouponCode()) { with if ($couponCode = $this->getCheckout()->getQuote()->getCartCouponCode()) {.

 

That's it. Don't know if this will work for you.

 

 

Re: Coupon code still work after remove 1.9.3

Magento sets the session when you apply the coupon, but never destroys it when the user removes/cancels it from the cart. This bug was introduced somewhere along the way in 1.9.x.

 

For now, create your own custom observer to destroy the session while watching the <controller_action_predispatch_checkout_cart_couponPost> event (replace Companyname and ModuleName in the below files with your own choice of names):

 

1.) Create Config File: app/code/local/Companyname/ModuleName/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Companyname_ModuleName>
            <version>1.0.0</version>
        </Companyname_ModuleName>
    </modules>
    <global>
        <models>
            <companyname_modulename>
                <class>Companyname_ModuleName_Model</class>
            </companyname_modulename>
        </models>
    </global>
    <frontend>
        <events>
            <controller_action_predispatch_checkout_cart_couponPost>
                <observers>
                    <remove_session_coupon_code>
                        <type>singleton</type>
                        <class>companyname_modulename/observer</class>
                        <method>removeCoupon</method>
                    </remove_session_coupon_code>
                </observers>
            </controller_action_predispatch_checkout_cart_couponPost>
        </events>
    </frontend>
</config>

 

2.) Create Observer: app/code/local/Companyname/ModuleName/Model/Observer.php

 

<?php
class Companyname_ModuleName_Model_Observer {
    public function removeCoupon(Varien_Event_Observer $observer)
    {
        $controller = $observer->getControllerAction();
        if ($controller->getRequest()->getParam('remove') == 1) {
            Mage::getSingleton("checkout/session")->unsetData('cart_coupon_code');
        }
        return $this;
    }
}


3.) Create Module Declaration File: app/etc/modules/Companyname_ModuleName.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Companyname_ModuleName>
            <codePool>local</codePool>
            <active>true</active>
        </Companyname_ModuleName>
    </modules>
</config>

 

4.) Clear Magento Cache, test, be happy.

 

Credit to ahe_borriglione [https://stackoverflow.com/a/42839424/1830601]