1

How to get product collection by multiple attributes?

Magento 2.0

2

1 Answer 1

2

You can use

Magento\Catalog\Model\ProductFactory;

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,

4
  • How to get product collection brand attribute wise on the product view page. Sep 3, 2018 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, 2018 at 6:45
  • Hi, om I have tried but it is not getting data. Sep 4, 2018 at 7:42
  • can you discuss on chatbox with me? Sep 4, 2018 at 8:43

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.