Open Site Navigation

Dynamic Add-to-Cart Button for Custom E-commerce Stores

In this lesson, you will learn how to create a custom E-Commerce dynamic page with an Add-to-Cart button that adds the product from the dynamic page to the shopping cart.



Before you add the code, watch this video to make sure you set up your Content Manager and Dynamic Pages correctly:



Here is the code used in the video:

 

import { cart } from 'wix-stores'; export function addToCart_click(event) { let product = $w('#dynamicDataset').getCurrentItem(); let idProduct = product.productReference; $w('#shoppingCartIcon1').addToCart(idProduct) .then(() => { console.log("Product Added"); cart.showMiniCart(); }) .catch((error) => { console.log(error); }); }

 

Make sure you use the proper names that correspond with your elements on your page! Have Fun!