Problem - Created a Dynamic Product page using the product collection (created by me). Now need to add addtocart functionality in the normal button but it's not working.
Error - FetchError: {"code":"CANNOT_ADD_CART","commandName":"AddToCart","message":"Product with id b3b9c456-042f-41d6-9411-fdb53c42b4f0 was not found","field":""}
Code Reference:-
// For full API documentation, including code examples, visit https://wix.to/94BuAAs
//TODO: write your page related code here...
$w.onReady(function () {
$w("#dynamicDataset").onReady(() => {
populateCalculatedFields();
});
});
// Add the customized item to the shopping cart.
export function button13_click(event) {
// Get the current product.
let currentProduct = $w('#dynamicDataset').getCurrentItem();
console.log("inside button click");
console.log(currentProduct._id)
// Add the current product to the cart with the user's chosen background color, text color, custom text, and custom background image.
$w('#shoppingCartIcon1').addToCart(currentProduct._id,1)
.then(() => {
// Item added to the shopping cart
console.log("add product ${productId} success");
})
.catch((error) => {
// Catch an error that occurs
console.log(error);
});
}
function populateCalculatedFields() {
const currentRow = $w("#dynamicDataset").getCurrentItem();
let colorRow = currentRow.color;
let selectionTagsOptions = $w("#selectionTags1").options;
selectionTagsOptions = [];
console.log(colorRow);
if(colorRow ===undefined)
{
$w("#selectionTags1").hide();
return;
}
for(let i =0; i <colorRow.length;i++)
{
selectionTagsOptions.push({'label': colorRow[i], 'value':colorRow[i]});
console.log(selectionTagsOptions[i]);
}
$w("#selectionTags1").options = selectionTagsOptions;
}
@Alexander (Wix) @Amit (Wix) @Anat Wix@Avi Guzansky (Wix)@Erez Cohen (Wix)