show inventory per branch in product page

Davecott
Shopify Partner
6 0 1

Hello community

We have 2 branches (1 physical store, 1 supplier) I need to show the stock per branch, I am using the following code but it shows me the total stock

 

Available: 7

{%- for variant in product.variants -%}
{%- assign total_inventory = 0 -%}
{%- for inventory_level in variant.inventory_levels -%}
{%- assign total_inventory = total_inventory | plus: inventory_level.inventory_quantity -%}
{%- endfor -%}
{{ variant.title }}: {{ total_inventory }} en stock
{%- endfor -%}
<br>
{% for location in shop.locations %}
{% if location.active %}
<p>{{ location.name }}</p>
{% endif %}
{% endfor %}

 

I need it to display something like this:

Physical Store: 2 Available
Exclusive Internet: 5 Available

thanks in advance

Replies 3 (3)

Kalen_Jordan
Shopify Partner
338 12 47

I'm not seeing inventory_levels as a field available on the variant liquid object:

https://shopify.dev/docs/api/liquid/objects/variant

 

One way to do this would be to set up an automated flow to populate the inventory levels by location in a metafield on the product - and then you'd be able to pull it into that liquid there.

Kalen Jordan
Platform Advocate
MESA - Shopify Automation You've Love
Davecott
Shopify Partner
6 0 1

Yes, it is what I had planned to do, but since I manage more than 10k products it is a problem to be updating, since the supplier's stock varies a lot

Thanks a hug

Kalen_Jordan
Shopify Partner
338 12 47

If you're open to a 3rd party app, I should be able to build this workflow out for you using our app mesa. 10k products wouldn't be an issue.

Kalen Jordan
Platform Advocate
MESA - Shopify Automation You've Love