Magento addCategoryFilter不';我不能按价格排序

Magento addCategoryFilter不';我不能按价格排序,magento,categories,Magento,Categories,这用于目录类别页面。默认的getLoadedProductCollection方法在所有情况下都不能正常工作,因此我需要这样做 我在下面添加价格排序时遇到了问题。通过删除addCategoryFilter,产品将按价格正确排序。通过删除价格排序方法并保留addCategoryFilter,类别显示未排序 我尝试使用以下方法来过滤类别,但没有任何效果:http://magento.stackexchange.com/questions/7094/filter-product-collection-

这用于目录类别页面。默认的getLoadedProductCollection方法在所有情况下都不能正常工作,因此我需要这样做

我在下面添加价格排序时遇到了问题。通过删除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();
任何帮助都将不胜感激。我不太明白这为什么不能正常工作


另外,除了addAttributeToSort外,我还尝试了setOrder方法,但没有成功。

你为什么不试试
setOrder()
而不是
addAttributeToSort()

大概是这样的:

$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();

希望有帮助

啊,很抱歉。我忘了补充说我也试过了。正在编辑。不过,感谢您的回复。:)