Calculating and displaying inventory count for specific product variants

Hi all

 

I'm currently attempting to calculate and display the combined inventory of certain variants in a collection.

 

Basically I design and make bags and offering a limited number of a custom product that is available in four sizes.

 

I have the first product option set up as the fabrics, so I want to only use the variants with a fabric description that contains "Custom", which is also the first variant in each product though may not always be the case (I might make another fabric the first viewed in the future).

 

So I'd like to get the inventory value for these variants from the four products, add them together and display them as an announcement like "35 of 50 limited edition products available", and when these products are purchased the count goes down.

 

I've tried using the code:

 

{% assign counttotal = 0 %}
{% for product in collections.ttthings.products %}
  	{% if product.variant.option1 contains 'Custom' %}  
		 {% capture customcount %}{{ product.variant.inventory_quantity }}{% endcapture %}
                {% capture tempcount %}{{ counttotal | plus: customcount }}{% endcapture %} 
    {% endif %}
    {% assign counttotal = tempcount %}
{% endfor %}
{% assign ttthing_count = counttotal | plus: 0 %}

Though not getting any result at the moment ....

 

I suspect I've done something very minor that is throwing things off.

 

Any suggestions would be greatly appreciated :) 

 

Matt

0 Likes