I have custom dropdown attribute with yes and no values. I want to get only those product names which have attribute value yes. I am trying to avoid using object manager directly, so I need to accomplish this using dependencies. Any ideas?

  • on list page Or somewhere else ?
    – Pawan
    Feb 26, 2019 at 4:34

1 Answer 1


Using object manager

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

use echo '<pre>';print_r($productcollection->getData()); to get product datas

Using constructor method

protected $_productRepository;

public function __construct(
    \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
) {
    $this->_productRepository = $productRepository;

punblic function getProductCollection(){
       $productcollection = $this->_productRepository->addAttributeToSelect('*')
       return $productcollection;

use echo '<pre>';print_r($this->getProductCollection()->getData()); to get product datas

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.