| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace FluentCart\App\Services\Email; |
| 4 | 4 | |
| 5 | +use FluentCart\Api\ModuleSettings; | |
| 5 | 6 | use FluentCart\App\Models\Meta; |
| 6 | 7 | use FluentCart\App\Services\Cache; |
| 7 | 8 | use FluentCart\App\Services\TemplateService; |
| 8 | 9 | use FluentCart\Framework\Support\Arr; |
| @@ -17,12 +18,24 @@ | ||
| 17 | 18 | ]; |
| 18 | 19 | |
| 19 | 20 | const META_KEY = 'email_notifications_config'; |
| 20 | 21 | |
| 22 | + /** The events the reviews module raises. */ | |
| 23 | + const REVIEW_EVENTS = ['review_created', 'review_approved_done', 'review_replied_done']; | |
| 24 | + | |
| 21 | 25 | public static function getNotifications(): array |
| 22 | 26 | { |
| 23 | 27 | $settings = static::getDefaultNotifications(); |
| 24 | 28 | $settings = apply_filters('fluent_cart/email_notifications', $settings); |
| 29 | + | |
| 30 | + // Review notifications are neither offered nor sent while the module | |
| 31 | + // is off; their stored settings are kept by name. | |
| 32 | + if (!ModuleSettings::isActive('reviews')) { | |
| 33 | + $settings = array_filter($settings, function ($setting) { | |
| 34 | + return !in_array(Arr::get($setting, 'event'), static::REVIEW_EVENTS, true); | |
| 35 | + }); | |
| 36 | + } | |
| 37 | + | |
| 25 | 38 | $config = Arr::get(static::cachedSettings(), 'notification_config', []); |
| 26 | 39 | |
| 27 | 40 | foreach ($settings as $key => &$setting) { |
| 28 | 41 | $setting['name'] = $key; |