I need a dropdown brand filter for Silvershop

How to filter $ Product on additional sites in the template?

I tried:

$Product.filter('AdditionalCategories', $MyFilter) 

But there is no AdditionalCategories column for the product in the database

+7
silverstripe silvershop
source share
2 answers

Using @ 3dgoo

Looks like I need the following:

 <% loop $Products.filter('Product_ProductCategories.ProductCategoryID', $MyFilter) %> 
+1
source share

Product relates many to many to a ProductCategory called ProductCategories .

If we want to filter products by category, we would name the following:

 $Product.filter('ProductCategories.ID', 5) 

I would recommend writing this filter to a function in the controller. Something like that:

 public function getFilteredProducts() { return Product::get()->filter('ProductCategories.Title', 'my-filter'); } 
+3
source share

All Articles