Discussing APIs and development related to customers, discounts, and order management.
I'm using Cart APIs to update cart notes and attributes, the API returns back successfully and if I make a GET request it shows that the properties are updated, but as soon as I move to the next step in check out all of my edited attributes are reset, I tried editing properties of line items as well in hopes that it will work but even they get reset.
I thought maybe they will be saved so I processed a whole order and checked on Shopify admin dashboard as well. but there are no attributes / notes present
not sure how to fix this
Example :
jQuery.post('/cart/update.js', "attributes[eid_gift]=Yes");
this issue has been around for at least 6 years and they haven't fixed it yet.
For anyone still looking for a fix,
There's a variable called "__ui" that is saved to local storage that seems to be created the first time you head to checkout. It stores the notes variable that the cart had the first time it went to checkout. So for customers returning from checkout, even if they update the notes, it seems to be restored to the previous value once they head to checkout(you can check this by hitting the /cart.js endpoint on checkout)
If you intend to update the notes attribute for whatever reason every time the user tries heading to checkout, add some code to detect this variable and delete it. Something like
if(localStorage.getItem('__ui'))
localStorage.removeItem('__ui')
Seems like a destructive approach, but I couldn't find a better solution.
Cheers!
Blimey! I spent half a day figuring out what was wrong with updating the cart note... Thank you for pointing out this!
Shopify, you can do better!!!
can u please explain how did u made ur solution for this issue
As in the previous post, I just delete the __ui from the local storage if it's there.
ok..it is working..but will the removal of this local storage property makes any adverse effects to any other functionalities ..?please let me know if you have faced any issues after making this change
No, I haven't faced any issues since adding this, at least nothing was reported.
I am facing an issue of cart-attributes missing for few orders..even though i kept them as required..does anyone face this issue?
My problem was line items not being update/deleted properly. Every time a customer returned to the cart page, the old items would be added on top of their new ones.
DarkAmdHa's solution didn't work for me because I couldn't find __ui in my localStorage -- it's possible Shopify stopped using it.
What DID work for me was deleting the "cart" cookie prior to adding/updating the new line items:
document.cookie = 'cart=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
This essentially forces Shopify to create an entirely new cart and cart cookie, which can then be updated with the normal Cart API endpoints.
No clue whether this has side effects like impacting abandoned cart features, but I couldn't find any other workarounds.