magento让collection的排序方式按照ID数组的顺序排序
时间:2016-01-10 02:40来源: 作者: 点击:次
[html] view plaincopyprint? $ ids = array (16,18,17,19); $ products = Mage ::getModel(catalog/product)- getCollection() - addAttributeToSelect(*) - addAttributeToFilter(entity_id,$ids); //shakesfistatPDOsarrayparameter $ ids = array_map (in
-
$ids = array(16,18,17,19);
-
$products = Mage::getModel('catalog/product')->getCollection()
-
->addAttributeToSelect('*')
-
->addAttributeToFilter('entity_id',$ids);
-
-
//shakes fist at PDO's array parameter
-
$ids = array_map('intval', $ids);
-
$products->getSelect()->order("find_in_set(e.entity_id,'".implode(',',$ids)."')");
-
foreach($products as $product)
-
{
-
var_dump($product->getEntityId());
-
var_dump($product->getSku());
-
}
(责任编辑:最模板) |
------分隔线----------------------------