-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CartJS.cart.items delayed #174
Comments
Hi there, same problem here. I use the "success" callback to update my cart totals and it is always a step behind. It looks like there is a delay for update the CartJS.cart JSON? |
Hi @dhruveonmars and @KevinSupertramp, apologies for the delayed response on this. I have very limited time for Cart.js these days. If this is still an issue, can you please point me to a publicly-accessible Shopify site that reproduces the issue, ideally as a minimal test case (ie without lots of other third party libraries that may be causing the issue)? Sounds like there may be some caching issues going on, but I really need a good example case to be able to nut this one out. |
Hey @gavinballard sure. Will try and get a development site up soon that's publicly accessible and doesn't have the timeouts |
Hey @gavinballard, Sorry for the delay. I have a development version of the site I was building setup, and is publicly accessible. https://black-lines-development.myshopify.com/products/test-product. I need to remove the third-party libraries and the timeouts that were added |
Thanks @dhruveonmars! Is the JS code you're using for the sidebar rendering easily accessible? |
Hi @gavinballard I've added a console.log when you press the 'add to cart' button, so you'll be able to find the code. It looks like Shopify is reformatting the code on the theme publishing, so let me know if it's not quite so readable and easy to follow in the web inspector, and I can upload a copy of the theme.js file which has the 'add to cart' functionality. I have left the timeouts that were needed on the live store. Please have a look, and let me know if I should remove them |
Hey @dhruveonmars, currently looks like some CSS/JS issues on that development site. |
Hey @gavinballard, sorry about that. Fixed that so you can have a look now |
@dhruveonmars can you please try updating to v1.0.2 of Cart.js (just released) to see if the new cache-busting code addresses this problem? |
hey @gavinballard , I've been testing and it still seems to have a delay. 1.0.2 also seems to require rivets, but I didn't think it was required before |
Hi everyone, I'm using the latest version (1.1.0) and I can confirm this is still happening. |
I was able to quickly fix this - not the cleanest - but you'll get the "why" it's happening.
request.success.push(CartJS.cart.update); by request.success.unshift(CartJS.cart.update);
var cart_options = {};
if (options.success) {
cart_options.success = options.success;
options.success = [];
}
CartJS.Queue.add('/cart/add.js', data, options);
return CartJS.Core.getCart(cart_options); Simply because the loca cart.items is updated with the getCart function. I hope it makes sense! |
So when I log or run anything against CartJS.cart.items, it always seems to be a step behind CartJS.cart, and I'm not sure how that's possible.
For eg,
After adding an item to the cart, I want to update the cart in the header. To do this, I call a function
refreshSidecart();
inside the success function of the CartJS.addItem request.In refreshSidecart, I am able to log CartJS.cart, which shows the items correctly, however when I log CartJS.cart.items, I get an empty array logged.
If I press the add to cart button again, in the CartJS.cart items, it shows the correct details, with a quantity of 2, however in the CartJS.cart.items log, it only shows 1.
I added the following delay
And this seems to log the correct values.
I'm not sure what to do about this, as I would have thought that CartJS.cart.items would just be accessing the value of items inside CartJS.cart but any help would be greatly appreciated.
The text was updated successfully, but these errors were encountered: