Reputation: 313
Hi I have a script that selects products. But it select all products, which have manufacturer 3,5. It works fine but I wanna select products that haven't fill in a field manufacturer. How can I do this?
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToFilter('manufacturer', array(3,5))
->addAttributeToSelect('*');
Upvotes: 2
Views: 899
Reputation: 5695
Mage::getModel('catalog/product')->getCollection()
->addFieldToFilter(
array(
array(
'attribute' => 'manufacturer',
'null' => 'null' //this value don't matter
)
)
)
->addAttributeToSelect('*');
Upvotes: 4
Reputation: 1554
Use the null
operator:
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToFilter('manufacturer', 'null')
->addAttributeToSelect('*');
Or the equals
operator:
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToFilter('manufacturer', array('eq' => ''))
->addAttributeToSelect('*');
Upvotes: 2