2016-03-15 69 views
0

這適用於目錄類別頁面。在所有情況下,默認的getLoadedProductCollection方法都不能正常工作,所以我需要這樣做。addCategoryFilter不適用於價格種類

我一直無法添加下面的價格排序。通過刪除addCategoryFilter,產品按價格進行正確排序。通過刪除價格排序方法並保留addCategoryFilter,類別顯示未排序。

我試過以下使用連接來過濾類別,這並沒有做任何事情:
http://magento.stackexchange.com/questions/7094/filter-product-collection-by-multiple-categories

$layer = Mage::getSingleton('catalog/layer'); 
$category = $layer->getCurrentCategory(); 
$currentCatId= $category->getId(); 
$category_model = Mage::getModel('catalog/category')->load($currentCatId); 
$_productCollection = Mage::getModel('catalog/product') 
    ->getCollection() 
    ->addAttributeToSelect("*") 
    ->addAttributeToSort('price', Varien_Data_Collection::SORT_ORDER_DESC) 
    ->addStoreFilter(Mage::app()->getStore()->getId()) 
    ->addAttributeToFilter('status',1) 
    ->setVisibility(
     Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds()) 
    ->addCategoryFilter($category_model) 
    ->load(); 

任何幫助,將不勝感激。我不太明白爲什麼這不能正常工作。

P.S.而不是addAttributeToSort,我也試過setOrder方法無濟於事。

回答

0

而不是addAttributeToSort(),你爲什麼不試試setOrder()

事情是這樣的:

$layer = Mage::getSingleton('catalog/layer'); 
$category = $layer->getCurrentCategory(); 
$currentCatId= $category->getId(); 
$category_model = Mage::getModel('catalog/category')->load($currentCatId); 
$_productCollection = Mage::getModel('catalog/product') 
    ->getCollection() 
    ->addAttributeToSelect("*") 
    ->addStoreFilter(Mage::app()->getStore()->getId()) 
    ->setOrder('price', Varien_Data_Collection::SORT_ORDER_DESC) 
    ->addAttributeToFilter('status',1) 
    ->setVisibility(
     Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds()) 
    ->addCategoryFilter($category_model) 
    ->load(); 

希望它可以幫助

+0

啊,我們對此深感抱歉。我忘了補充說我也嘗試過。現在編輯。 –

+0

感謝您的回覆,但。 :) –

相關問題