我想獲得一個產品集合的產品在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
這個固定爲我'$收藏 - >不同的(真正的);' –
你能告訴我該文件的完整路徑編輯? –
我不確定你的意思。沒有真正的文件路徑要編輯,因爲這是我自己的代碼中的文件,在我自己的插件中。 –