0

I have a product collection created by Magento for the category product list.

I then pass some information about this collection to an external method that returns the entity IDs in a specific sort order.

Now I'd like to re-order the product collection according to the order of the entity IDs, which is completely random and does not follow any conceivable logic.

What would the best approach be?

1 Answer 1

1

Say your product collection is stored in the variable $productCollection and your list of a specific ordered entity IDs are in the array $entityIdsOrder.

Below is how you re-order your product collection according to a specific order of the entity IDs.

$productCollection->getSelect() ->order(new Zend_Db_Expr('FIELD(e.entity_id, ' . implode(',', $entityIdsOrder).')')); 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.