Hello, Magento mates. ?

Welcome to MageComp’s Magento tutorials.

Sometimes, the product/s your customer is willing to buy may be out of stock, and to prevent them from frequently visiting to check the product availability and leaving your website disappointedly, you can choose to notify them about the out of stock products that are restocked again.

Today, in this new Magento tutorial, we will learn to set automated notifications for customers about out of stock Magento 2 products that are back in stock using REST API.

Steps to Set the Customer Notifications for Back in Stock Products

Step 1 – 

First, we need to create a webapi.xml” file inside our Magento 2 extension by following this path ?

app/code/Vendor/Extension/etc

Enter the following code. ?

Step 2 – 

After this, we need to create a “di.xml” file inside our extension by following this path. ?

app/code/Vendor/Extension/etc

Then, enter the following code.?

Step 3 –

Once again, we need to create a “ProductAlertManagementInterface.php” file in the following extension path. ?

app/code/Vendor/Extension/Api

Then, enter the following code. ?

Step 4 – 

After that, we need to create a “ProductAlert.php” file in our following extension path. ?

app/code/Vendor/Extension/Model

Now, enter the following code. ?

Output ?

Magento 2: How to Set Notify Customers When Out of Stock Product is Back in Stock Using REST API

Please Note That

We have defined our API end point in etc/webapi.xml file.

For Add product, we have /V1/productalertstock/add/:productId.

The complete URL will be http://{Magento2Root}/rest/V1/productalertstock/add/123

To access the above API, you need a Customer token, which can be obtained by

http://{Magento2Root}/rest/V1/integration/customer/token

Conclusion

So, this was it. By following the steps mentioned above, you can easily set notifications to notify your customers about product restocking of out-of-stock products. The practice of notifying your customers about products being back in stock will help you gain their trust and increase their loyalty toward your brand.

Hope this tutorial was helpful to you. If you face any trouble with these steps, you can comment your queries in the comment section or contact us through our official Facebook page or hire an experienced Magento 2 developer to help you with the trouble.

Thank you for reading.

Happy Coding!!!

hire magento developers

Click to rate this post!
[Total: 0 Average: 0]