我选择产品
$products = Mage::getModel('catalog/product')->getCollection()->addAttributeToFilter('entity_id', array('in' => $productIds));
Run Code Online (Sandbox Code Playgroud)
我怎么能认为该集合与$ productIds中的ID的顺序相同?
谢谢
我为我们的Magento商店开发了一个自定义搜索引擎,我正在尝试按照特定的顺序加载产品集合(我根据我设计的算法对结果进行了排序).
我可以正确加载产品集合,但它不是我希望它的顺序.这里基本上是它如何工作:
我的数据库查询基本上带有PHP数组的产品ID.对于这个例子,让我们说它看起来像这样:
$entity_ids = array(140452, 38601 );
Run Code Online (Sandbox Code Playgroud)
现在我可以转换140452和38601,每次产品系列都以相同的顺序返回.我希望产品集合与实体ID的ID顺序相同.
我用来创建我的集合的代码如下:
$products = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('entity_id', array('in' => $entity_ids))
->setPageSize($results_per_page)
->setCurPage($current_page)
->load();
Run Code Online (Sandbox Code Playgroud)
有没有办法将排序顺序设置为$ entity_ids数组的顺序?