Skip to main content

Email & SMS Notifications

This document describes the notification system including email templates, SMS sending, push notifications, and automated notification generation.

Overview

The system sends notifications through three channels:

  • Email — Transactional and marketing emails via Yii mailer
  • SMS — Via Messente API (Estonian phone numbers)
  • Push — Mobile push notifications

SMS (Messente)

File: common/infrastructure/SmsSender.php

  • Uses Messente\Api\OmnimessageApi
  • Configuration from Yii::$app->params['smsSender'] (username, password, senderName)
  • sendMessage(to, content, throw) — Sends SMS, returns boolean
  • getNormalizedEstonianPhoneNumber() — Normalizes Estonian numbers (adds +372 prefix for numbers starting with 5)
  • Error handling: Catches ApiException, optionally throws RuntimeException

Email System

Email Templates

Directory: common/mail/views/

23 templates with HTML and text variants:

TemplatePurpose
emailVerify-html/textEmail verification
passwordResetToken-html/textPassword reset
orderCompleteItems*Order completion details
basketReminderAbandoned basket reminder
wishList*Wishlist notifications
authorNewProductsNew products by followed authors
feedbackReminderPost-purchase feedback request
vendorProductConfirmedVendor product approval
vendorAddedProductNew vendor product added
mergedProductsProduct merge notification
voucherGiftCard*Gift card emails
wholesaleClientRegistrationWholesale registration

Layouts: templateWrapper.php, html.php, text.php

Email Message Composers

Directory: common/mail/composers/

25+ composers, each building a specific email type. All implement IEmailMessageComposer interface.

Order-related:

  • OrderCompletedBuyerMessageComposer — Order confirmation to buyer
  • OrderCompletedReceiverMessageComposer — Order confirmation to receiver (if different)
  • OrderReminderMessageComposer — Order pickup/action reminder
  • OrderDriveInReminderMessageComposer — Drive-in pickup reminder

User account:

  • EmailVerificationMessageComposer — Email verification link
  • PasswordResetMessageComposer — Password reset link

Gift cards:

  • VoucherGiftCardMessageComposer — Voucher gift card delivery
  • LoyaltyGiftCardMessageComposer — Loyalty gift card notification

Subscriptions:

  • SubscriptionPurchasedMessageComposer — Subscription confirmation
  • SubscriptionCancelledMessageComposer — Cancellation confirmation
  • SubscriptionBillingFailedMessageComposer — Failed billing notification

Other:

  • BackInStockNotificationMessageComposer — Product back in stock
  • WholesaleRegistrationMessageComposer — Wholesale registration
  • WholesaleBasketMergeReceiverMessageComposer — Wholesale basket merge
  • VendorProductConfirmationMessageComposer — Vendor product confirmed
  • VendorProductManagerProductAddedMessage — New vendor product alert
  • RevenueShareReportMessageComposer — Revenue share reports
  • WoltOfferEmailMessageComposer — Wolt delivery offers

Base class: UserMessageComposer — provides common email building logic with store-specific URL management and activity tracking (objectId, activityType).

Automated Notification System

Directory: common/notifications/

Notification Generation

Generators (common/notifications/generators/):

GeneratorTypeDescription
BasketReminderGeneratorbasketAbandoned basket reminders
NewSameAuthorProductsGeneratoroffersNew products by authors the user follows
OrderFeedbackReminderGeneratororderPost-purchase feedback requests
SpecialOfferGeneratoroffersSpecial offer notifications
WishlistProductDiscountGeneratoroffersWishlist items on discount
WishlistProductGlobalDiscountGeneratoroffersWishlist items in global discount
WishlistProductOutOfStockGeneratoroffersWishlist items back in stock
WishlistProductEndingGeneratoroffersWishlist items ending soon

Notification Formatting

Formatters format notifications for specific channels:

  • Email formatters: BasketReminderEmailFormatter, NewAuthorProductEmailFormatter, OrderFeedbackReminderEmailFormatter, SimpleSpecialOfferEmailFormatter, WishlistProductDiscountEmailFormatter, WishlistProductEndingEmailFormatter
  • Push formatters: Corresponding push notification variants

Publishing

Publishers (common/notifications/publishers/):

  • SpecialOfferEmailPublisher — Sends special offer emails
  • SpecialOfferPushPublisher — Sends special offer push notifications
  • BackInStockNotificationPublisher — Back-in-stock emails
  • VendorRentalReportEmailPublisher — Vendor rental reports
  • WoltOfferEmailPublisher — Wolt delivery offer emails

Management

Managers:

  • SpecialOfferGenerationManager — Orchestrates offer generation
  • SpecialOfferNotificationManager — Manages offer notification lifecycle
  • BackInStockNotificationManager — Back-in-stock notification management
  • VendorRentalReportEmailManager — Vendor report email scheduling
  • WoltOfferEmailManager — Wolt offer email management

Caching

  • ExcludedClientAccountCache — Prevents sending to excluded accounts
  • SentNotificationCache — Prevents duplicate notifications

Mobile Push

File: common/notifications/MobilePushNotificationSender.php

Handles mobile push notification delivery.

Console Commands

# Generate notifications
php yii notification/generate --type=basket [--dayOffset=N] [--webStoreNavCode=...]
php yii notification/generate --type=order
php yii notification/generate --type=offers

# Send queued notifications
php yii notification/send [--webStoreNavCode=...]

# Clear expired notifications
php yii notification/clear-expired

# Back-in-stock
php yii back-in-stock-notification/send-emails
php yii back-in-stock-notification/cleanup-old-emails

Expiration Rules

  • Wishlist notifications: expire after 3 days
  • Product ending notifications: expire after 2 days
  • Back-in-stock notifications: cleaned up after 14 days