Skip to content

Commit

Permalink
Prevent duplicate entry when updating salesrule_coupon_usage (#1117)
Browse files Browse the repository at this point in the history
* remove $timesUsed > 0 check to prevent duplicate entry

* Prevent $timesUsed from going less than 0
  • Loading branch information
drwilliams authored and colinmollenhour committed Aug 21, 2020
1 parent 79106ba commit 03a4798
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions app/code/core/Mage/SalesRule/Model/Resource/Coupon/Usage.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,20 @@ public function updateCustomerCouponTimesUsed($customerId, $couponId, $decrement

$timesUsed = $read->fetchOne($select, array(':coupon_id' => $couponId, ':customer_id' => $customerId));

if ($timesUsed !== false && $timesUsed > 0) {
$this->_getWriteAdapter()->update(
$this->getMainTable(),
array(
'times_used' => $timesUsed + ($decrement ? -1 : 1)
),
array(
'coupon_id = ?' => $couponId,
'customer_id = ?' => $customerId,
)
);
if ($timesUsed !== false) {
$timesUsed += ($decrement ? -1 : 1);
if($timesUsed >= 0) {
$this->_getWriteAdapter()->update(
$this->getMainTable(),
array(
'times_used' => $timesUsed
),
array(
'coupon_id = ?' => $couponId,
'customer_id = ?' => $customerId,
)
);
}
} else {
$this->_getWriteAdapter()->insert(
$this->getMainTable(),
Expand Down

0 comments on commit 03a4798

Please sign in to comment.