How can I get the remaining quantity when a bundle component is not enough?

I use the cart transform expand operation to build custom bundles, e.g. select 18 cupcakes to get 10% off.

Let’s say the customer adds 10 chocolate cupcakes, but only 8 are available, the cart API error response will show:

The product ‘{{ parent-product.name }}’ is already sold out.

Can you give me the available quantity? I want to tell the customers to remove 2 chocolate cupcakes and continue, or I will remove 2 for her. Now, the error message will tell customers to leave, which is not satisfactory.

However, I see no way to get this quantity or even the bundle component name. Is there any feasible way? I need both the product variant name and the quantity

The storefront API may be able to do so. But it’s too heavyweight for this particular use case. Also, checking all item quantities may slow down the add to cart action.

Hello, this requires a bigger change since it’s part of the Cart API which will affect other areas than custom bundles.

Can you do something in online store that displays the available quantity?

What are the possible ways? I think Shopify intentionally hides the inventory quantities

Can you use Liquid API’s variant.inventory quantity as a workaround?

2 issues here:

  • The inventory_quantity is not found in a variant if the variants are printed with the json filter, i.e. variants: {{ product.variants | json }}
  • This quantity is loaded when the page is opened. If the customer stays on the page for a while, it doesn’t update