2010-04-20 90 views
1

我有一個Magento幫助類,我寫了1.3奇妙的作品。但是,我們正在進行1.4版的新安裝,並且由於某種原因,按類別過濾不起作用。Magento 1.4負載類別不工作

 
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)); 
} 

我不明白爲什麼這不工作在1.4。有沒有其他人進入這個問題?

回答

1

我能得到它與下面的代碼工作...

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

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

} 

1

根據您發佈的內容,我的猜測是您的代碼中有其他內容會在您的收藏夾中添加/刪除濾鏡。我在1.4版本上運行以下代碼

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

並且按預期過濾了產品集合。

擴大你的問題,以顯示你如何使用你的助手,你期望它做什麼,它會做什麼會有所幫助。