通过rand()查询magento limit + order

Pau*_*aan 4 magento

function getIdModelsSliderJuwels(){
 $collection = Mage::getModel("catalog/product")->getCollection();
 $collection->addAttributeToFilter("attribute_set_id", 27); 
     $collection->addAttributeToSelect('modellijnen'); 
   //  $collection->setRandomOrder();
   //  $collection->getSelect()->limit( 5 ); 
 return $collection; 
}
Run Code Online (Sandbox Code Playgroud)

嗨,您好,

我想知道如何为在Magento中运行的查询设置限制因为 $collection->getSelect()->limit( 5 );不起作用.

另外如何随意选择,$collection->setRandomOrder();也行不通.

TXS.

clo*_*eek 8

setRandomOrder不适用于产品系列,仅适用于相关产品.您必须使用以下代码自行添加:

$collection->getSelect()->order(new Zend_Db_Expr('RAND()'));
Run Code Online (Sandbox Code Playgroud)

同时设置页面大小和数字的快捷方式是:

$collection->setPage($pageNum, $pageSize);
Run Code Online (Sandbox Code Playgroud)