Liquid - Filter Array of Products using properties

Solved

Liquid - Filter Array of Products using properties

ap5356
Shopify Partner
8 2 2

I would like to filter an array of products using values from the "properties" field. Specifically so in the cart with line_items. 

I am currently trying to use the "where" filter, to only include products with the property of "group-id". Ideally, this would be as easy as:

{% assign filtered_items = items | where: 'properties.group-id' %}


But from trying this, and searching around in the documentation and online, it doesn't look like others were able to get it to work. 

 

 

I understand this can be implemented using a for loop with conditional checks,  but I am curious about this method. 

Accepted Solution (1)

ap5356
Shopify Partner
8 2 2

This is an accepted solution.

I wasn't able to use the where filter as I was hoping, but ended up solving the issue anyway. 

In my use case, I needed to create sub-arrays based on a common property. And this common property always showed up contiguously across items in the original array. This made the situation a little easier. I just iterated through the original array, kept track of the relevant indices, and took slices of it using slice to create the sub-arrays. 

View solution in original post

Reply 1 (1)

ap5356
Shopify Partner
8 2 2

This is an accepted solution.

I wasn't able to use the where filter as I was hoping, but ended up solving the issue anyway. 

In my use case, I needed to create sub-arrays based on a common property. And this common property always showed up contiguously across items in the original array. This made the situation a little easier. I just iterated through the original array, kept track of the relevant indices, and took slices of it using slice to create the sub-arrays.