Copy link to clipboard
Copied
With liquid we have better control over the system's output and use it to tweak system's behavior. One such scenario is if variations are enabled for a product how can we display/hide the variations that has inStock value 0. Via BC system setup, we can hide a product when its inStock value becomes 0, that means, when all the variations inStock value becomes 0. But using liquid we can hide the variation options that has inStock value 0.
Add the code on the attached link to the product large layout:
http://dhell.businesscatalyst.com/productinventoryupdate.png
Note: The code works but with two conditions:
1) There is ONLY ONE SET of the attributes, screenshot: http://prntscr.com/di898h
2) The attributes MUST be set to Radio List: http://prntscr.com/di89ru
In the Adobe code, we are first looping through the inventoryByAttributes array to fetch if a variations inStock value is 0, if yes, then we are using javascript to target that variation to hide it.
Hope this helps.
Regards,
Gaurav Aggarwal
Message was edited by: gaurav aggarwal
Copy link to clipboard
Copied
Hiho
I´m also trying to hide product variation with inventory control enabled. Using {{inventoryByAttributes}} doesn´t do the trick. Buy button doesn´t work when you are using this object... this is only usable for display purposes and have no functionality. Am I wrong? I hope so
Why script and display: none?
You can ask for items that are enabled AND have a inStock value > 0.
Like so:
<ul>
{% for i in inventoryByAttributes -%}
{% if i.inStock > 0 and i.enabled == true -%}
<li>id: {{i.id}}, inStock: {{i.inStock}} do something more here... </li>
{% endif -%}
{% endfor -%}
</ul>