Hi there,
We have an app in production for almost two years now. For the app to work, we rely on the jQuery wrapper for the Shopify Javascript API.
What we have been using is the cart attributes object. A couple of days ago we noticed that the JS API has stopped behaving the way it did before.
Previously, and working from the information in this thread http://ecommerce.shopify.com/c/shopify-apps/t/cannot-update-cart-attributes-before-adding-a-product-to-a-cart-37095 we embraced the logic of having to 'initialize' the cart before being able to store anything in the attributes object. Fair enough, so we did. When we need to add some cart attribute, we just added a product, removed it, and then stored the attributes. Worked fine until now.
Right now, we can't seem to store anything in the cart attributes unless something is *permanently* in the cart.
To prove this point, and to save everyone from having to read the extra logic we added to the Shopify jQuery API Wrapper, I'll just use the API sandbox here: http://mayert-douglas4935.myshopify.com/pages/api
I recommend using either Firebug or Chrome's developer tools to be able to have a look at the API calls responses.
Here's the issue:
1. Click on Shopify.getCart(). The response will display a completely empty cart object.
2. Click on Shopify.updateCartAttributes() entering some key/value of your choice. It returns the cart object with a new token and the correct attributes in the cart.
3. Click on Shopify.getCart() again. Empty cart again. No attributes there. Not even the token.
If we consider the logic in the thread I linked above, meaning we need to initialize the cart by adding / removing an item, let's see what happens:
4. Click on Shopify.addItem() using a variant_id that is in stock. It will respond with the correct line item of the cart.
5. Click on Shopify.getCart() again. The response shows the correct cart object, with the variant we just added and, oddly, with the cart attributes we entered in step 2.
(Note: in this example I opted to not enter any attribute, because it is already there. But you can do so and verify that the end result will be the same)
6. Click on Shopify.removeItem() using the same variant_id. It will respond with the correct cart object - variant removed, correct cart attributes.
7. Click on Shopify.getCart() again. Empty cart. No token, no attributes.
To me, this is a really odd behaviour, especially because we have seen this work flawlessly for almost two years. It almost seems that there is some kind of weird caching behaviour when the cart has no items..
What is causing this? How can we work around this? Any ideas would be very welcome.
Thanks,
Rui Leitão.