Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coupon is always re-added during checkout

I encountered the following bug

  1. Add a product to cart
  2. Apply a coupon code
  3. Remove coupon code
  4. Coupon code is not shown anymore / remove successful
  5. Go in checkout
  6. Continue billing and shipping step
  7. Go back in cart
  8. Coupon code of step #2 is active again
like image 579
ahe_borriglione Avatar asked Sep 19 '25 17:09

ahe_borriglione


1 Answers

It seems to be a bug in CE 1.9

There is a new session value set in Mage_Checkout_CartController::couponPostAction()

$this->_getSession()->setCartCouponCode($couponCode);

which restores the coupon code in Mage_Checkout_Model_Type_Onepage::_setCartCouponCode()

protected function _setCartCouponCode()
{
    if ($couponCode = $this->getCheckout()->getCartCouponCode()) {
        $this->getQuote()->setCouponCode($couponCode);
    }
    return $this;
}

I solved it by event/observer

    <events>
        <controller_action_predispatch_checkout_cart_couponPost>
            <observers>
                <remove_session_coupon_code>
                    <type>singleton</type>
                    <class>yourmodule/observer</class>
                    <method>removeCoupon</method>
                </remove_session_coupon_code>
            </observers>
        </controller_action_predispatch_checkout_cart_couponPost>
    </events>

and:

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;
}
like image 185
ahe_borriglione Avatar answered Sep 23 '25 13:09

ahe_borriglione