Ajax API allows out of stock products to be added without 422 error, and corrects after following requests

There’s a store where their recommended products can be added to cart, even if they are out of stock, and the “continue selling when out of stock” setting is inactive.

For some reason, after following Ajax API requests (like /add or /update), the cart still shows these out of stock products in the items array, but with quantity: 0.

Example:

 {
      "id": 51294307451222,
      "properties": {},
      "quantity": 0,
      "variant_id": 51294307451222,
      "key": "51294307451222:607d828368faf72c2987cdbca9bdfc9c",
      "title": "Monalisa - Navy - 34",
      "product_title": "Monalisa - Navy",
      "variant_title": "34",
      "price": 0,
      "original_price": 0,
      "discounted_price": 0,
      "line_price": 0,
      "original_line_price": 0,
      "presentment_price": 0,
      "total_discount": 0,
      "discounts": [],
      "sku": "0225-2090-86\\50\\34",
      "grams": 700,
      "vendor": "Junge",
      "taxable": true,
      "product_id": 9815705944406,
      "product_has_only_default_variant": false,
      "gift_card": false,
      "final_price": 0,
      "final_line_price": 0,
      "url": "/products/monalisa-kv-86-navy?variant=51294307451222",
      "featured_image": {
        "alt": "Junge Monalisa Kv. 86 50-Navy",
        "aspect_ratio": 0.667,
        "height": 1499,
        "url": "...",
        "width": 1000
      },
      "image": "...",
      "handle": "monalisa-kv-86-navy",
      "requires_shipping": true,
      "product_type": "Kv. 86",
      "untranslated_product_title": "Monalisa - Navy",
      "product_description": "...",
      "untranslated_variant_title": "34",
      "variant_options": [
        "34"
      ],
      "options_with_values": [
        {
          "name": "Størrelse",
          "value": "34"
        }
      ],
      "line_level_discount_allocations": [],
      "line_level_total_discount": 0
    },

Does anyone know what could be causing this? Or is this some internal Shopify bug? If anyone from the team at Shopify wants to see the bug, reach out to me and I’ll send you the store link (for the merchant’s privacy).

Any insight is appreciated, thank you!

What type of topic is this

Bug report

Can you proceed with the checkout process? Actually, it should be correct if you cannot continue the checkout flow —I think there’s an issue with your theme code.

@Eric_Han That’s the thing, the checkout shows that the product is out of stock immediately.

This can’t be correct because the /add is not responding the 422 out of stock error as it should be, and after that the item starts appearing as quantity: 0. Not in the theme UI, but in the cart returned from the Ajax API itself.

I’m not reporting that the customer is able to place an order with an out of stock product, I’m reporting that the AJAX API is not working properly. Does that make sense?

I tested it in the same scenario and found that /cart/add.js cannot add variants without inventory, while other variants with inventory can be added normally.

@Eric_Han that’s exactly the point of my post Eric: in the particular store I’m talking about, the API doesn’t respond that 422 error, even though the product doesn’t have inventory.

Hi there,

I’ll have a look at our logs to see if it reveals anything about this issue.

Will send a DM requesting store information :slight_smile:

If anyone else encounters this issue, please contact support directly at help.shopify.com. This way we will be authorized to access the store in order to properly investigate the issue.