BackInStock (optional)

https://github.com/magesuite/back-in-stock

It allows to receive email notifications when a product is again in stock. Can be extended with Magesuite_PwaNotifications and Magesuite_BackInStockPwaNotifications

 

Installation

This module is optional

composer require "creativestyle/magesuite-back-in-stock" ^1.0.0

User manual

https://creativestyle.atlassian.net/wiki/spaces/MGS/pages/1999798279

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 https://creativestyle.atlassian.net/wiki/spaces/MGSDEV/pages/2272854054 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 ( ) correct support for simple products in configurable and grouped product

Admin settings

In order to activate this module go to:

Stores -> Configuration -> Magesuite -> Back in Stock Subscriptions and select Yes in the Enabled dropdown. With its activation additional tab Back in stock can be found on every product detail page.

Above there are also a few optional settings visible above - they are well described and can be adjusted per clients request.

Another set of settings are available in Email Configuration - they’re described in user manual linked above.

Frontend

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 panel:

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:

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

magesuite.consumer.amqp:

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

back_in_stock_notification_queue

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