-
1. Re: Outputting Individual Product Quantities with Liquid
Liam Dilley Oct 24, 2014 2:58 PM (in response to Daryl Barnes)Hey Daryl,
You do not need a for loop. Its an array of data so you can always just get a single item by getting that items index...
currentcart.items[0].quantity
-
2. Re: Outputting Individual Product Quantities with Liquid
Daryl Barnes Oct 24, 2014 3:04 PM (in response to Liam Dilley)Thanks! That works. But if I understand it correctly, the index value can change depending on which product was added to the cart first. So I want to select by a particular productId and then output the quantity. Is that possible?
-
3. Re: Outputting Individual Product Quantities with Liquid
Liam Dilley Oct 24, 2014 3:11 PM (in response to Daryl Barnes)Its early morning, I can remember off the top of my head if ID was in there for the summary. productID.id?
IF it is just do an if inside the loop per item Or an unless so it ignores the other products.
-
4. Re: Outputting Individual Product Quantities with Liquid
Daryl Barnes Oct 24, 2014 6:26 PM (in response to Liam Dilley)I figured it out and included assigning it to a variable as well so I can use it later. Hope this helps anyone else:
{% if currentcart.items[0].productId == 123456 %}
{% assign my_variable = currentcart.items[0].quantity %}
{% elseif %}
<%comment%> Other options here........ <%endcomment%>
{% endif %}
If you don't need to assign the variable you can just use this:
{% if currentcart.items[0].productId == 123456 %}
{{ currentcart.items[0].quantity }}
{% elseif %}
<%comment%> Other options here........ <%endcomment%>
{% endif %}
Works just fine but I really wish there was a more direct way of getting the quantity of a particular product in the cart. When I do {this | JSON } the Key Value pair is there so it should be easier. If anyone else has any ideas feel free to add them.
-
5. Re: Outputting Individual Product Quantities with Liquid
Liam Dilley Oct 24, 2014 6:27 PM (in response to Daryl Barnes)Hey Daryl,
I would store your variable first then use that there after..
{% assign my_variable = currentcart.items[0].quantity %}
{{ my_variable }}
And if you have only one follow on with your if you just need else not elseif because that will be looking for another condition in memory.



