Reputation: 23
I am using magento 1.7.0.2. For some reason, I keep getting "Coupon code "XXX" is not valid." I investigated a little bit, and found what the problem is but I don't know how to fix it.
in the file: \app\code\core\mage\checkout\controllers\cartController.php
$couponCode = (string) $this->getRequest()->getParam('coupon_code');
if ($this->getRequest()->getParam('remove') == 1) {
$couponCode = '';
}
$oldCouponCode = $this->_getQuote()->getCouponCode();
if (!strlen($couponCode) && !strlen($oldCouponCode)) {
$this->_goBack();
return;
}
try {
$this->_getQuote()->getShippingAddress()->setCollectShippingRates(true);
$this->_getQuote()->setCouponCode(strlen($couponCode) ? $couponCode : '')
->collectTotals()
->save();
if ($couponCode) {
if ($couponCode == $this->_getQuote()->getCouponCode()) {
$this->_getSession()->addSuccess(
$this->__('Coupon code "%s" was applied.',Mage::helper('core')->htmlEscape($couponCode))
);
}
else {
$this->_getSession()->addError(
$this->__('Coupon code "%s" is not valid.', Mage::helper('core')->htmlEscape($couponCode))
);
}
} else {
$this->_getSession()->addSuccess($this->__('Coupon code was canceled.'));
}
The problem is that $this->_getQuote()->getCouponCode()
comes empty. It's coming in as ''.
Edit:
A further investigation led me to the a more specific problem..
Its the ->collectTotals()->save();
that doing all the mess..
For some reason if i remove them it runs perfectly but the coupon doesn't apply.
How can this be fixed?
Upvotes: 0
Views: 7837
Reputation: 61
This is a common bug of Magento from that version while they told that this bug was fixed but it wasn't. Also at the bug tracker of Mangeto it's still showing that the issue is "In Progress" till now. Here what I have found from https://github.com/husseycoding/cartrulefix :
Shopping Cart Price Rule Fix When creating a shopping cart price rule in Magento CE 1.9 and using 'Stop Further Rules Processing', the logic has been changed since 1.8 CE and is now flawed. This flawed logic now stops rules being applied correctly with more than one product in the cart and doesn't consider 'Stop Further Rules Processing' at the item level. This means that you get incorrect discount amounts applied as per the bug report here:
http://www.magentocommerce.com/bug-tracking/issue/index/id/67
This extension corrects the flawed logic and causes 'Stop Further Rules Processing' to be considered at the item level allowing rules to be processed for all items in the cart.
Upvotes: 3