在随机排序并导航到下一页时排除以前显示的产品
我正在使用
if($this->getCurrentOrder() != 'price'){
if($this->getCurrentOrder() != 'created_at') {
$this->_collection->getSelect()->order('rand()');
}else{
$this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
}
}else{
$this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
}
在toolbar.php中显示产品页面中的随机项目,但产品不断重复!!
答案 0 :(得分:0)
礼貌@marius
您需要按“种子”随机顺序订购产品,并确保整个会话期间的“种子”相同。
这是一种可能的方法。我没有对它进行测试,但我已经使用这种种子随机排序来列出其他实体。
if($this->getCurrentOrder() != 'price'){
if($this->getCurrentOrder() != 'created_at') {
//check if there is a seed in the session.
$seed = Mage::getSingleton('catalog/session')->getListSeed();
//if there is none, generated it and store it in the session
if (!$seed) {
$seed = time(); //can replace with custom logic if you want
Mage::getSingleton('catalog/session')->setListSeed($seed);
}
//get a random number based on seed
srand($seed);
$rand = rand(0, 100);
//pass the random number to the sorting.
$this->_collection->getSelect()->order('rand('.$rand.')');
}
else{
$this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
}
}
else {
$this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
}