Skip to content

Commit

Permalink
Prevent integrity constraint violation when order is canceled (#1473)
Browse files Browse the repository at this point in the history
  • Loading branch information
luigifab authored Feb 25, 2021
1 parent 741222f commit 7f185e5
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/code/core/Mage/SalesRule/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ public function sales_order_paymentCancel($observer)
Mage::getResourceModel('salesrule/coupon_usage')->updateCustomerCouponTimesUsed($customerId, $coupon->getId(), true);

// Decrement rule times_used
if ($customerCoupon = Mage::getModel('salesrule/rule_customer')->loadByCustomerRule($customerId, $coupon->getRuleId())) {
$customerCoupon = Mage::getModel('salesrule/rule_customer')->loadByCustomerRule($customerId, $coupon->getRuleId());
if ($customerCoupon->getId()) {
$customerCoupon->setTimesUsed($customerCoupon->getTimesUsed() - 1);
$customerCoupon->save();
}
Expand Down

0 comments on commit 7f185e5

Please sign in to comment.