Hi everyone!
I am trying to add a button so a customer can be notified when an out of stock button is back in stock. see link below:
[https://www.wix.com/corvid/example/notification-when-back-in-stock](https://www.wix.com/corvid/example/notification-when-back-in-stock
I)
I got the below error but I already created the stock wait list collection:
“WDE0025: The stockWaitList collection does not exist. You cannot work with a collection using the Data API before it is created in the Editor.”
Please help! Thank you!
So you have the dataset setup in your site structure as this?
As well as having the same name and settings of the dataset itself.
Then have you got the same name used as in the example and as used in the code on the page?
const { items } = await wixData.query('stockWaitList').eq('product', productId).eq('userEmail', userEmail).find();
newNotifyUserObj.shouldNotifyUser ? await wixData.remove('stockWaitList', newNotifyUserObj.itemId) : await wixData.insert('stockWaitList', objToInsert);
As well as in the backend checkProductAvailability.jsw file too?
const { items } = await wixData.query('stockWaitList').include('product').find();
await wixData.remove('stockWaitList', waitingItem._id);
Hello! Thanks for the help!
I double checked all the above and only the “stockwaitlist” has some capital letters in the wrong place. I corrected and the button is working but then when I put the item back in stock, I didn’t receive the email.
Thanks!
Have you got your own SendGrid API key and added it to your Secrets Manager?
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 .
Email.jsw
import { getSecret } from 'wix-secrets-backend';
import sgMail from '@sendgrid/mail'
export async function sendEmail(userEmail, productName) {
const sendgridKey = await getSecret('sendGridAPIkey'); // read more about secrets-manager here: https://support.wix.com/en/article/corvid-working-with-the-secrets-manager
sgMail.setApiKey(sendgridKey);
const message = {
to: userEmail,
from: 'corvid@wix.com',
subject: 'Product is back to stock!',
text: `Your product is back to stock: ${productName}`
}
return sgMail.send(message)
}
Add it to your secrets manager as shown here by going to Dashboard, Settings and it will be under the Production Tools heading.
Thank you for your help!
I just did what you mentioned above.
Is this the correct name “sendGridAPIkey”?
Do I need to do anything else?
Can I change where the email comes from in the code? Instead of coming from corvid email, I want people to receive it from my email.
Thank you!
Call it the same as they have used in the example and you won’t need to worry about changing anything in the code.
As for email address, yes just change corvid one to your own preferred one.
I didn’t change it in the code. But I am wondering if I picked the right name from the code. This is the code:
Waited for 24hours to see if I would receive the notification when the item was back in stock but didn’t receive any email.
Any idea of what I am missing?
Thank you!
Did you actually create an account with SendGrid to get your own API key?
https://sendgrid.com/docs/ui/account-and-settings/api-keys/
As well as changing the from example to your own real email address.
Plus, note that with SendGrid, certain emails like gmail can not be used.
https://support.wix.com/en/article/corvid-tutorial-sending-an-email-on-form-submission
Important:
Using SendGrid to send emails from certain email providers may not work as expected. For example, see this notification about sending from Gmail addresses.
Yes I created an account with SendGrid and then created an API Key which I added to the Secret Manager.
I replaced corvid’s email address with mine which is not gmail, its my own domain.
I checked the “Stock Wait List” and the items I asked to be notified when they’re back in stock are there but then I don’t get the email when they are back in stock.
But they do disappear from the “Stock Wait List” after they are back in stock.
Are you testing it on a live published site or through preview?
As you are using Wix Users API, you need to be using a live site for this.
https://www.wix.com/corvid/reference/wix-users.html
The APIs in wix-users are only partially functional when previewing your site. View a published version of your site to see their complete functionality.
Also, it might be worth setting up SendGrid Authentication here as well so that SendGrid is allowed to send on your behalf and you don’t get the ‘sent by SendGrid’ message attached to your email too.
https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-domain-authentication/
Also, try adding a new site member to your site that does not use an email that is connected to your site.
Then login with that users details and try using the email when back in stock option and log back out.
Go back to the Wix Dashboard and change your product stock levels.
https://support.wix.com/en/article/managing-your-inventory-in-wix-stores
Save and republish your site.
Check to see if you then get an email for this other member about new stock etc… and log back into the website to see if the notification has gone as well.
I was also wondering if the products were automatically tracking inventory levels as like here.
https://support.wix.com/en/article/managing-your-inventory-in-wix-stores
However, this option is not turned on in the Wix example.
Oh and not forgetting here too, make sure that you sync the Stock Wait List from sandbox to live as well.
https://support.wix.com/en/article/syncing-content-between-sandbox-and-live-collections
I am testing it on live website.
I didnt have the SendGrid Authentication. I already asked for the person who has access to the domain host to copy the links. But I don’t believe that this is the problem with it not working right?
I signed up on my live website with an email account that is not my domain or gmail but still getting get the back in stock email.
All my products have specific stock amount for each.
I already synced the Stock Wait List from sandbox to live as well.
The button works because I can click it and I do receive the notification in the content manager. Therefore I believe the only problem is the email not getting out to the person’s email when the item is back in stock.
Somehow it finally worked! I got the back in stock email.
is it possible for the email to include the image of the product and the website’s link of the specific product?
Thank you! Really appreciate your help and patience!