문제

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?

도움이 되었습니까?

해결책 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);

}

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top