我试图找到两种类别的产品。 我发现了一个例子,以获得类别1或类别2中的产品。 http://www.alphadigital.cl/blog/lang/en-us/magento-filter-by-multiple-categories.html 我需要属于category1和category2的产品。在Magento中过滤两个类别的产品集合
在博客的例子是:
class ModuleName_Catalog_Model_Resource_Eav_Mysql4_Product_Collection
extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection{
public function addCategoriesFilter($categories){
$alias = 'cat_index';
$categoryCondition = $this->getConnection()->quoteInto(
$alias.'.product_id=e.entity_id AND '.$alias.'.store_id=? AND ',
$this->getStoreId()
);
$categoryCondition.= $alias.'.category_id IN ('.$categories.')';
$this->getSelect()->joinInner(
array($alias => $this->getTable('catalog/category_product_index')),
$categoryCondition,
array('position'=>'position')
);
$this->_categoryIndexJoined = true;
$this->_joinFields['position'] = array('table'=>$alias, 'field'=>'position');
return $this;
}
}
当我单独使用此过滤器就几类查询执行或。 当我将此过滤器与Mage_Catalog_Model_Layer 的prepareProductCollection组合时,它以某种方式删除过滤器效果。
如何将过滤器更改为AND并将其与prepareProductCollection组合使用?
感谢
感谢
伟大的解决方案和解释,谢谢。 – gregdev 2013-05-25 22:47:30