I have problem when i try to loop all products from parent category and its sub-catgories.
I create two extra page types:
- ProductCategory
- Product
In SiteTree
(pages) i create structure:
|-Pages
|- Dental equipment (productCategory)
|----- Sub category (productCategory)
|----- Sub sub category (productCategory)
|----- Sub sub sub category (productCategory)
|----- Product 1 (product type)
|----- Product 2 (product type)
|----- Product 3 (product type)
|----- Product 4 (product type)
Now in ProductCategory_Controller
i create method to loop all products that not working.
public function Products()
{
$products = Product::get()->filter([
'ParentID' => $this->ID
]);
return $products;
}
My question is how to get all products thats belongs to all parenet and sub-categories?
If you're trying to get the products for the current category page and all parent category pages, then the example code below might point you in the right direction.
If I misunderstood your question, please comment and I'll update my answer.