You can do as following for filtering products id 10 and 12
$products->addAttributeToFilter('entity_id', array('in'=>array(10,12)));
当然这种方式的上面,必须用 ->addAttributeToSelect();
下面这种方式比较实用的,如果想按照名字排序,那么使用方法:setOrder("name","asc");如果想按照ids中的排列的顺序,那么实用 $collection->getSelect()->order("find_in_set(e.entity_id,'".implode(',',$ids)."')");
此为zf框架!
$idss = Mage::registry("idss");
$ids = explode(",",$idss);
//= array(3552,3553,3554,3555);
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('entity_id',$ids);
// ->setOrder("name", "asc");
$collection->getSelect()->order("find_in_set(e.entity_id,'".implode(',',$ids)."')");
$this->setCollection($collection);