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'); May 10, 2016 at 7:30
  • @Anil Suthar I tried, but can't do it. $ranking is not an attribute, just a temporary parameter.
    – Jeffery
    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.
    – Sourav
    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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.