Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento自定义排序选项_Magento_Magento 1.7 - Fatal编程技术网

Magento自定义排序选项

Magento自定义排序选项,magento,magento-1.7,Magento,Magento 1.7,如何在Magento中添加自定义排序选项。我想添加畅销书,最高评级和独家除了排序的价格。有关畅销书,请提供帮助 haneged incode/local/Mage/Catalog/Block/Product/List/Toolbar.php方法setCollection to public function setCollection($collection) { parent::setCollection($collection); if ($this->getCurre

如何在Magento中添加自定义排序选项。我想添加畅销书,最高评级和独家除了排序的价格。有关畅销书,请提供帮助

haneged in
code/local/Mage/Catalog/Block/Product/List/Toolbar.php
方法setCollection to

public function setCollection($collection) {
    parent::setCollection($collection);
    if ($this->getCurrentOrder()) {
        if($this->getCurrentOrder() == 'saleability') {
            $this->getCollection()->getSelect()
                 ->joinLeft('sales_flat_order_item AS sfoi', 'e.entity_id = sfoi.product_id', 'SUM(sfoi.qty_ordered) AS ordered_qty')
                 ->group('e.entity_id')->order('ordered_qty' . $this->getCurrentDirectionReverse());
        } else {
            $this->getCollection()
                 ->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
        }
    }

    return $this;
}
setCollection之后,我添加了此方法:

public function getCurrentDirectionReverse() {
    if ($this->getCurrentDirection() == 'asc') {
        return 'desc';
    } elseif ($this->getCurrentDirection() == 'desc') {
        return 'asc';
    } else {
        return $this->getCurrentDirection();
    }
}
最后我把我的方法改为

public function setDefaultOrder($field) {
    if (isset($this->_availableOrder[$field])) {
        $this->_availableOrder = array(
            'name'        => $this->__('Name'),
            'price'       => $this->__('Price'),
            'position'    => $this->__('Position'),
            'saleability' => $this->__('Saleability'),
        );
        $this->_orderField = $field;
    }

    return $this;
}
最高评级

试试上面的代码

添加日期

我不会因为任何工作或关注而与上述任何链接联系,这只是为了知识目的和解决您的问题


希望这一定会对您有所帮助。

谢谢您的回答,Anuj,这是迄今为止我能找到的最好的工作模块

只需在代码中添加一个额外的位,即可解决“分组依据”导致的分页问题

复制“/lib/varien/data/collection/Db.php” 到“local/varien/data/collection/Db.php”

将getSize函数更改为

public function getSize()
{

    if (is_null($this->_totalRecords)) {
        $sql = $this->getSelectCountSql();
        //$this->_totalRecords = $this->getConnection()->fetchOne($sql, $this->_bindParams); //============================>change behave of fetchOne to fetchAll

        //got array of all COUNT(DISTINCT e.entity_id), then sum 
        $result = $this->getConnection()->fetchAll($sql, $this->_bindParams);

        foreach ($result as $row) {//echo'<pre>'; print_r($row);
            $this->_totalRecords += reset($row);
        }

    }
    return intval($this->_totalRecords);
}
Price.php getMaxPrice

app\code\core\Mage\Catalog\Model\Resource\Product\Collection.php 如果你有同样的问题,你会知道我的意思。 祝你好运,花了8个小时在最畅销的功能上


再次更新

刚刚找到另一种方法来实现 使用cron收集每日保存在一个表中的最佳销售数据,该表包括产品id和计算的基本销售数字。 然后简单地离开join,而不应用“groupby” 这意味着核心功能不需要改变,也不需要加快整个分拣过程。
终于完成了!呵呵。

要解决自定义排序集合的分页问题,请从中重写其集合的资源模型


以上将解决自定义排序集合的计数问题。

这对我来说非常有用。谢谢顺便说一句,我建议不要直接更改Mage中的核心文件,而应该使用自己的模块。我使用的不是直接更改
code/local/Mage/Catalog
而是本地代码而不是核心文件。但您也可以在自定义模块中使用它来重写块
$maxPrice = 0;
    foreach ($connection->fetchall($select) as $value)
    {
        if (reset($value) > $maxPrice)
        {
            $maxPrice = reset($value);
        }

    }
    return $maxPrice;
app\code\core\Mage\Catalog\Model\Resource\Product\Collection.php protected function _getSelectCountSql($select = null, $resetLeftJoins = true) { $this->_renderFilters(); $countSelect = (is_null($select)) ? $this->_getClearSelect() : $this->_buildClearSelect($select);

    /*Added to reset count filters for Group*/ 
    if(count($countSelect->getPart(Zend_Db_Select::GROUP)) > 0) {
     $countSelect->reset(Zend_Db_Select::GROUP);
    }
    /*Added to reset count filters for Group*/  

    $countSelect->columns('COUNT(DISTINCT e.entity_id)');
    if ($resetLeftJoins) {
      $countSelect->resetJoinLeft();
    }
    return $countSelect;
   }