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 ?
Thanks for your support,
regards,
Nicolas
Solved! Go to the solution
Hi @niko-paris ! Welcome to the Shopify Community forums.
What does updateCartDisplay do exactly?
Are you getting any errors in the console?
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
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
Hi @niko-paris
I am trying to replicate your situation, can I ask what Theme you are using?
Cheers
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!
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
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
User | Count |
---|---|
14 | |
12 | |
10 | |
8 | |
7 |