← All changes
|
app/Services/Reminders/SubscriptionReminderService.php
+19
-0
1.4.2
→
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') |
| @@ -227,8 +233,14 @@ | ||
| 227 | 233 | } |
| 228 | 234 | |
| 229 | 235 | protected function queueForSubscription(Subscription $subscription): int |
| 230 | 236 | { |
| 237 | + // Store-billed (manual/system) subscriptions use the renewal order email + | |
| 238 | + // renewal reminders instead — queueing these too would double-remind | |
| 239 | + if ($subscription->usesRenewalEngine()) { | |
| 240 | + return 0; | |
| 241 | + } | |
| 242 | + | |
| 231 | 243 | if (!$this->isEligible($subscription)) { |
| 232 | 244 | return 0; |
| 233 | 245 | } |
| 234 | 246 | |
| @@ -602,8 +614,15 @@ | ||
| 602 | 614 | */ |
| 603 | 615 | |
| 604 | 616 | protected function isEligible(Subscription $subscription): bool |
| 605 | 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 | + | |
| 606 | 625 | if (!in_array($subscription->status, $this->getReminderStatuses(), true)) { |
| 607 | 626 | return false; |
| 608 | 627 | } |
| 609 | 628 | |