1

What i am doing

->addFieldToFilter('value', array(['eq' => '', array('isnull' => true)]))

What i want in the query - '((value = '' )is NULL)`

Can anyone help me on this

Thanks.

3
  • What is your actual requirement ? do you want to check value is empty and null?
    – aravind
    Feb 10, 2020 at 12:41
  • i am checking if a customer ticked the attribute or not when i do null= true doesnt bring me any record but soon as i add is null it works Feb 10, 2020 at 12:52
  • so can you explain me what exact you want? Feb 11, 2020 at 6:51

2 Answers 2

0

Try this solution,

->addFieldToFilter('value', array('null' => true) );
1
  • this returns (value IS NULL) i needed ((value = '' )is NULL) Feb 10, 2020 at 12:34
0

Try this solution,

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

$collection->addFieldToFilter(
    [
        ['attribute' => 'value', 'null' => true], // Check if 'value' is NULL
        ['attribute' => 'value', 'eq' => '']     // Check if 'value' is empty
    ]
);

In the above example, we create a product collection and then use addFieldToFilter with an array of filter conditions.

The first condition checks if 'value' is NULL ('null' => true), and the second condition checks if 'value' is empty ('eq' => '').

These conditions are combined using the OR operator, so the collection will return products where either condition is met.

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.