How do I filter $Product on AdditionalCategories in the template?
I've tried:
$Product.filter('AdditionalCategories', $MyFilter)
But there is no AdditionalCategories column on Product in the database
Product
has a many to many relationship to ProductCategory
called ProductCategories
.
If we want to filter products on the category relationship we would call the following:
$Product.filter('ProductCategories.ID', 5)
I would recommend writing this filter in a function in a controller. Something like this:
public function getFilteredProducts() {
return Product::get()->filter('ProductCategories.Title', 'my-filter');
}
With the help of @3dgoo,
Looks like I needed the following:
<% loop $Products.filter('Product_ProductCategories.ProductCategoryID', $MyFilter) %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With