Can't add to cart

Hello,
Anyone else with the same problem?
Yesterday it was working but now it isn’t and I haven’t change anything in this function. Thanks in advance

export function addProduct(event) {

$w(‘#cart’).addProductsToCart([{ “productID”: “7e61e2a8-76f4-1333-52a4-5fc0bb3cf61f”, “quantity”: 1}]); }

1 Like

The id name should be #shoppingCartIcon and not #Cart, so first simply try changing it back to what it was originally called when Wix Stores was added to your site and what is used in the code as well.

https://www.wix.com/corvid/reference/$w.CartIcon.html#addToCart

//rest of code//
$w('#myShoppingCartIcon').addToCart("ea77f230-558f-0ba565e8f827")
//rest of code//

Also, if you are only adding one product then you don’t really need the optional quantity in your code.

‘Use the quantity property of each AddToCartItem object that is passed to the products parameter to add more than one product unit to the shopping cart at one time. If quantity is omitted, one product unit will be added.’

I’ve tried to rename back to “shoppingCartIcon” and the error is still the same.

I’ve also opened in the editor the template linked in this article and it’s not working either and some days ago it was working.

I not use the AddToCartItem because the code below is a simple version of what the code is and was just for testing (the id is valid).

Today I check again and in the article de button is working but mine not

NOW only works when published

I have the same problem here! Some weeks ago it was working fine( I haven´t changed code), but now it just works when published!

Same issue here and Wix support was not helpful.
it was working perfectly on the 20th and then by the same time of this post I faced the same issue. I have been trying to crack it since then with no luck.
today I have started a new site and started testing and it is also not working.

any tips?

@aubmmt please update your code,
it supposed to be an array (or use addToCart for single item):

$w(“#widget2”).addProductsToCart( [
{ productID: “xxxxxx”, quantity: 1 }
] )

To add to Alexander’s post above, you should really be using something like a button click event to use the addToCart or addProductsToCart functions instead of the code line of ‘export function addProduct(event) {’ if you are just using it as it is on its own.

As mentioned in the tutorial linked from the original post and reply from hugomarinhodroid, the add to cart part is still a seperate button and the code used in the tutorial itself is setup to work with other parts of the code elsewhere, so you can not just simply take part of the code and expect it to work on your own site.

https://support.wix.com/en/article/corvid-tutorial-adding-multiple-items-to-the-cart-in-a-wix-stores-site#step-16-create-the-addtocartbutton_click-function-1

Step 16: Create the addToCartButton_click Function
The addToCartButton_click() function is wired to the add to cart button in step 3 of the customization process. The button is used to add the selected bracelet and charms to the store’s shopping cart.

export async function addToCartButton_click(event, $w) {
  let itemsToAdd = [{productID: selectedBracelet._id, quantity: 1, options: {}}];
  selectedCharms.forEach(function(charm){
    itemsToAdd.push({ productID: charm._id, quantity: 1, options:{} });
  });
  let res = await $w('#shoppingCartIcon').addProductsToCart(itemsToAdd);
}

Lines 2-4: Define the bracelet and charms to be added to the shopping cart.
Line 6: Add the bracelet and selected charms all at once to the store’s shopping cart.

Example site add to cart button

Editor add to cart button

Along with it being shown in the Wix API Reference for this as well.
https://www.wix.com/corvid/reference/$w.CartIcon.html

https://www.wix.com/corvid/reference/$w.CartIcon.html#addToCart

Add a product to the cart from a button click

$w("#myButton").onClick( () => {
  $w("#myShoppingCartIcon").addToCart("ea77f230-558f-0ba565e8f827")
    .then( () => {
      console.log("Product added");
    } )
    .catch( (error) => {
      console.log(error);
    } );
} );

Yes, I’ve been having this issue on 2 of my sites on different situations with google chrome browser. It’s been a nightmare as I have a sale going on and people can’t add to cart!!!

Sorry I am not a pro when it comes to these topics. But I am facing the same issue (cart disappeared on the chrome website, safari works) and I do not know how to solve it.