From 00bddb4cefb9e7112f2ab282b997ac03b1a4b336 Mon Sep 17 00:00:00 2001 From: Attila Fulop <1162360+fulopattila122@users.noreply.github.com> Date: Fri, 23 Aug 2024 17:21:02 +0300 Subject: [PATCH] Fixes at promotion logic --- src/Promotion/Actions/CartFixedDiscount.php | 1 + src/Promotion/Models/Coupon.php | 4 ++++ src/Promotion/Models/Promotion.php | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Promotion/Actions/CartFixedDiscount.php b/src/Promotion/Actions/CartFixedDiscount.php index 96a6abb1..d0790b36 100644 --- a/src/Promotion/Actions/CartFixedDiscount.php +++ b/src/Promotion/Actions/CartFixedDiscount.php @@ -40,6 +40,7 @@ public function apply(object $subject, array $configuration): array if ($subject instanceof Adjustable) { $result[] = $subject->adjustments()->create($this->getAdjuster($configuration)); } + //@todo also set the origin return $result; } diff --git a/src/Promotion/Models/Coupon.php b/src/Promotion/Models/Coupon.php index 43bc39d7..dc8a2777 100644 --- a/src/Promotion/Models/Coupon.php +++ b/src/Promotion/Models/Coupon.php @@ -51,6 +51,10 @@ public function canBeUsed(): bool public function isExpired(): bool { + if (null === $this->expires_at) { + return false; + } + return $this->expires_at->isPast(); } diff --git a/src/Promotion/Models/Promotion.php b/src/Promotion/Models/Promotion.php index e61f1b83..7371a142 100644 --- a/src/Promotion/Models/Promotion.php +++ b/src/Promotion/Models/Promotion.php @@ -92,7 +92,7 @@ public function getActions(): Collection public function isValid(?\DateTimeInterface $at = null): bool { - if ($this->usage_count >= $this->usage_limit) { + if (null !== $this->usage_limit && $this->usage_count >= $this->usage_limit) { return false; }