Error 404 when adding product to cart

Hi all,
I am quite new to coding with javascript.
I have created dynamic product configurator page using this example: https://medium .com/@jonathanz.dev/corvid-by-wix-setting-up-a-dynamic-store-page-with-product-configurators-799f2271e824
I am now trying to add a addtocartbutton using

const productId = “9a6c00d3-aac8-9959-a26e-43bbf982ac12” ;

export function addToCartButton_click ( event , $w ) {
cart . addProducts ([{
‘productId’ : productId ,
‘quantity’ : 1 //,
// ‘options’: { choices: selectedOptions }
}])
}

This is the error message I receive:


The strange thing here is that the ID in the error message and my defined ID do not match and I was not able to find the ID from the error message in any database.
Does anyone have an idea on how to solve this problem?

Edit: I also tried using this code:

export function addToCartButton_click ( event , $w ) {
$w ( ‘#shoppingCartIcon1’ ). addToCart ( productId , 1 /, {choices: selectedOptions}/ );
}
Here I don’t get an error message but it does not add anything to the cart. It just opens the cart upon pressing the button and shows the empty cart.

Edit again: This code also does not work:

const product = [{
“productId” : “9a6c00d3-aac8-9959-a26e-43bbf982ac12” ,
“quantity” : 1 ,
“options” : { “choices” : selectedOptions }
}]

cart . addProducts ( product )
. then (( updatedCart ) => {
// Products added to cart
const cartId = updatedCart._id ;
const cartLineItems = updatedCart.lineItems ;
})
. catch (( error ) => {
// Products not added to cart
console . error ( error );
});

Leaving me without any error message or anything else happening

You’re not alone! I was getting the exact same “Ambassador” 404 error coupled with the “cart fetch error” below on Monday. I was getting this randomly on all pages where I have cart.addProducts. (And this code has been functioning on my site for more than a year.) By randomly, I mean it was working fine sometimes for some users, and not working for others. Somehow, it just magically fixed itself without me adjusting the code (and a whole lot of cranky phone calls and emails to Support…I started out nice, but I’ve since learned that being nice & patient doesn’t get a response when it comes to Wix Support.)

There seems to be a pattern emerging with mine…once per week (usually Sundays, early Monday–exactly when everyone’s trying to order for the week.), and it lasts 3 to 12 hours. It also occurs alongside other major warnings, usually starting on the homepage, such as “Failure to load resource: 404” on the homepage, “Get site assets.parastorage(url) 404,” “DOMException: Failed to execute ‘importScripts’ on ‘WorkerGlobalScope…failed to import user code script,’” and a new one “Access to fetch at …siteassets.parastorage…has been blocked by CORS policy: No 'Access-Control-Allow-Origin header is present.”

The only thing that I did both times preceding these error events was add a cart onChange() function to the masterpage in order to count the number of items in their carts (for their cart icons). Granted, both times, these errors disappeared without me touching any of my code, so my theory about the cart onChange() doesn’t make much sense.

Yesterday night, and working completely in the dark and, admittedly, off of a gut feeling that is bereft of logical support, I decided to take down all code on my masterpage, nix all “cart onChange” usages, and track their item counts through addProducts/update Cart/etc. The changes are working fine now (although that change was stupidly tedious), however, I still doubt that it will really make a difference. Guess I’ll just wait till Sunday to watch my business be pulverized by Wix’s unreliability once again.

Anyways, are you using any cart onChange() functions or do you have anything having to do with the cart on your masterpage?? Also, has yours magically resolved itself?

Hi, thanks for your reply. I am sorry that you are having so much trouble using wix.
I have not published the site yet since I am not done with it and never made the cart button to work.
Before, I did not have an onChange() function in my masterpage. I now included it but i still receive the same error message with a productID that does not exist and has never been declared anywhere.