Magento选择产品过滤器

时间:2012-10-15 09:45:37

标签: magento

您好我有一个选择产品的脚本。但它选择所有产品,其中有制造商3,5。它工作正常,但我想选择没有填写现场制造商的产品。我怎么能这样做?

$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToFilter('manufacturer', array(3,5))
->addAttributeToSelect('*'); 

2 个答案:

答案 0 :(得分:4)

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

答案 1 :(得分:2)

使用null运算符:

$collection = Mage::getModel('catalog/product')->getCollection()
  ->addAttributeToFilter('manufacturer', 'null')
  ->addAttributeToSelect('*'); 

equals运营商:

$collection = Mage::getModel('catalog/product')->getCollection()
  ->addAttributeToFilter('manufacturer', array('eq' => ''))
  ->addAttributeToSelect('*');