0

I am trying to filter products by category as below in the screenshot.

enter image description here

Once the category selected from the drop down the products belongs to that category should populate in the products section.

I need to populate child categories in dropdown once the parent is selected in first dropdown.

can we have this filter in list page?

Please anyone suggest me the solution. Thanks

1

get parent categories

protected $_categoryCollectionFactory;

public function __construct(
        \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryFactory
    ) {
        $this->_categoryCollectionFactory = $categoryFactory;
    }
    public function getParentCategoryCollection()
    { 
      return   $this->_categoryCollectionFactory->create()->addAttributeToSelect('*')->addFieldToFilter('parent_id',0); 

     }

get child categories

    public function getChildCategoryCollection()
    { 
      $parentId = 1;
      return   $this->_categoryCollectionFactory->create()->addAttributeToSelect('*')->addFieldToFilter('parent_id',$parentId); 

     }
0

Easiest way is to add category filter(of Layred Navigation) on selection of category dropdown.

Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.