Created
May 14, 2013 21:38
-
-
Save drobinson/5579802 to your computer and use it in GitHub Desktop.
Fixes salesrule times_used data update bug introduced in Magento CE 1.8 and EE 1.13 Salesrules with zero sum discount amounts (such as salesrules created for free shipping) will not have their times_used data updated.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Index: app/code/core/Mage/SalesRule/Model/Observer.php | |
| =================================================================== | |
| --- app/code/core/Mage/SalesRule/Model/Observer.php (revision 146067) | |
| +++ app/code/core/Mage/SalesRule/Model/Observer.php (working copy) | |
| @@ -90,7 +90,6 @@ | |
| $customerId = $order->getCustomerId(); | |
| // use each rule (and apply to customer, if applicable) | |
| - if ($order->getDiscountAmount() != 0) { | |
| foreach ($ruleIds as $ruleId) { | |
| if (!$ruleId) { | |
| continue; | |
| @@ -129,7 +128,6 @@ | |
| $couponUsage->updateCustomerCouponTimesUsed($customerId, $coupon->getId()); | |
| } | |
| } | |
| - } | |
| } | |
| /** |
Author
Scenario:
A salesrule is created that requires a coupon code, and is configured to only be used once. The salesrule has either a 0% discount, or a $0 fixed amount discount, and allows for free shipping. The rule doesn't have any conditions or item conditions. A user uses the coupon and places the order.
Expected Result:
The coupon code should no longer be valid after use
Actual Result:
The coupon is still usable since the times_used attribute is not updated.
Relevant code:
~ Line 93 of class Mage_SalesRule_Model_Observer in method sales_order_afterPlace
Thanks for the insight Andrey!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The reason for this "if ..." was to properly calculate usage of coupons during multi-address checkout. Without it, the usage of a coupon with fixed discount for the whole cart will be counted not once, but equal to "number of addresses".
David, I understand the case you're trying to fix. However, it would be great, if you can write down the exact step-by-step scenario, expected and actual result - so I can provide it to our QA and devs. Also, as you have access to EE, then you can contact support to ask for a patch - this will be a fast solution for you.