具有特定ID的magento产品集合 [英] magento product collection with specific id

查看:90
本文介绍了具有特定ID的magento产品集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我选择

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

我如何归档该集合与$ productIds中的id顺序相同?

how can i archieve that the collection is in the same order as the ids in $productIds?

谢谢

推荐答案

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

查看更多@

如何选择mysql按IN子句的顺序排行

这篇关于具有特定ID的magento产品集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆