Skip to content

Commit

Permalink
Cart update recalculates promotions as well
Browse files Browse the repository at this point in the history
- Coupon code gets saved to promo adjustment origin
  • Loading branch information
fulopattila122 committed Aug 25, 2024
1 parent a81be8d commit 22a49f0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Foundation/Listeners/CalculatePromotions.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

use Vanilo\Adjustments\Contracts\Adjustment;
use Vanilo\Adjustments\Models\AdjustmentTypeProxy;
use Vanilo\Checkout\Events\CouponAdded;
use Vanilo\Checkout\Events\CouponRemoved;
use Vanilo\Cart\Contracts\CartEvent;
use Vanilo\Checkout\Contracts\CheckoutEvent;
use Vanilo\Promotion\Contracts\PromotionAction;
use Vanilo\Promotion\Models\CouponProxy;

class CalculatePromotions
{
use HasCartAndCheckout;

public function handle(CouponAdded|CouponRemoved $event): void
public function handle(CheckoutEvent|CartEvent $event): void
{
$this->initialize($event);

Expand All @@ -35,6 +35,7 @@ public function handle(CouponAdded|CouponRemoved $event): void
/** @var PromotionAction $action */
foreach ($promotion->getActions() as $action) {
foreach ($action->execute($this->cartModel) as $adjustment) {
$adjustment->update(['origin' => $couponCode]);
if ($this->isAppliedToOurCart($adjustment)) {
$cartPromotionsTotal += $adjustment->getAmount();
}
Expand Down
1 change: 1 addition & 0 deletions src/Foundation/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class EventServiceProvider extends ServiceProvider
CartUpdated::class => [
CalculateShippingFees::class,
CalculateTaxes::class,
CalculatePromotions::class,
],
CartDeleting::class => [
DeleteCartAdjustments::class,
Expand Down

0 comments on commit 22a49f0

Please sign in to comment.