Possible bug with "out of stock" handling of products added to the cart with line item properties

Justin66
Tourist
5 0 2

It seems that there may be a bug with the /cart/add.js endpoint when adding products that:

  • have inventory enabled
  • do not allow customers to purchase the product when it's out of stock
  • have a line item property in the add to cart request

The issue is that you can add more than the available quantity so long as you provide a new unique line item property with the add to cart request (i.e. create a new line item).

To reproduce:

  1. Create a product with Inventory Policy: Shopify, inventory: 3, allow customers to purchase this product when it's out of stock (unchecked)
  2. Add all available quantity: $.post('/cart/add.js', {id: 702152101, quantity: 3}) and get an expected successful response
  3. Try to add one more $.post('/cart/add.js', {id: 702152101, quantity: 1}) and get an expected failure response: {"status":422,"message":"Cart Error","description":"All 3 Test Product are in your cart."}
  4. Now add the same product, but with a line item property: $.post('/cart/add.js', {id: 702152101, quantity: 1, properties: {hello: 'world'}}) and get an unexpected success
  5. Add that same product/line item property another three times and you'll get a successful add to cart for the first two, and then finally a failure on the third.

Basically it looks like Shopify is treating stock availability by line item, rather than by product variant id. Anyone else ever encounter this? Is this the expected result from the Shopify servers, or might it be "fixed"?

Thanks!

VladimirC
Shopify Partner
7 0 1

Have you done anything with that since then?

0 Likes