通过对自定义属性使用addAttributeToSort对产品集合进行排序-不起作用



我想通过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;
}

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

但第三个根本不起作用。

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

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

感谢

我觉得你也需要与管理员合作。

转到"管理"->"目录"->"属性"->"管理属性",然后单击featured_product进行编辑,然后从编辑屏幕

set Used in Product Listing=Yes

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

并保存属性并清除缓存。

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

最新更新