How to Get Product Collection in Magento 2?

  • author-img Nidhi Arora
  • 5 years
  • 218 views

If you are a developer who uses Magento 1.x, you will find yourself deeply aware about the usage of “Mage::getModel(‘catalog/product’)->getCollection();” to get product collection. However, if you are using Magento 2 and you want your product collection, it is quite different as compared to Magento 1.x.

So with no further delay, let’s have a look at the code mentioned below:

<?php

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

/* @var \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection /

$productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection');

/* Apply filters here /

$productCollection->load();

var_dump($productCollection->getData());

?>

After reviewing afore shared code, we believe that you can easily understand & perform the required steps to get the product collection in Magento 2. If you still have any query regarding applying this coding in your Magento 2, or any other inquiry related to Magento 2, you can leave a comment below or contact us.

Download Blog

ENQUIRY

Ready to Get started

Communication is the key for us to understand each other. Allow us to understand
your requirements or queries. Present us with an opportunity to serve you.

Fill out the form and out team will get back to you
within 24 hours

    Head Office

    1250 Pittsford Victor Road Ste 310
    Pittsford, NY 14534

    Development Center

    Plot no. 10, Rajiv Gandhi
    Chandigarh Technology Park