Example Description
This example displays a few products that can be purchased using Wix Stores.
On a product page of an item that is out of stock a “Notify Me When in Stock” button will appear. After clicking the button the member will be subscribed to the item’s stock availability, so once it’s back in stock they will get an email notification. The member can cancel his subscription to the item’s stock availability by clicking the “Cancel Notification” button in the item’s product page.
Note that the member needs to be logged-in to the site in order to see these buttons.
How We Built It
Collections
For this example we created a collection called “Stock Wait List” that holds the user’s email and a reference to the wanted item from the Stores/Products collection (which is created automatically when Wix Stores is added).
Page Elements
In the product page we added the following page element:
-
Subscription button - the button is displayed when the user is logged-in and the item is out of stock. The button’s label is “Notify me When in Stock”, but if the user has already subscribed to the notification the label is changed to “Cancel Notification”.
Backend Code
-
Jobs.config - a scheduled job that runs once a day and calls the CheckProductAvailability function.
-
CheckProductAvailability.jsw - includes a function that goes over the “Stock Wait List” collection and checks for each subscription if the product if it’s back in stock. If it is back in stock it calls the sendMail function in email.jsw to send a mail notification to the subscriber, and removes the record from the collection.
-
Email.jsw - includes the sendMail function that sends the mail to the subscribed user using sendgrid node module. In order to send the mail the module gets the Sendgrid API key from Secrets Manager.
Frontend Code
-
NofityButtonUIHandler - decides if to show the subscription button and what label to put on the button.
-
setOnClickNotifyButton - adds or removes a row from the “Stock Wait List” collection when the button is clicked.
-
getProductObj - checks if the product is in stock and what is the product’s id.
-
getUserEmail - gets the user’s email address
-
wixLocation.onChange - inits the button and event handlers accordion to the current product page.
Related Examples
Did this help?
|
Thanks for your feedback!
Related Items
Recommend products based on price, brand and more.
Intermediate
Back in Stock Notification for Site Contacts
Allow site visitors to register and receive a notification when a product is back in stock
Advanced
Highest-Rated Products
Showcase your highest-rated products in their own gallery.
Advanced
Product Configurator
Let customers create one-of-a-kind products.
Advanced