2013-03-24 101 views
1

* $ parent_category *有N個子類別。我如何從* $ parent_category *獲得所有產品,除了屬於* $ excluded_child_category *的產品?產品系列:從某個類別中排除產品

這是我如何檢索父類別:

$collection = Mage::getModel('catalog/category')->load($parent_category_id)->getProductCollection(); 

回答

1

你應該嘗試這樣的事情

Mage::getModel('catalog/category')->load($parent_category_id)->getProductCollection()->addFieldToFilter('entity_id', array('nin' => array('your category id'))); 
+0

你試過嗎?似乎沒有爲我工作,拋出一個錯誤:致命錯誤:調用app/code/core/Mage/Eav/Model/Entity/Abstract.php中的非對象上的成員函數getBackend() 816' – 2013-03-25 06:19:15

+0

你的單位類別是否啓用? – Mufaddal 2013-03-25 06:48:28

+0

我已經改變了我的代碼,我沒有試過這個,你得到的錯誤是因爲沒有像'category_id'這樣的屬性,所以我改變了條件 – Mufaddal 2013-03-25 06:51:41

相關問題