我选择的产品有
$products = Mage::getModel('catalog/product')->getCollection()->addAttributeToFilter('entity_id', array('in' => $productIds));
我怎样才能确保该集合与 $productIds 中的 id 顺序相同?
thanks
$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 以任意顺序获取产品集合 https://stackoverflow.com/questions/3990266/magento-get-a-product-collection-in-an-arbitrary-order
如何按 IN 子句的顺序选择 mysql 行 https://stackoverflow.com/questions/4986731/how-to-select-mysql-rows-in-the-order-of-in-clause
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)