1

Could anyone help me why the following code returns empty result when use LIKE operator with addAttributeToFilter option? Thanks!

$productcollection = $this->_objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection')
       ->addAttributeToSelect(['name', 'price', 'image'])
       ->addAttributeToFilter('name', array('LIKE' => '%Iphone%'))
       ->setPageSize(10,1);
11

Use 'like' instead of 'LIKE'

$productcollection = $this->_objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection')
                                                  ->addAttributeToSelect(['name', 'price', 'image'])
                                                  ->addAttributeToFilter('name', array('like' => '%Iphone%'))
                                                  ->setPageSize(10,1);

You can print query following way:

echo $productcollection->getSelect()->__toString();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.