I need help with an Add To Cart button on a dynamic page to make it add the product. Like how the Stores Product Page Works, but in another dynamic page.
It is urgent, please!
Hi,
After creating a dynamic page and adding the Products dataset, you should add a button (a regular button), add an onClick event, get the product ID using the getCurrentItem function and use the addToCart function to add it to the cart. Hereās an example of what Iām referring:
export function addToCartBtn_click(event, $w) {
const productId = $w('#dynamicDataset').getCurrentItem()._id;
$w("#shoppingCartIcon1").addToCart(productId, 1, { choices: { Color: 'red' } });
}
Good luck,
Tal.
Tal, I canāt manage to do it.
I added the onClick event to the button:
export function button15_click(event, $w) {
//Add your code for this event here:
}
Now what do i do from there?
Hey, did you figure this out? Iām having the same problem.
This code does not work.
This is the code I have used -
export function addToshoppingCartIcon_click(event, $w) {
const productId = $w(ādynamicDatasetā).getCurrentItem()._id;
$w(ā#shoppingCartIconā).addToCart(productId, 1, );
}
Once clicked, nothing happens, no warning, no add to cart.
Could you please help? Iām trying to create a dynamic page with add to cart button, based on the product shown on the dynamic page - but nothing seems to be working.
is there any solution?
I got it work somehow a couple times then no go again
what I did was:
- I created dynamic page from the original Wix storeās āproductsā dataset
- I build regular button and apply the code without the product option part and hit preview
thatās the only time it work, somehow
it did add my product to the cart and jump to check-out page but thatās fine
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?
Old post being closed, please add a new post and refer back to this in a link if needed, rather than bumping an old thread from 2018.