Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capture all products in Shopify collection

Tags:

shopify

liquid

As I'm looping through a collection in Shopify, I want to add that product to another array of products so that I can loop through it again.

{% assign custom_products = '' %}
{% for product in collections['all'].products %}
    {% assign custom_products = custom_products | append: product %}
{% endfor %}

But when I iterate through it again I get nothing

{% for product in custom_products %}
{% endfor %}

When I dump custom_products I get ProductDropProductDropProductDropProductDrop... and so on. Is this because I am constructing as a string? I want the second for loop in the Liquid template to move through the products as if it were collections['all'].products. Any ideas?

like image 537
JLF Avatar asked Oct 29 '25 09:10

JLF


1 Answers

{% capture custom_products %}
  {% for product in collections['all'].products %}
    {{ custom_products }},{{ product.handle }}
  {% endfor %}
{% endcapture %}

{% assign custom_products = custom_products | split: ',' %}

{% for product in custom_products %}
  {{ all_products[product].title }}
{% endfor %}
like image 64
HymnZzy Avatar answered Oct 31 '25 12:10

HymnZzy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!