I need a dropdown brands filter for Silvershop
Asked Answered
H

2

7

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

Higdon answered 12/5, 2017 at 17:34 Comment(0)
H
1

With the help of @3dgoo,

Looks like I needed the following:

<% loop $Products.filter('Product_ProductCategories.ProductCategoryID', $MyFilter) %>
Higdon answered 15/5, 2017 at 0:24 Comment(0)
A
3

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');
}
Aggappera answered 14/5, 2017 at 23:4 Comment(0)
H
1

With the help of @3dgoo,

Looks like I needed the following:

<% loop $Products.filter('Product_ProductCategories.ProductCategoryID', $MyFilter) %>
Higdon answered 15/5, 2017 at 0:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.