bug in addToCart API

I’m trying to use an add to cart button using the addToCart API. The product to be added to the cart has an option category call “Anti-Aging” with the following 8 options;
“Vitamin A & Vitamin B3 & Coenzyme Q10”, “Vitamin B3 & Coenzyme Q10”, “Vitamin A & Coenzyme Q10”, “Coenzyme Q10”, “Vitamin A & Vitamin B3”, “Vitamin B3”, “Vitamin A”, “None”.

The add to cart button works well for all options other than those containing Vitamin A (e.g. works for option “Vitamin B3”). For any options which include Vitamin A (e.g. Vitamin A & Vitamin B3"), the cart opens on the right hand side of the page, but no product is added.

The url is https://www.giadaskincare.com/quiz-1 and the code I am using is below. Can Wix look into this to try and fix the issue, as it seems like the issue is on Wix’s side?

$w(“#shoppingCartIcon1”).addToCart(“f40e3741-5c56-a54e-f4a8-6ee5ad994200”, 1, {
“choices”: {

“Anti-Aging”: “Vitamin A”, “Rejuvenating & Soothing”: “None”, “Lifting & Firming”: “None”, “Blemish Reduction”: “None” },

“customTextFields”: [{
“title”:“Who is the custom cream for?”,
“value”:“John”}]}

)

Is anyone from wix able to look into this?

@alexander-wix is someone from wix able to look at what’s causing this issue?

1 Like

Can anyone from wix tell me if this is a bug, and how it can be fixed?

This is still unresolved…

Hi,
It seems like you’ve added the product options incorrectly. Here’s an example of how to add a product with multiple options:

let selectedOptions = {
Body:{choices:
[{value:"Plus Pattern",
description:"Plus Pattern",
inStock:true,
visible:true,
mainMedia:"wix:image://v1/614034_103e8f4ab0ae4536a38b319d3eb437ed~mv2.png/missing-media.png#originWidth=500&originHeight=500",
mediaItems:[]}]},

Sleeves:{choices:
[{value:"Dot Pattern",
description:"Dot Pattern",
inStock:true,
visible:true,
mainMedia:"wix:image://v1/614034_103e8f4ab0ae4536a38b319d3eb437ed~mv2.png/missing-media.png#originWidth=500&originHeight=500",
mediaItems:[]}]},

Neckline:{choices:
[{value:"Lavender",
description:"Lavender",
inStock:true,
visible:true,
mainMedia:null,
mediaItems:[]}]},

Pocket:{choices:
[{value:"Dot Pattern",
description:"Dot Pattern",
inStock:true,
visible:true,
mainMedia:"wix:image://v1/614034_103e8f4ab0ae4536a38b319d3eb437ed~mv2.png/missing-media.png#originWidth=500&originHeight=500",
mediaItems:[]}]}}
    
$w('#CartIcon').addToCart("f40e3741-5c56-a54e-f4a8-6ee5ad994200", 1, selectedOptions )
  .then( () => {
    console.log("Product added");
  } )
  .catch( (error) => {
    console.log(error);
  } );

I recommend checking out our Product Configurator example to learn how to add a product with multiple product options.

Good luck,
Tal.

1 Like

Thanks for replying - I really appreciate it.

It’s still not working. Having taken your advice and read the product configurator example, I updated the code as follows. Any ideas what’s going wrong?

export function button1_click(event) {
//Add your code for this event here:

let selectedOptions = {

“Anti-Aging”:{choices:
[{value:“Vitamin A”,
description:“Vitamin A”,
inStock: true ,
visible: true ,
mainMedia: null ,
mediaItems:}]},

“Rejuvenating & Soothing”:{choices:
[{value:“None”,
description:“None”,
inStock: true ,
visible: true ,
mainMedia: null ,
mediaItems:}]},

“Lifting & Firming”:{choices:
[{value:“None”,
description:“None”,
inStock: true ,
visible: true ,
mainMedia: null ,
mediaItems:}]},

“Blemish Reduction”:{choices:
[{value:“None”,
description:“None”,
inStock: true ,
visible: true ,
mainMedia: null ,
mediaItems:}]}}

$w(“#shoppingCartIcon1”).addToCart(“f40e3741-5c56-a54e-f4a8-6ee5ad994200”, 1, {“choices”: selectedOptions},
{“customTextFields”: [{
“title”:“Who is the custom cream for?”,
“value”:“John”}]}
)
}

Tal - can you see anything wrong with the code I’ve added? I’m convinced this is either a simple syntax error or a bug in wix API. It’s so frustrating, as I’ve been trying to fix this for months.

Any help appreciated.

John :slightly_smiling_face:

Tal - are you able to assist on this? Thanks

I have now confirmed with multiple external consultants/developers that the error is on wix side - can wix please fix this ASAP??

The most simple form of the issue can be observed by clicking the button at the following link:

https://www.giadaskincare.com/copy-of-new-page

The code from the page on the link is below. The issue is that this code does not add any product to the cart.

Please let me know the timeline for getting this fixed.

export function button1_click(event) {
//Add your code for this event here:

$w(“#shoppingCartIcon1”).addToCart(“f40e3741-5c56-a54e-f4a8-6ee5ad994200”, 1,{ choices:

{“Anti-Aging”:“Vitamin A”,
“Rejuvenating & Soothing”:“None”,
“Lifting & Firming”:“None”,
“Blemish Reduction”:“None”}}

)
}

Hi,
The example works fine so there’s no bug with the API. The product options of your product mentioned in the ProductOptions:

You should copy the same attributes with the same values of the selected product option. You can get the JSON object here:


In order to view it properly, I recommend using the JSON viewer site . Note that in your code you haven’t copied the mainMedia value of the selected option. This may cause the issue.
Please re-check the JSON value you were trying to add to your cart and make sure that all the values are the same as described in your collection.

Good luck!
Tal.

Hi Tal

To highlight the issue in the simplest form, I have created a page on my site which includes a button which triggers the issue, at the following url:

https://www.giadaskincare.com/copy-of-new-page

I have also re-written the code to use the simplest form of the AddToCartOptions object. When entering AddToCartOptions I have used key:value pairs for each selected option. Note, this is exactly as specified in the Wix API reference guide (CartIcon - Velo API Reference - Wix.com) and in the “print on demand” example (https://www.wix.com/code/home/example/Print-on-Demand).

I am certain this is an issue on Wix’s side, as I have tested the code with other products and other sites, and the code works fine.

The new simplified code is presented below. Can you, or someone else from Wix, please look into fixing this issue ASAP? I’ve been trying to get this resolved for months, and it’s really frustrating.

Thanks

John

export function button1_click(event) {

$w(“#shoppingCartIcon1”).addToCart(“f40e3741-5c56-a54e-f4a8-6ee5ad994200”, 1,{ choices:

{“Anti-Aging”:“Vitamin A”,
“Rejuvenating & Soothing”:“None”,
“Lifting & Firming”:“None”,
“Blemish Reduction”:“None”}}

)
}

@yisrael-wix any update available on this? Thanks

QA opened a ticket for this issue. Hopefully a fix will be available soon.

Hey John,
Please see my sample - based on yours site https://screencast.com/t/GkNS3XTzt
https://jdanov-qa.wixsite.com/copy-of-mysite/copy-of-new-page - click the yellow button
Here is my code sample:

$w.onReady(function () {
    $w("#button2").onClick(() => {
        $w("#shoppingCartIcon1").addToCart("f40e3741-5c56-a54e-f4a8-6ee5ad994200", 1, {
 "choices": {
 "Anti-Aging": "Vitamin B3",
 "Rejuvenating & Soothing": "None",
 "Lifting & Firming": "None",
 "Blemish Reduction": "None"
                }
            })
            .then(() => {
                console.log("Product added");
            })
            .catch((error) => {
                console.log(error);
            });
    });
});

Regarding the problem with “Vitamin A” option - it’s wired, will check it with dev guys.

1 Like

@alexander-jdanov Thanks for the above. I have always been able to get the code to work for most product options, but the issue is only with certain options. For example, and Anti-Aging options which includes “Vitamin A” does not work. I have been trying to resole this for the last few months, but nobody can seem to figure out what the underlying issue is. Hopefully the dev guys can help. Thanks. John.

1 Like

@johndavidbarkwith Issue has been solved, verified on your site - looks ok. Please confirm.

2 Likes