Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Once product is back in stock every subscriber will be notify by email. This action can be also triggered manually for every product on it’s page in admin panel.

Backend

Queue setup

This module depends on queue consumers being run constantly.

Queue name depends on environment configuration:

  • magesuite.consumer.db if RabbitMQ is not configured in app/etc/env.php

  • magesuite.consumer.amqp if RabbitMQ is configured in app/etc/env.php

Example of queue startup:

magesuite.consumer.db:

Code Block
bin/magento queue:consumers:start magesuite.consumer.db

magesuite.consumer.amqp:

Code Block
bin/magento queue:consumers:start magesuite.consumer.amqp

Cron

This module is using send_back_in_stock_notification_from_queue cron.

Its name is self-explanatory. It sends notifications about the items that are back in stock.

By default, it does so every minute, but it can be changed as we please in the admin panel.

We can also set if the subscription should be canceled after sending the first notification, by default, it is not canceled, so the customer will be receiving a notification every time a product will be back in stock unless he/she unsubscribes or we change settings.

Database changes

This module comes with 2 tables.

back_in_stock_subscription_entity

Code Block
languagenone
int "id" PRIMARY KEY
int "customer_id" NOT FOREIGN KEY (!)
varchar "customer_email" 
int "product_id" FOREIGN KEY
int "parent_product_id" NOT FOREIGN KEY (!)
smallint "store_id" FOREIGN KEY
timestamp "add_date"
timestamp "send_date"
smallint "send_count"
varchar "send_notification_status"
boolean "customer_confirmed"
boolean "customer_unsubscribed"
varchar "token"
varchar "notification_channel"
boolean "is_removed"

back_in_stock_notification_queue

Code Block
languagenone
int "id" PRIMARY KEY
int "subscribtion_id" FOREIGN KEY
varchar "notification_type"
text "message"

Subscription management from the user side

Both enabling and disabling subscription from the user side, is resolved by entering accordingly Subscribe and Unsubscribe controller via Ajax script.

Enabling

Controller/Notification/Subscribe.php which leads to Service\Subscription\Channel\Email\EmailSubscriptionCreator::subscribe

Disabling

Controller/Notification/Unsubscribe.php which leads to Model\BackInStockSubscription::setCustomerUnsubscribed

Plugins

This module comes with 3 plugins.

The first 2, are responsible for collecting back-in-stock items.

Plugin\Inventory\Model\SourceItem\Command\SourceItemsSave\CollectBackInStockItemsForQueue

Plugin\Inventory\Model\SourceItem\Command\SourceItemsSaveWithoutLegacySynchronization\CollectBackInStockItemsForQueue

The 3rd one adds them to the queue

Plugin\InventoryIndexer\Plugin\InventoryApi\ReindexAfterSourceItemsSavePlugin\AddBackInStockItemsToQueue