tags:

views:

343

answers:

2

Hi folks. I have a Magento helper class I wrote that works wonderfully in 1.3. However, we're working on a new install of 1.4 and filtering by category won't work for some reason.

 function __construct()
 {
  Mage::app();
  $this->model = Mage::getModel('catalog/product');
  $this->collection = $this->model->getCollection();
  $this->collection->addAttributeToFilter('status', 1);//enabled
  $this->collection->addAttributeToSelect('*');
 }

 function filterByCategoryID($catID)
 {
  $this->collection->addCategoryFilter(Mage::getModel('catalog/category')->load($catID));
 }

I can't figure out why this isn't working in 1.4. Has anyone else come into this issue?

+1  A: 

Based on what you posted, my guess would be there's something else in your code that's adding/removing filters to/from your collection. I ran the following code on a 1.4 install

$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToFilter('status', 1)
->addCategoryFilter(Mage::getModel('catalog/category')->load(8))
->addAttributeToSelect('*');

and the product collection was filtered as expected.

Expanding your question to show how you're using your helper and what you expect it to do vs what it does would help.

Alan Storm
A: 
LinuxGnut