Hi All,
Ok so im not expert but i have been following this guide
I have got to the point where i have configured everything and i can see that the button appears when in fact an item is out of stock, i can also click the button as a member and see that my database “Stock Wait List” being updated when i use it. I can also see that the item is removed when i un click the button. So all good!!! But…
The tricky bit i have registed an account on SendGrid, i have created the secret API Keys and believe i have configured this correctly.
So the only thing im trying to do now is send the email to a user when the jobs.config runs at the time specified…
BUT the job does not run… and no email is sent…i cannot see anything sent to SendGrid… So my suspicion is that the job is not running however im not sure how i troubleshoot or know this…
Any help appreciated!
This is my code for all sections:
Product Page
import wixData from 'wix-data';
import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
wixLocation.onChange((location) => {
$w('#notifyButton').hide();
productBackToStockNotificationInit();
});
$w.onReady(() => {
productBackToStockNotificationInit();
});
async function productBackToStockNotificationInit() {
const productObj = await getProductObj();
const userEmail = await getUserEmail();
const userNotifyObj = await getUserNotifyObj(userEmail, productObj.productId);
$w('#notifyButton').onClick(async () => await setOnClickNotifyButton(productObj, userEmail));
notifyButtonUIHandler(productObj, userNotifyObj.shouldNotifyUser);
}
async function getUserNotifyObj(userEmail, productId) {
const { items } = await wixData.query('stockWaitList').eq('product', productId).eq('userEmail', userEmail).find();
const shouldNotifyUser = items.length > 0;
const shouldNotifyUserObj = { shouldNotifyUser };
if (shouldNotifyUser) {
shouldNotifyUserObj.itemId = items[0]._id;
}
return shouldNotifyUserObj;
}
function notifyButtonUIHandler(productObj, shouldNotifyUser) {
productObj.isInStock ? $w('#notifyButton').hide() : $w('#notifyButton').show();
$w('#notifyButton').label = shouldNotifyUser ? 'Cancel Notification' : 'Notify Me When In Stock';
}
async function setOnClickNotifyButton(productObj, userEmail) {
$w('#notifyButton').label = 'please wait...'
const newNotifyUserObj = await getUserNotifyObj(userEmail, productObj.productId);
const objToInsert = {
userEmail: userEmail,
product: productObj.productId,
}
newNotifyUserObj.shouldNotifyUser ? await wixData.remove('stockWaitList', newNotifyUserObj.itemId) : await wixData.insert('stockWaitList', objToInsert);
notifyButtonUIHandler(productObj, !newNotifyUserObj.shouldNotifyUser);
}
async function getProductObj() {
const { inStock, _id } = await $w('#productPage1').getProduct();
const productObj = {
isInStock: inStock,
productId: _id,
}
return productObj;
}
function getUserEmail() {
const user = wixUsers.currentUser;
return user.getEmail();
}
Email.jsw (EmailSecret is my API Key) from address has been changed
Jobs.Config
CheckProductAvailability.jsw
Just a little update but I have also noticed the following error when i try to run the function, its complaining about "Cannot find module ‘@sendgrid/mail’
OK ******************* UPDATE 12/03/2021 ***********************
Ok so a little update but i learnt that you need to add the @Sendgrid module to WIX (It doesnt tell you this in the example provided) so to help people you need to add this in via the COG Box near number (1)
When you have done this the module actually runs ! great.
However my users are still not recieving emails!!!
Help!