0

Could someone somehow guide me on how I can make the product list filter by clicking on one of the three buttons.

I have a custom page, and on it 3 buttons with categories. E.g. category A, B and C.

By default, products from category A should be displayed, and by clicking on these buttons I would like to change products to products from other categories.

The whole thing is done in phtml, and single block file. For displaying the products I used $productCollectionFactory, and simple for loop in phtml.

Thanks in advance for help.

1 Answer 1

1

you can simply put parameter to those button and receive them on submission

then check for the parameter value before loading it and set a default value ,something like

$catalog_ids = [1, 2, 3];

and then filter them in collection

$productCollection = $this->productCollectionFactory->create();
$productCollection->addAttributeToSelect('*');
$productCollection->addCategoriesFilter(array('in' => $catalog_ids));
2
  • Forgive me for asking, but I work in Magento more on the front-end side. So all I need to do is make a form in phtml, and pass a parameter during submit, and I can somehow receive it in block?
    – mrcl
    Commented Jan 31, 2022 at 8:47
  • yes , you can receive form values with $this->getRequest()->getParam('filedName'); Commented Jan 31, 2022 at 10:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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