Coupon Code Should Apply Once Order is Canceled in Magento 1.9

couponmagento-1.9orders

If we applied coupon code and completed order.

Once we cancel the order, then coupon code should become applicable again, but it can't be used anymore. Please help me, it's strange default Magento behavior.

Please help me soon.

Best Answer

This is default Magento behaviour - if the payment fails / the order is canceled before it, then the coupon code will not be free to be reused.

There're few modules that change this behaviour. Quick googling gave me f/e:

http://magetechno.com/cancel-order-coupon-code-reuse.html

Here's description for the situation: http://magebase.com/magento-tutorials/quick-fix-coupon-codes-used-up-on-incomplete-transactions/

To avoid link being removed and for future reference I'm copy-pastying the contents of that post: (all credits go to MageBase.com for this solution, it's untested but from the looks of it - should do it's job):

app/code/local/Orchid/CouponFix/Model/Observer.php

<?php
class Orchid_CouponFix_Model_Observer
{
    public function cancel($observer)
    {
    $event = $observer->getEvent();
        $order = $event->getPayment()->getOrder();
        if ($order->canCancel()) {
        if ($code = $order->getCouponCode()) {
            $coupon = Mage::getModel('salesrule/rule')->load($code, 'coupon_code');
            $coupon->setTimesUsed($coupon->getTimesUsed()-1);
            $coupon->save();
            if($customerId = $order->getCustomerId()) {
                if ($customerCoupon = Mage::getModel('salesrule/rule_customer')->loadByCustomerRule($customerId, $coupon->getId())) {
                    $customerCoupon->setTimesUsed($customerCoupon->getTimesUsed()-1);
                    $customerCoupon->save();
                }
            }
        }
    }
}

app/code/local/Orchid/CouponFix/etc/config.xml

<config>
    <modules>
            <Orchid_CouponFix>
                    <version>0.1.0</version>
            </Orchid_CouponFix>
    </modules>
    <global>
        <models>
            <couponfix>
                <class>Orchid_CouponFix_Model</class>
            </couponfix>
    </models>
    <events>
        <sales_order_payment_cancel>
        <observers>
          <orchid_couponfix_observer>
            <type>singleton</type>
            <class>Orchid_CouponFix_Model_Observer</class>
            <method>cancel</method>
          </orchid_couponfix_observer>
        </observers>
        </sales_order_payment_cancel>     
    </events>
    </global>
</config>

app/etc/modules/Orchid_CouponFix.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Orchid_CouponFix>
            <active>true</active>
            <codePool>local</codePool>
        </Orchid_CouponFix>
    </modules>
</config> 
Related Topic