magento - 使用addAttributeToSort为自定义属性对产品集合进行排序 - 无法正常工作

Kay*_* Li 4 php sorting magento

我想通过getLoadedProductCollection进行排序.

对于产品属性,我有一个自定义属性'featured_product'

这是我的代码:

$sort=$_GET['s'];
$_productCollection=$this->getLoadedProductCollection()->addAttributeToSelect('featured_product');

$_productCollection->clear();
$_productCollection->getSelect()->reset(Zend_Db_Select::ORDER);

switch($sort)
{
    case 'lp':
    $_productCollection->addAttributeToSort('price', 'ASC');
    break;
    case 'hp':
    $_productCollection->addAttributeToSort('price', 'DESC');
    break;
    case 'fp':
    $_productCollection->addAttributeToSort('featured_product');

    break;
}
Run Code Online (Sandbox Code Playgroud)

对于前两种情况,它没有问题.

但第三个根本不起作用.

我想将所有特色产品移到收藏列表的开头.

如何更改实现第三种情况的代码?

谢谢

Ram*_*rma 6

我觉得你还需要和管理员一起工作.

转到Admin-> Catalog-> Attributes-> Manage Attributes,然后单击featured_product进行编辑,然后从编辑屏幕进行编辑

set在产品列表中使用=是

用于产品列表中的排序=是

并保存属性并清除缓存.

如果需要,则重新索引数据.