Hello everyone. I have a custom product attribute (brand) and I need to create a brand listing page. I know that I can filter by brand in the products category page (e.g. /category?brand=23) but the same brand could be in products of different categories. How can I display a page with all the products of a specific brand?
Hello @Miroir Studio
You need customization for show products of specific "brand" attribute.
You can take reference from below example code:
Make preference of this class Magento\Catalog\Block\Product\ListProduct and go to its _getProductCollection() method and put your attribute filter condition after this line $this->_productCollection = $layer->getProductCollection(); for example $this->_productCollection = $layer->getProductCollection(); $this->_productCollection->addAttributeToFilter('brand', 10);
It may help you!
Thank you.
Hi @Miroir Studio ,
Refer this module https://github.com/magepow/magento-2-shop-by-brand
Specifically below file
https://github.com/magepow/magento-2-shop-by-brand/blob/master/Block/Product/ListProduct.php
Hope it helps!
Thanks