且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

加载后对 Magento 集合进行排序

更新时间:2023-11-30 10:01:28

另一种有效的解决方案:

Another solution which works:

class Aligent_Navigation_Block_Dropdown extends Mage_Catalog_Block_Product_List {

public function getProductsByShortDesc(){
    $data = $this->getLoadedProductCollection()->getItems();  //an array of objects
    usort($data,array('Aligent_Navigation_Block_Dropdown','sortByShortDesc'));
    return $data;
}

public static function sortByShortDesc($a, $b)
{
  if($a->getShortDescription() ==  $b->getShortDescription()){ return 0 ; }
  return ($a->getShortDescription() < $b->getShortDescription()) ? -1 : 1;
}
}