过滤产品集合
$model = Mage::getModel('catalog/product')->getCollection()
基于商店过滤:
$mode->addStoreFilter($storeId)
根据产品类型过滤:
$mode->addAttributeToFilter('type_id', 'configurable')
$mode->addAttributeToFilter('type_id', 'simple')
根据状态过滤:
$model->addAttributeToFilter('status',Mage_Catalog_Model_Product_Status::STATUS_DISABLED)
$model->addAttributeToFilter('status',Mage_Catalog_Model_Product_Status::STATUS_ENABLED)
使用 null 和 notnull 过滤:
$model->addAttributeToFilter('short_description', array('null' => true))
$model->addAttributeToFilter('short_description', array('notnull' => true))
使用大于和小于的过滤器:
$model->addAttributeToFilter('entity_id', array('gt' => 64230))
$model->addAttributeToFilter('entity_id', array('lt' => 64230))
过滤使用大于等于:
$model->addAttributeToFilter('entity_id', array('gteq' => 64230))
使用小于等于的过滤:
$model->addAttributeToFilter('entity_id', array('lteq' => 64230))
过滤使用而不是:
$model->addAttributeToFilter('entity_id', array('in' => array(1,4,64231)))
$model->addAttributeToFilter('entity_id', array('nin' => array(1,4,64231)))
按一系列实体 ID 过滤产品:
$model->addAttributeToFilter('entity_id', array(
'from' => 64229,
'to' => 64231
))
根据产品可见性过滤:
$model->addAttributeToFilter('visibility', 4) //catalog,search
$model->addAttributeToFilter('visibility', 3) //catalog
$model->addAttributeToFilter('visibility', 2) //search
$model->addAttributeToFilter('visibility', 1) //not visible individually
过滤使用喜欢和不喜欢:
$model->addAttributeToFilter('sku', array('nlike' => '5713%'))
$model->addAttributeToFilter('sku', array('like' => '%shirt%'))
过滤使用等于和不等于:
$model->addAttributeToFilter('sku', array('neq' => 'shirt'))
$model->addAttributeToFilter('sku', array('eq' => 'shirt'))
过滤库存产品:
$model->joinField('is_in_stock',
'cataloginventory/stock_item',
'is_in_stock',
'product_id=entity_id',
'is_in_stock=1', //make this 0 for out of stock products
'{{table}}.stock_id=1',
'left')
按顺序设置:
$model->setOrder('entity_id','desc')
设置页面大小:
$model->setPageSize(100)