← All changes
|
app/Services/Reminders/SubscriptionReminderService.php
+13
-0
1.6.3
→
1.6.5
View file →
| @@ -4,8 +4,9 @@ | ||
| 4 | 4 | |
| 5 | 5 | use FluentCart\App\Helpers\Status; |
| 6 | 6 | use FluentCart\App\Models\Subscription; |
| 7 | 7 | use FluentCart\App\Models\SubscriptionMeta; |
| 8 | +use FluentCart\App\Services\Payments\SubscriptionHelper; | |
| 8 | 9 | use FluentCart\Framework\Support\Arr; |
| 9 | 10 | |
| 10 | 11 | class SubscriptionReminderService extends ReminderService |
| 11 | 12 | { |
| @@ -111,8 +112,12 @@ | ||
| 111 | 112 | if (!$this->isTrialSubscription($subscription) || !$subscription->next_billing_date) { |
| 112 | 113 | return false; |
| 113 | 114 | } |
| 114 | 115 | |
| 116 | + if (!$this->isEligible($subscription)) { | |
| 117 | + return false; | |
| 118 | + } | |
| 119 | + | |
| 115 | 120 | $state = $this->normalizeReminderState($subscription->getMeta(static::TRIAL_META_KEY, [])); |
| 116 | 121 | if ($this->isStageAlreadySent($state, $cycleKey, $stage)) { |
| 117 | 122 | return false; |
| 118 | 123 | } |
| @@ -184,8 +189,9 @@ | ||
| 184 | 189 | $batchSize = $this->getScanBatchSize(); |
| 185 | 190 | |
| 186 | 191 | while (!$this->isRuntimeExpired($startedAt, $maxRuntime)) { |
| 187 | 192 | $subscriptions = Subscription::query() |
| 193 | + ->with('order') | |
| 188 | 194 | ->where('id', '>', $lastId) |
| 189 | 195 | ->whereNotNull('next_billing_date') |
| 190 | 196 | ->whereIn('status', $this->getReminderStatuses()) |
| 191 | 197 | ->orderBy('id', 'ASC') |
| @@ -608,8 +614,15 @@ | ||
| 608 | 614 | */ |
| 609 | 615 | |
| 610 | 616 | protected function isEligible(Subscription $subscription): bool |
| 611 | 617 | { |
| 618 | + // Live subscription on a test-mode store (or vice versa): don't email — | |
| 619 | + // mode lives on the parent order. Checked at both scan and send time so | |
| 620 | + // pre-queued actions copied to a clone are also caught. | |
| 621 | + if ($subscription->order && !SubscriptionHelper::canProcessInMode($subscription->order->mode)) { | |
| 622 | + return false; | |
| 623 | + } | |
| 624 | + | |
| 612 | 625 | if (!in_array($subscription->status, $this->getReminderStatuses(), true)) { |
| 613 | 626 | return false; |
| 614 | 627 | } |
| 615 | 628 | |