【问题标题】:magento ce 1.7 exclude previously displayed on product page while sorting randommagento ce 1.7 排除以前显示在产品页面上的随机排序
【发布时间】:2014-03-18 18:07:47
【问题描述】:

在随机排序并导航到下一页时排除以前显示的产品

我正在使用

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中显示产品页面中的随机项目,但产品不断重复!

【问题讨论】:

    标签: php magento sorting pagination


    【解决方案1】:

    礼貌@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());
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多