问题描述
我正在寻找一种方法,该方法可以按当前类别和可选的子类别来过滤在类别页面上返回的产品.到目前为止,我所看到的每个解决方案都是显示类别A或类别B的产品".
I am looking for a way to filter the products being returned on a category page by the current category AND an optional sub-category. Every solution I have seen so far has been 'show products that are in category-a OR category-b'.
我需要编辑哪个文件以通过作为查询参数(例如?catfilter=32
)传递的附加的可选类别ID来过滤产品系列?
Which file do I need to edit to filter a product collection by an additional, optional category id passed as a query parameter (e.g. ?catfilter=32
)?
推荐答案
在此处查看: http://vibrantdrive.com/how-to-filter-magento-products-using-2-or-more-category-filters/
要获取第4类和第5类产品
To get products in Category 4 AND category 5
$_productCollection = Mage::getModel('catalog/product')
->getCollection()
->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left')
->addAttributeToSelect('*')
->addAttributeToFilter('category_id', array(
array('finset' => '4'),
array('finset' => '5'))
)
->addAttributeToSort('created_at', 'desc');
要获得类别4或类别5的产品
To get product in Category 4 OR category 5
$_productCollection = Mage::getModel('catalog/product')
->getCollection()
->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left')
->addAttributeToSelect('*')
->addAttributeToFilter('category_id', array(
array('finset' => array('4', '5')),
)
->addAttributeToSort('created_at', 'desc');
这篇关于Magento 1.7多个类别的过滤产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!