具有特定ID的magento产品集合

wut*_*aer 11 magento

我选择产品

$products = Mage::getModel('catalog/product')->getCollection()->addAttributeToFilter('entity_id', array('in' => $productIds)); 
Run Code Online (Sandbox Code Playgroud)

我怎么能认为该集合与$ productIds中的ID的顺序相同?

谢谢

Ren*_*art 20

    $productIds = array(1,3,2);
    $products = Mage::getModel('catalog/product')->getCollection()
                ->addAttributeToFilter('entity_id', array('in' => $productIds));


    $products->getSelect()->order("find_in_set(entity_id,'".implode(',',$productIds)."')");

    foreach($products as $product)
    {
        echo $product->getEntityId();
        echo $product->getSku();
    }
Run Code Online (Sandbox Code Playgroud)

看更多 @