Magento - sort product collection using addAttributeToSort for custom attribute - not working

I want to do a sort using getLoadedProductCollection.

For the product attribute, I have one custom attribute 'featured_product'

Here is my code:

$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;
}

For the first 2 cases it works without problems.

But the third one does not work at all.

I want to move all selected products to the top of the collection list.

How can I change the code to achieve the third case?

thanks

+4
source share
1 answer

I feel that you need to work with an administrator as well.

Admin- > Catalog- > Attributes- > Manage Attributes, featured_product,

set =

=

.

, .

+6

All Articles