I am trying to create a product collection based on array of products ids, and also sort the collection based on the ids array.
$productIds = array(318,310,311); $collection = Mage::getModel('catalog/product') ->getCollection() ->setOrder('entity_id', 'asc') // This will not do the job ->addAttributeToSelect('*') ->addAttributeToFilter('status', 1) ->addAttributeToFilter('entity_id', array( 'in' => $productIds, ));
I want to sort collected as they appear in
$productIds array that is
318, 310, 311 but above code will return collection sort like
Is this possible without using plain MySQL query as given below?
SELECT * FROM catalog_product_entity WHERE entity_id IN (318, 310, 311) ORDER BY FIELD(entity_id, 318, 310, 311);