1

I have a structure like this:

  1. My Root Category
    • Food
      • Fixed
      • Bread
      • Milk
      • ...

This code lists out all the products in Food.

$category_id = 11;
$catagory_model = Mage::getModel('catalog/category')->load($category_id); 
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->addCategoryFilter($catagory_model);

foreach($collection as $_product){
...
}

I want to list out all the products except the ones in Fixed. Is it possible? Thanks.

0

One way to do this would be to get a list of the product ids from the "Fixed" category and add a filter to your collect for "not in".

$fixedCategory = Mage::getModel('catalog/category')->load($fixedCategoryId);
$fixedCategoryProductIds = $fixedCategory->getProductCollection()->getAllIds();

...

$collection->addIdFilter($fixedCategoryProductIds, true); // true causes filter to act as an exclude filter
...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.