Patrik Dendis
Patrik Dendis

Reputation: 313

Magento select products filter

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

Answers (2)

Kalpesh
Kalpesh

Reputation: 5695

Mage::getModel('catalog/product')->getCollection()
    ->addFieldToFilter(
        array(
            array(
                'attribute' => 'manufacturer',
                'null' => 'null' //this value don't matter
            )    
         )
     )
    ->addAttributeToSelect('*');

Upvotes: 4

Matt Humphrey
Matt Humphrey

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

Related Questions