我正在按如下方式拉取一个集合
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('jan')
->addAttributeToSelect('name')
->addAttributeToSelect('upc')
->addAttributeToSelect('ean')
->addAttributeToSelect('price')
->addAttributeToFilter('ean', array('neq' => ''))
->addFieldToFilter(array(
array('attribute'=>'type_id','eq'=>'simple')
))
->setPage(1,5);
目前我正在选择所有简单的产品,其中'ean'不为空。如何选择所有简单的产品,或者up或者jan不为空。
换句话说,只要产品有ean,upc或jan,就选择所有产品。如果它们都是空的,请不要选择它。
答案 0 :(得分:4)
http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/using_collections_in_magento
class Mage_Catalog_Model_Resource_Product_Collection extends Mage_Catalog_Model_Resource_Collection_Abstract
-
class Mage_Catalog_Model_Resource_Collection_Abstract extends Mage_Eav_Model_Entity_Collection_Abstract
-
Mage_Eav_Model_Entity_Collection_Abstract
/**
* Add attribute filter to collection
*
* If $attribute is an array will add OR condition with following format:
* array(
* array('attribute'=>'firstname', 'like'=>'test%'),
* array('attribute'=>'lastname', 'like'=>'test%'),
* )
*
* @see self::_getConditionSql for $condition
* @param Mage_Eav_Model_Entity_Attribute_Interface|integer|string|array $attribute
* @param null|string|array $condition
* @param string $operator
* @return Mage_Eav_Model_Entity_Collection_Abstract
*/
public function addAttributeToFilter($attribute, $condition = null, $joinType = 'inner')
溶液:
$collection->addAttributeToFilter(
array(
array(
'attribute' => 'ean',
'neq' => '',
),
array(
'attribute' => 'upc',
'neq' => '',
),
),
array(
'attribute' => 'jan',
'neq' => '',
),
)
);