Access a community of over 900,000 Shopify Merchants and Partners and engage in meaningful conversations with your peers.
I'm probably like most partners and I find myself lurking around these forums more than posting in them. I thought I'd share a minor fix that might help others.
When performing an ajax post to /cart/add.js, I was getting a 422 error. This seems easy now, but it still took time to identify.
The issue is, when creating variants on-the-fly, I wasn't setting the inventory_policy value. The default for this value is 'deny'. This means that I would create a variant, the initial inventory would be zero, then the add to cart would fail because it's not allowed to be sold when there isn't inventory. In my case, I wanted to create the variant with an inventory_policy of 'continue' so that the variant could be added to the cart.
Like I said, seems easy now.
Hello @szuke ,
thank you for sharing, would you mind to share your code also ? It could help to see exactly what needs to be done 🙂
Kind regards,
Nicolas
This is an example from a python request, but the idea remains the same:
payload = "{\"variant\": {\"option1\": \"" + str(timestamp) + "\",\"price\": \"" + price + "\",\"inventory_policy\":\"continue\"}}"
Hi has anyone solved the Cart Error(422) error display? out of stock initiates this error on trying to add another out of stock item.
I'm not a coder so pls be gentle:-)
Hi, Thanks for sharing with us.
I am working on similar things and sending inventory_policy as continue. Changes has been reflected i can see in response but when i goto checkout it still shows "OUT OF STOCK".
if you anything about this please let know. Thanks
I tried to create a new variant and add it to the cart immediately. When I add the new variant to the cart, the new variant price, product image, options are gone as the 1st line item. The 2nd one is a working example. After I refresh the browser, it is showing the correct result again. How to resolve it? Any one?
User | RANK |
---|---|
5 | |
4 | |
4 | |
3 | |
3 |