Setting up ‘Back in Stock’ notifications for Magento 2
Are the products in your Magento webshop often sold out? Do you have insufficient stock to meet customer demand? Keeping your customers up-to-date is crucial in such situations. You don’t want to lose those customers. If you wait too long to inform them, you risk losing sales. That's why it's a good idea to send email alerts to everyone interested in your out-of-stock products. In this article, we’ll explain how to do this for Magento 2.
Back in Stock Tracking
Imagine someone wants to buy a product from your webshop—great! But then, the customer discovers that the product is out of stock. Disappointed, the enthusiastic customer leaves. By enabling back in stock tracking for Magento 2, you can easily send notifications when an item is restocked. This way, you quickly notify customers and ensure they return to your webshop.
You have control over how, where, and when the back in stock trigger button appears. Additionally, you can fully customize the display and text of this feature. This means you get to decide how the back in stock notifications will look. You do this by successfully sending back in stock events to Klaviyo. Afterward, you can create a back in stock flow, ensuring that customers who signed up for notifications actually receive them.
Magento 2 Setup Recommendations
To implement back in stock for Magento 2, you’ll need:
- A sign-up form on the product page that appears when a product is out of stock. This form collects the email addresses of customers who want to be notified when the product is available again.
- When someone signs up via the form, send the data to Klaviyo’s back in stock API. When a customer submits the form, make a call to the API to register the customer for back in stock notifications.
- After sending the data to the API, configure the automated back in stock notifications.
Account Settings and Flow Triggers
Once a back in stock event is captured, you’ll find the back in stock settings under Account > Settings > Email. If you don’t see these settings, first create an event trigger. These settings allow you to determine how to trigger your back in stock flows.
Want to Set Up a 'Back in Stock' Notification Flow? Read here ‘How to build a back in stock flow’ gids.
Subscribing to Notifications
When a customer subscribes to back in stock notifications, send a request to Klaviyo’s back in stock endpoint. There are two versions of this request that you can choose from: a server-side version and a front-end version. Here’s a breakdown of the differences between these versions:
Server-Side Request
To send new subscriber information to the server-side API, you use a POST request. The information is sent to the server via a JSON data object as a URL-encoded form. The JSON object requires the following:
- a – Your public API key.
- email – The email address of the customer subscribing to back in stock notifications for this product.
- variant – The ID of the product variant.
- platform – Set this to magento_two
Front- end request
ou can also send a back in stock notification request via JavaScript. To do this, include the following parameters in an ajax request:
- a – Your public API key.
- email – The email address of the customer subscribing to back in stock notifications for this product.
- variant – The ID of the variant (must match
$id
in the step about field mapping). - platform – Set this to magento_two
API Responses
Here are the meanings of the responses you may receive from the API:
Successful Back in Stock Subscription:
This indicates that the customer has successfully subscribed to the back in stock notifications.
{"email": "test@email.com", "success": true}
Invalid Email Address or API Key:
{"errors": ["There was something wrong with your request. Please try again."], "data": {}, "success": false}
Missing Parameters for Form Data:
{"status": 400, "message": "There was something wrong with your request: * email * This field is required."}
Invalid Variants and Duplicate Subscriptions
- The API does not validate variant IDs. If an invalid variant ID is included in a request, the API will send back a standard response, making it seem like the subscription was successful. However, no event will be created for the profile, and the customer will not receive a back in stock notification.
- It is not possible to submit multiple subscriptions for the same product variant using the same profile. Only the first request is accepted if multiple requests are submitted for the same email address.
- There is no limit to the number of unique item variants a profile can subscribe to.
- Once a customer receives an email notifying them that a specific variant is back in stock, the current subscription for notifications is deactivated. The customer can then re-subscribe for notifications for the same item.
Extra articles
Want to learn more about ‘back in stock’ emails, flows, and notifications?
- Read here; How to build a back in stock flow.
- Readh here; How to set up a custom back in stock notification
- Read here; How to configure your back in stock emails.