Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
I've observed an issue with the unique key value of cart line items when manipulating multiple products in a single request using Shopify's CART API. Tested on multiple stores and same behavior. Here's how you can replicate this behavior (see pictures):
During this process, I noticed that the unique key value for each line item changes after the second request. However, after second request, the line item key remains consistent in all subsequent requests.
Docs:
https://shopify.dev/docs/api/liquid/objects/line_item#line_item-key
https://shopify.dev/docs/api/ajax/reference/cart
I'm uncertain about the duration of this issue, but I recall that around six months ago, the unique key values for line items remained consistent across all requests.
Here's code snippet for testing:
let formData = {
"items": [
{
"id": PLACE_VARIANT_ID_1,
"quantity": 1,
},
{
"id": PLACE_VARIANT_ID_2,
"quantity": 1,
},
]
}
fetch(window.Shopify.routes.root + 'cart/add.js', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(formData)
}).then(response => {
return response.json();
}).then(data => {
data.items.forEach(obj => console.log(obj.key));
})
I have the same issue in my stores. I need to update the quantity on some products when customers update the quantity on others, and this issue is affecting the first quantity change, as the item key becomes different. In the subsequent changes it works fine, but the quantities are not synced anymore because the first change returns different item keys and it needs to update the other product quantity correctly to everything works fine.
I have exactly the same issue. Adding a product to the cart using the cart.js api.
Then trying to remove the item from the cart by clicking the link generated by the {{item.url_to_remove}} results in a Shopify error:
'no valid id or line parameter'
If I refresh the cart page, the key (and generated remove link) then changes, and I'm able to remove the item from the cart. I'm not sure why this would be as the docs state that the key is a hashed version of the properties, which are always blank in my case.
Must be a Shopify bug.
I'm experiencing an issue with line item keys in Shopify. The key seems to be changing based on whether a discount is applied to the line item or not.
Here's what I'm observing:
In essence, the line item key keeps switching back and forth depending on the presence or absence of a discount.
I would appreciate it if Shopify could investigate this behavior and consider potential solutions for ensuring consistent line item keys across discount scenarios.
Facing similar issue:
1. Trying to update `attributes` in the cart with `update.js` api.
2. Key of the items present in the cart changes.
3. Because of this when I try to remove item from cart with `change.js`, it gives 400 with message `no valid id or line parameter`.
4. Once I refresh and then try to remove item from cart, it works.
Same issue here. The item.key changes on existing products in the cart for me anytime a new product is added. As these keys are used to manage connections between products in the cart this is causing issues. Hopefully someone from Shopify can confirm if this is expected behaviour as it appears it wasn't in the past.
Hi guys,
I had reached out to the Shopify Support and they have now fixed the issue. Could you guys please check and confirm?
Yes, the issue has been solved now. Thanks 👍
Thank you.
🙏
Thank you 👏
Yap, now its working
How did you managed to contact Shopify Support?
You can send your queries here -- https://help.shopify.com/en/support/partners/
They are very responsive.
Thanks KaustuvDhungana,
Key seems to stay the same when other products are added or removed from the cart but I'm seeing the key change when the quantity of the item is increased/decreased. Does anyone know if this expected behaviour? The item key changing seems to limit it's usefulness.
Thanks,
Darren
Hi Darren,
I just checked a couple of my stores and the keys seem to be consistent even when the quantity is updated. Could you please check again or provide me your store url so that I can check once.
Thank you.
- Kaustuv
Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024