API call to /cart/add.js is not working when option "Enable automatic cart updates" is selected

Solved
niko-paris
Tourist
8 0 1

Hello,

After a very long investigation I have reached the conclusion that my API call to:

 

jQuery.post('/cart/add.js', items, updateCartDisplay)

 

is not working when the option "Enable automatic cart updates" is enabled in the cart section of the theme (Debut in my case)

Obviously the call is working and my application working properly when the option is NOT enabled

Question: Is this an expected behavior ? Is there any way to use the API even when the option is enabled ?

 

 

  Capture d’écran 2020-09-04 à 22.48.46.png

 

 

 

 

 

 

 

 

 

 

 

 

Thanks for your support,

regards,

Nicolas

 

0 Likes
BStubbs
Shopify Partner
124 14 45

Hi @niko-paris ! Welcome to the Shopify Community forums.

What does updateCartDisplay do exactly?

Are you getting any errors in the console?

Was this helpful? Press like!
Did it fix the problem? Mark it as the solution for others!
Buy me a beer? Well, sure!
0 Likes
niko-paris
Tourist
8 0 1

Hello @BStubbs ! Thanks for looking at my issue

UpdateCartDisplay is just a refresh (and logs)

function updateCartDisplay(data,status ){
  console.log("data added: " + data);  
  console.log("status: " + status);
  setTimeout("window.location.reload()",600);
  console.log(" cart display updated.");
}

I also use the promise to log errors:

  jQuery.post('/cart/add.js', data, updateCartDisplay).done(function(result) {
    console.log("cart update done.", result);
  })
  .fail(function(xhr, status, error) {
    console.log("cart update fail, error: " + error + ", status: " + status+", content: " + xhr.status );
  })
  .always(function() {
    console.log("cart update always.");
  });

I don't get much info in the logs:

cart update fail, error: , status: error, content: 0 cart:558:13
NS_ERROR_XPC_SECURITY_MANAGER_VETO: cart:563

 

0 Likes
niko-paris
Tourist
8 0 1

Hello @BStubbs a little update,

after looking more at the logs you asked I noticed that actually it is also the fail callback which is called when the option is disabled...

yet the API call is successfull in this case: the cart is updated and the page is refreshed....

So I if I can fix this and go through the done() callback instead of the fail() callback on my cart/add.js query maybe the cart will be updated whatever option is selected. The issue is that there is no clue in the logs about the failure... Is there any tool I could use here to get more info ?

regards,

Nicolas

 

0 Likes
BStubbs
Shopify Partner
124 14 45

Hi @niko-paris 

I am trying to replicate your situation, can I ask what Theme you are using?

Cheers

Was this helpful? Press like!
Did it fix the problem? Mark it as the solution for others!
Buy me a beer? Well, sure!
0 Likes
niko-paris
Tourist
8 0 1

Thx a lot @BStubbs , I am using the theme "Debut".

regards,

Nicolas

0 Likes
BStubbs
Shopify Partner
124 14 45

Hi @niko-paris 

Did you get anywhere with this?

I have just noticed a similar error coming up on a Debut theme, seems uncanny that its basically the same issue you are having, just a few days later? The system was working fine until this point.

Weird!

Was this helpful? Press like!
Did it fix the problem? Mark it as the solution for others!
Buy me a beer? Well, sure!
0 Likes
niko-paris
Tourist
8 0 1

Hello @BStubbs , no I'm still trying to understand why the "fail" callback is always called and without any error...

Do you also go through the "fail" callback in your case ?

 

regards,

Nicolas

 

0 Likes
BStubbs
Shopify Partner
124 14 45

This is an accepted solution.

Hey @niko-paris ,

Just to let you know how I fixed my issue. I moved over to the fetch API instead. Long story short, there were multiple versions of jQuery on the shop, so I am making the assumption that there was a problem with conflicting versions. Depending on if it is jQuery 2 or 3, it will have different promises, so that could be the reason why it is always failing? Anyway, fetch is working great, so I'm going to probably use that for most things going forward.

Cheers

Was this helpful? Press like!
Did it fix the problem? Mark it as the solution for others!
Buy me a beer? Well, sure!
niko-paris
Tourist
8 0 1

Thx a lot @BStubbs ! That's a good advice, i'll try to apply it !

kind regards,

Nicolas