Question

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?

Was it helpful?

Solution 2

I was able to get it working with the code below...

function __construct() { Mage::app(); }

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

}

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top