Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I need a dropdown brands filter for Silvershop

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

like image 358
helenclarko Avatar asked May 12 '17 17:05

helenclarko


2 Answers

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');
}
like image 142
3dgoo Avatar answered Nov 03 '22 23:11

3dgoo


With the help of @3dgoo,

Looks like I needed the following:

<% loop $Products.filter('Product_ProductCategories.ProductCategoryID', $MyFilter) %>
like image 25
helenclarko Avatar answered Nov 03 '22 23:11

helenclarko