Skip to content

Commit

Permalink
Redeems only one coupon per order
Browse files Browse the repository at this point in the history
  • Loading branch information
sampoyigi committed Jun 12, 2024
1 parent c74ba68 commit 9c086d5
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions models/Coupons_history_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,20 @@ class Coupons_history_model extends Model

public static function redeem($orderId)
{
Coupons_history_model::query()
->where('order_id', $orderId)
->get()
->each(function ($couponHistory) {
$couponHistory->update([
'status' => 1,
'created_at' => now(),
]);

Event::fire('admin.order.couponRedeemed', [$couponHistory]);
});
if (!$couponHistory = static::query()->orderBy('created_at', 'desc')->firstWhere('order_id', $orderId)) {
return false;
}

$couponHistory->update([
'status' => 1,
'created_at' => now(),
]);

static::query()->where('order_id', $orderId)
->where('coupon_history_id', '<>', $couponHistory->coupon_history_id)
->delete();

Event::fire('admin.order.couponRedeemed', [$couponHistory]);
}

public function getCustomerNameAttribute($value)
Expand Down

0 comments on commit 9c086d5

Please sign in to comment.