您好我有一个选择产品的脚本。但它选择所有产品,其中有制造商3,5。它工作正常,但我想选择没有填写现场制造商的产品。我怎么能这样做?
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToFilter('manufacturer', array(3,5))
->addAttributeToSelect('*');
答案 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('*');