Skip to main content
Post Undeleted by Rizwan Khan
Post Deleted by Rizwan Khan
Improved Answer
Source Link
Rizwan Khan
  • 2k
  • 2
  • 18
  • 41

You can use the Product Collection factory as below.

\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory

$_collection = $this->_productCollectionFactory->create();
$_collection->addAttributeToSelect('*');
$_collection->addAttributeToFilter('status',\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED);
// Your attribute code   
$_collection->addAttributeToFilter('size',  array('notnull' => true));

Get your product.

foreach ($_collection as $_product) {
    $_product->getName();
}

You can use the Product Collection factory as below.

$_collection = $this->_productCollectionFactory->create();
$_collection->addAttributeToSelect('*');
$_collection->addAttributeToFilter('status',\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED);
// Your attribute code   
$_collection->addAttributeToFilter('size',  array('notnull' => true));

Get your product.

foreach ($_collection as $_product) {
    $_product->getName();
}

You can use the Product Collection factory as below.

\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory

$_collection = $this->_productCollectionFactory->create();
$_collection->addAttributeToSelect('*');
$_collection->addAttributeToFilter('status',\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED);
// Your attribute code   
$_collection->addAttributeToFilter('size',  array('notnull' => true));

Get your product.

foreach ($_collection as $_product) {
    $_product->getName();
}
Source Link
Rizwan Khan
  • 2k
  • 2
  • 18
  • 41

You can use the Product Collection factory as below.

$_collection = $this->_productCollectionFactory->create();
$_collection->addAttributeToSelect('*');
$_collection->addAttributeToFilter('status',\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED);
// Your attribute code   
$_collection->addAttributeToFilter('size',  array('notnull' => true));

Get your product.

foreach ($_collection as $_product) {
    $_product->getName();
}