Doing Inventory Quantity the "Best" Way with POD Products

Solved
Excursionist
13 0 2

Hello - I am opening a procuts store (apparel, prints, mugs etc) and using a few different print-on-demand vendors for fulfillment (currently using the Supply theme). I'd like to be able to have some products be "limited quantity," which means I'd limit my production and sales of a POD product to a limited number (say, 50). I know there are some paid apps that can do this type of thing, but was hoping code additions could do it. On this board I found this post which got me the code so I can have the inventory numbers appear on the Products page, and the Collection grid.

 

So my question is:

 

1) When I have a product that IS NOT going to show as a limited quantity (like I'll sell as many as I can over time), how can I get the inventory number NOT to show up? See this example where one product shows the remaining quantity, but the other, where I removed the inventory tracking for that variant, it shows as "zero." That's what I need to fix, or is using an app the only/best way?

 

Screen Shot 2019-09-11 at 1.45.18 PM.png

0 Likes
Explorer
51 6 20

Hey so if I understand correctly you want to display the limited quantity only on your special limited quantity items, then if you have a normal product you will just sell it forever and you don't want it to show the inventory quantity.

 

If that is correct you could do this with a simple liquid if statement and either a product tag or metafields. I saw from your original post you had this:

  <p>      	{% assign total=0 %}
      	{%for variant in product.variants %}
      	{% capture i %}{{ total | plus:variant.inventory_quantity }}{%endcapture%}
      	{% assign total = i %}
      	{%endfor%}
      	<b>Total Qty Avalaible : </b>{{ total }}
      </p>

So if you wanted to do it by tag you could do something like this:

{% assign total=0 %}
<p>      	
	{%for variant in product.variants %}
	{% capture i %}{{ total | plus:variant.inventory_quantity }}{%endcapture%}
	{% assign total = i %}
	{%endfor%}
	{%- assign isLimited = false -%}
	{%-for tag in product.tags-%}
		{%-if tag contains 'limited'}
			{%- assign isLimited = true -%}
		{%-endif-%}
	{%-endfor-%}
	{%-if isLimited-%}
	   <b>Total Qty Available : </b>{{ total }}
	{%-endif-%}
</p>

So in this case only products that have the tag limited will actually display the quantity remaining. You just then need to add the limited tag to any items you want to be limited time purchase. If you want to see how this could be done with product metafields let me know and I can provide that as well. Also fixed the typo with available.

1 Like
Excursionist
13 0 2

Hey thank you so much for the help! BUT I'm getting an unexpected character error when I add this to product-template.liquid:

 

Also should "{% assign total=0 %}" be outside of the p tag like that?

 

Screen Shot 2019-09-11 at 4.41.18 PM.png

 

0 Likes

Success.

Explorer
51 6 20

Oops my mistake I rushed when writing that this is what the code should be:

{% assign total=0 %}
<p>      	
	{%for variant in product.variants %}
	{% capture i %}{{ total | plus:variant.inventory_quantity }}{%endcapture%}
	{% assign total = i %}
	{%endfor%}
	{%- assign isLimited = false -%}
	{%-for tag in product.tags-%}
		{%-if tag contains 'limited'-%}
			{%- assign isLimited = true -%}
		{%-endif-%}
	{%-endfor-%}
	{%-if isLimited-%}
	   <b>Total Qty Available : </b>{{ total }}
	{%-endif-%}
</p>

I forgot to add the closing % for the if tag contains line. 

 

For the assign total it doesn't matter where that is it is just creating a variable I prefer to put it outside the p tag because I find it easier to read. The only important thing is that it is before that first for loop, since that loop is accumulating your total. Let me know if there are any more issues with the code!

1 Like
Excursionist
13 0 2

Thank you @michaelPeterson! very much appreciated. Seems to work great - one last question ;) Since I will be doing this on shirts which have multiple variants (S, M, L etc), is there a way in Shopify to use a total inventory number across all variants, as opposed to say, 5 smalls, 5 mediums etc.

 

I'm getting this now - where the customer would get a warning for only 5 left, but the "real" number I'll limit it is at 30 for the entire design run.

 

Again THANK YOU!

Screen Shot 2019-09-11 at 5.08.12 PM.png

 

0 Likes
Highlighted
Explorer
51 6 20

No worries glad it worked! I was kind of worried since I rush wrote that code before heading home. Anyways just to be clear so you would rather display total inventory across all variants for the product and not the inventory of each individual variant? I ask only because both ways are possible, the reason it is showing just per variant is because the liquid is setup to get that inventory value per variant. With that said though the code you showed earlier was grabbing the total inventory value for all variants of the product. You could use code similar to that on your product page.

 

If you wanted you could set it up so that it does display the variant inventory quantity when a user selects a variant the only catch is that would require JavaScript. The best way to do that would be to find your code in the theme.js file that handles your variant changes and add a function that will change that text to match the inventory quantity of the variant. So either way is possible it is just up to you how deep into the matrix you want to go and what you need. If you want to have a dynamic update for your variants you can send me a message and I can provide my email and you can send me your theme files and I can help figure out what code you would need to add to your theme.js file.

1 Like
Excursionist
13 0 2

What I'd like is for, say, a T-Shirt – if I do a limited run of 50, then ONLY 50 shirts of any size/variant would be sold, period. Now that I'm looking at my product page, I'm thinking my trouble isn't with your code, that seems to be doing the right job, but in the Supply Theme's variant remaining message (you can see here "Only 5 left.") I set my quantities to 5 each of 6 variants for this shirt to get/show a total of "30 Left." Yeah, I'm thinking this is maybe not the easiest thing tackle now that I see what's happening.

 

Screen Shot 2019-09-12 at 11.19.55 AM.png

 

I'll DM you, but don't want to impose, you've already been such a great help!

0 Likes