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
I also want to add this feature to my Shopify store. Can you guide me? I want to avoid using any external requests to maintain site load speed.
Hi @jj0980 Which feature do you want to add? We are talking about an issue here 🙂
We want to take a moment to celebrate the incredible ways you all engage with the Shopi...
By JasonH Oct 15, 2024Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024