There seems to be an issue on every theme I try. At first I thought I messed up my code somewhere, but that doesn’t seem to be the case. In my case (video attached) I created a product with a stock of 5. I have 5 of them in the cart, both being unique because of the line property.
If I try to update one, it of course returns 422 due to stock. It works fine on the second item but when I try to do the same on the first item, al though it returns a 422, it still updates it once you refresh the page. I have tried everything, from using line, key, to using /cart/change.js to /cart/update.js. I always get the same result.
Please note it works just fine if there’s enough stock, as it should. Has anyone ever had a similar problem?
The problem is, is that they may be unique in the sense that they have inputs that tell you what to put on the product once sold, but the inventory you are using is just 1 line item. You put 5 in stock and are expecting more because of it being a different engravement? How would it know what the other stock should be if this was the case? What is your expected outcome? If these were truly unique in terms of the database, they would have two separate inventories that controlled them each individually. Lets say I have 50 necklaces in stock that are all the same but could be engraved. I would put this in as 1 inventory item. I can only sell 50 of these necklaces regardless of what the user decides to put on it. But personally that is exactly what I would expect and would hope for as the engraving is just a variable that could constantly change. There is no way to keep track of this in a feasible way unless you had a set number of variations and each one had their own inventory.
Hi! thanks for your input! No, actually we’re talking about the same thing! That’s why I attached the video, since it showcases my problem way better! Let me explain what happens in the video.
Basically I have set a stock of “5” for the item called “test”. This item however allow engravings - line properties. So I have 3 items in the cart, with engraving “A”, and 2 items with engraving “B”, both being product “test”. So yes, it indeed shares the same stock of “5”, meaning it should return a 422 when trying to increase the quantity of either of them! Sure, it does that on the second line item correctly (with engraving “B”). Meaning when you’re trying to increase it, a 422 returns, I refresh the page, all good. I still have 3 items with engraving “A” and 2 items with engraving “B”.
But problem occurs when I try to increase the quantity on the first line item, meaning the one with engraving “A”. I try to increase it to “4”, which again, it returns a 422, as it should, because there is not enough available stock. But when I refresh the page, I now have 4 items of engraving “A” and 1 item of engraving “B” in the cart. So as you can see it for some reason increased the quantity of item with engraving “A”, while decreasing the quantity of “B”. That shouldn’t have happened!
Now again, I face zero problems when having enough stock, meaning there’s no problem recognizing which is the correct item to either increase/decrease in quantity. Problem only occurs when there’s not enough stock left. Again, I tried several things, including using “line” and “item.key” as recommended by Shopify. Both outcomes are the same. Both work when there’s enough stock, but not when there’s not enough stock and you try to increase past that quantity!
The behavior you’re describing suggests that the shopping cart is not maintaining a clear distinction between individual product instances with the same item.variant.id but different custom engravings. Since they share the same item.variant.id, the cart might be treating them as the same product variant.
To address this issue, you’ll need to ensure that each individual product instance, even if they share the same variant ID, is uniquely identified in the shopping cart. One way to achieve this is by incorporating additional information, such as the engraving details, into the identifier.
Unique Identifiers for Each Item: Modify the data-quantity-variant-id attribute to include the engraving details or any other unique information. For example:
data-quantity-variant-id=“{{ item.variant.id }}-{{ item.engraving }}”
This way, even if the variant ID is the same, the engraving details will differentiate between individual items.
Custom Data Attributes:
If the engraving details are not suitable for inclusion in the data-quantity-variant-id, you could use custom data attributes to store additional information about the item. For example: data-engraving=“{{ item.engraving }}”
By ensuring that each individual product instance has a unique identifier in the cart, you should be able to maintain proper separation and avoid issues when adjusting quantities and refreshing the page. Ensure that you update both the input elements and any related JavaScript logic that interacts with the cart to use these unique identifiers.
They are identified as unique, I can see it in a JSON response as well (on load). Each item has it’s own unique properties and unique key, so no issue there. Like I said, they get identified correctly and just fine when there’s enough stock. Problem only occurs on when you try to add past the stock limit. I have now coded a simple “disable” button function when max quantity limit is reached for the item in the cart. Works great, but again, not optimal.