Shivam
Shivam

Reputation: 2443

Collection filter With null and attribute value matched

I am trying to get the products which match certain attribute values + Null in product collection. I have tried the following code, but it does not work:

$collection->addAttributeToFilter('length', NULL);
$collection->addAttributeToFilter('length', array('in' => array(115, 116)));

Upvotes: 2

Views: 1382

Answers (1)

Shivam
Shivam

Reputation: 2443

$collection->addAttributeToFilter(
                    array(
                        array(
                            'attribute' => 'length',
                            'null' => true
                        ),
                        array(
                            'attribute' => 'length',
                            'finset' => array(115,116)
                        )
                    )
            );

Upvotes: 2

Related Questions