我想获得一个产品集合的产品在A类或B类。我已经能够成功地把这些产品用下面的PHP代码:过滤产品收集Magento的1.7
$collection = Mage::getModel('catalog/product')
->getCollection()
->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left')
->addAttributeToFilter('category_id', array('in' => array('finset' => 4,19)))
->addAttributeToSelect('*');
但是,如果该产品是在这两个类别4和19,则显示错误:
Item (Mage_Catalog_Model_Product) with the same id "173" already exist
这是因为集合有重复的行了。我努力寻找合适的代码来过滤出集合中的任何重复行。解决方案必须是对值进行分组,或者使用不同的值,但我不确定如何前进。
又见Filter Magento collection but not products, using distinct
这个固定为我'$收藏 - >不同的(真正的);' –
你能告诉我该文件的完整路径编辑? –
我不确定你的意思。没有真正的文件路径要编辑,因为这是我自己的代码中的文件,在我自己的插件中。 –