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

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).')'));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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