是否可以按类别显示畅销商品?
我有工作代码(下方)收集畅销书,但我无法弄清楚如何按类别过滤它!
$storeId = Mage::app()->getStore()->getId();
$collection = Mage::getResourceModel('reports/product_collection')
->addOrderedQty()
->setStoreId($storeId)
->addStoreFilter($storeId)
->setOrder('ordered_qty', 'DESC');
if (Mage::helper('catalog/product_flat')->isEnabled()) {
$collection->getSelect()
->joinInner(array('e2' => 'catalog_product_flat_' . $storeId), 'e2.entity_id = e.entity_id');
} else {
$collection->addAttributeToSelect('*')
->addAttributeToSelect(array('name', 'price', 'small_image'));
}
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
$collection->setPage(1, 10);
答案 0 :(得分:0)
您可以在产品系列中使用以下类别过滤器
$product_collection->joinField('category_id','catalog/category_product','category_id','product_id=entity_id',null,'left')
->addAttributeToFilter('category_id', array('in' => array(25,35,10,45)));