2

In my file, the $ranking of each product is an integer numeric value derived from a particular formula.

$productCollection = Mage::getModel('catalog/product') ->getCollection(); foreach($productCollection as $product){ $ranking = formula; //integer numeric value } 

I want to sort the products according to the $ranking.
What should I do?

3
  • use $productCollection->addAttributeToSort('ranking', 'desc'); Commented May 10, 2016 at 7:30
  • @Anil Suthar I tried, but can't do it. $ranking is not an attribute, just a temporary parameter. Commented May 10, 2016 at 7:37
  • What is the formula??? Where you are saving the ranking for products. if you are saving product ranking in DB then you may use joins in collection. Commented May 17, 2016 at 1:03

1 Answer 1

1

I reckon you should use setOrder:

$productCollection->setOrder($ranking); 

Where $ranking should be a valid SQL order statement.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.