Versions Compared

Key

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

...

4.4.Back-In-Stock Subscriptions

Advantages over a native Magento solution

Magento has its own back-in-stock functionality, however using Magesuite module comes with some advantages:

  • support for guest users, the native solution requires login

  • push notifications support (with BackInStockPwaNotifications (optional) module)

  • counting of the return to stock uses a message queue based on actual salable quantity taking into account reservations just after data update in inventory

  • counting of the return to stock is not done by cron but "almost live"

  • in combination with swatchenator module (Swatchenator (optional) ) correct support for simple products in configurable and grouped product

Admin settings

In order to activate this module go to:

...

In the buybox short form for subscribing to back-in-stock email notifications is displayed.

...

When confirmation is required there is a message visible and email is being sent:

...

When confirmation is not required success message is displayed:

...

Logged-in users can unsubscribe from all back-in-stock notifications in the admin paneltheir dashboard:

...

Once a product is back in stock every subscriber will be notify notified by email. This action can be also triggered manually for every product on it’s its page in the 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