Store_availabilities available always shows true for store, even when there is 0 stock

Store_availabilities available always shows true for store, even when there is 0 stock

Forsel
New Member
4 0 0

For our store we have 2 inventories. One of them is a physical store where people can pickup their product, the other is not. I'm trying to use store_availabilities to check if the product is 'available' in our physical store so I can show that to my visitors. However the available flag is always true. Even if there is zero stock.

 

Why is that? And how do I fix it?

Replies 3 (3)

Liam
Community Manager
3108 340 871

Hi Forsel,

 

The available flag within the store_availabilities object might be indicating that the location (physical store in this case) itself is available for pick-up, not necessarily that the specific product variant is in stock at that location.

 

To check if a specific product variant is in stock at a particular location, you should use the inventory_quantity field within the inventory_levels object.

Here is an example:

{% assign location_id = YOUR_PHYSICAL_STORE_LOCATION_ID %}
{% product_in_stock = false %}

{% for inventory_level in product_variant.inventory_levels %}
  {% if inventory_level.location.id == location_id %}
    {% if inventory_level.available_quantity > 0 %}
      {% assign product_in_stock = true %}
    {% endif %}
  {% endif %}
{% endfor %}

{% if product_in_stock %}
  <p>This product is available for pick up at our physical store.</p>
{% endif %}

In this example, replace YOUR_PHYSICAL_STORE_LOCATION_ID with the actual ID of your physical store location. The above code will check each inventories for the product variant and if the product is available in the physical store, it will display a message.

 

Please note that you may need to adjust this code to fit your specific theme and setup.

 

Hope this helps!

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Forsel
New Member
4 0 0

Hi Liam!

 

Thanks for your response. However the code doesn't seem to work. When I check 'product' in the documentation it doesn't show the inventory_levels property.

 

Also, the documentation says for the 'store_availability' that the 'available' property shows if there is available inventory in the location. Which should mean I should be able to check that.

 

Thanks so far!

Forsel
New Member
4 0 0

Oh and sorry, there is also a flag in ‘store_availability’ showing true when pickup at the store is available, but that is separate from the ‘available’ flag as you can see in the link I provided