there is grand question out there that quite a lot of people sought to figure out
"HOW TO ADD AN ’ ADD TO CART ’ BUTTON TO MY STORE’S DATABASE 'S CUSTOM DYNAMIC PAGE "
I got it work somehow a couple times before no go again what I did was:
- I created dynamic page from the original Wix store’s “products” dataset
- I build regular button, create onClick event and apply this code
export function addToshoppingCartIcon_click(event, $w) {
const productId = $w('dynamicDataset').getCurrentItem()._id; $w('#shoppingCartIcon1').addToCart(productId, 1 );
and
$w.onReady(function () {
$w("#addToCartButton").onClick((event) => {
let $item = $w.at(event.context);
let selectedProduct = $item('#productsDataset').getCurrentItem();
let productId = selectedProduct._id;
$w('#shoppingCartIcon1').addToCart(productId)
.then(() => {
console.log("add product ${productId} success");
})
.catch((error) => {
console.log(error);
});
});
});
that’s the only time it work, somehow …it did add my product to the cart and jump to cart page but that’s fine
I was so hype…then it didn’t work again …somehow, on the console it show the error as: addToCart is not a function which is odd because when it compile it can work and i did find the function but it become not when
preview.
can anyone figure something from what I told?
I already know how to setup “standalone add-to-cart-button” which is not what I want.
I don’t want to use the standard wix store page and store widget, I want to use MY designed dynamic page.
the solution to this error is my only objective of this discussion.