How to get product collection by multiple attributes?

Magento 2.0


You can use


to get product collection and filter by multiple attribute like this:

$productCollection = $this->_productFactory->create()->getCollection()->addAttributeToSelect('*')->addFieldToFilter('sku',array('eq' => $styleCode));

Use "Dependency Injection" method to implement this, Please reply if need more clarification,

  • How to get product collection brand attribute wise on the product view page. – Masud Shaikh Sep 3 '18 at 12:58
  • 1
    1. You can override this Class \Magento\Catalog\Block\Product\View 2. Use above mentioned ProductFacory as Dependency injection as $_productFactory 3. Create new function in same class and insert below code in this function: $productCollection = $this->_productFactory->create()->getCollection()->addAttributeToSelect('*')->addFieldToFilter('brand',array('eq' => $brand)); return $productCollection; 4. Now call above created function on product page phtml however that phtml should be linked with above overriden class. – Om Prakash Sep 4 '18 at 6:45
  • Hi, om I have tried but it is not getting data. – Masud Shaikh Sep 4 '18 at 7:42
  • can you discuss on chatbox with me? – Masud Shaikh Sep 4 '18 at 8:43

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.