Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

updating cart notes or attributes not working

updating cart notes or attributes not working

mashhadi
Visitor
1 0 1

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");

 

Replies 9 (9)

xinghul
Shopify Partner
7 0 0

this issue has been around for at least 6 years and they haven't fixed it yet.

darkAmdHa
Shopify Partner
4 0 3

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!

VladimirK89
Shopify Partner
13 1 4

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!!!

kiran9
Shopify Partner
5 0 1

can u please explain how did u made ur solution for this issue

VladimirK89
Shopify Partner
13 1 4

As in the previous post, I just delete the __ui from the local storage if it's there.

kiran9
Shopify Partner
5 0 1

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

VladimirK89
Shopify Partner
13 1 4

No, I haven't faced any issues since adding this, at least nothing was reported.

kiran9
Shopify Partner
5 0 1

I am facing an issue of cart-attributes missing for few orders..even though i kept them as required..does anyone face this issue?

EricH1
Shopify Partner
1 0 0

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.