Add Custom Attribute in getData of Eav Collection magento 2

If you need to add a custom attribute to add in collection getData array. you need to add it in filter of addAttributeToFilter.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productCollection = $objectManager->create('Magento\Product\Model\Product\ResourceModel\CollectionFactory')->create();
$productCollection->create()->addAttributeToFilter('custom_attr', ['eq', '']);

Note -: Don’t use objectmanager directory, use dependency injection to create object.

Leave a Reply

Your email address will not be published. Required fields are marked *