-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the UpdateCouponUsage listener
- Loading branch information
1 parent
d955bc9
commit 7958a02
Showing
3 changed files
with
30 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Vanilo\Foundation\Listeners; | ||
|
||
use Illuminate\Support\Facades\DB; | ||
use Vanilo\Checkout\Contracts\CouponEvent; | ||
use Vanilo\Promotion\Models\CouponProxy; | ||
|
||
class UpdateCouponUsage | ||
{ | ||
public function handle(CouponEvent $event): void | ||
{ | ||
if (null !== $coupon = CouponProxy::findByCode($event->getCouponCode())) { | ||
DB::transaction(function () use ($coupon) { | ||
$coupon->usage_count += 1; | ||
$promotion = $coupon->getPromotion(); | ||
$promotion->usage_count += 1; | ||
$coupon->save(); | ||
$promotion->save(); | ||
}); | ||
} | ||
} | ||
} |
This file contains 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