【发布时间】:2018-11-01 09:53:23
【问题描述】:
我正在开发 magento 自定义代码,该代码添加了按销售数量对产品列表进行排序的功能,
我为此使用了这个网站代码 https://inchoo.net/magento/magento-products/sort-show-products-by-sold-quantity-in-magento/comment-page-1/
代码看起来运行良好,但我只需要在用户点击该过滤器时显示已售商品
/app/code/local/Inchoo/Catalog/Block/Product/List/Toolbar.php 上的代码
public function setCollection($collection)
{
$this->_collection = $collection;
$this->_collection->setCurPage($this->getCurrentPage());
// we need to set pagination only if passed value integer and more that 0
$limit = (int)$this->getLimit();
if ($limit) {
$this->_collection->setPageSize($limit);
}
if ($this->getCurrentOrder()) {
if($this->getCurrentOrder() == 'qty_ordered') {
$this->getCollection()->getSelect()
->joinLeft(
array('sfoi' => $collection->getResource()->getTable('sales/order_item')),
'e.entity_id = sfoi.product_id',
array('qty_ordered' => 'SUM(sfoi.qty_ordered)')
)
->group('e.entity_id')
->order('qty_ordered ' . $this->getCurrentDirection());
}
else{
$this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
}
}
return $this;
}
是否可以对只有销售额的产品进行筛选和排序,或者我需要更改一些其他功能,谢谢
【问题讨论】:
标签: php magento magento-1.9