Magento的产品收集与特定ID(magento product collection with

2019-08-02 04:36发布

我选择产品

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

我怎么能archieve该集合是相同的顺序在$ productIds的ID?

谢谢

Answer 1:

    $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();
    }

看更多 @

  • Magento的以任意顺序获得产品收集

  • 如何在IN子句的顺序选择MySQL的行



文章来源: magento product collection with specific id
标签: magento