如何在Magento 1.7中添加评级以排序列表 [英] How to add Rating to sort list in Magento 1.7

查看:96
本文介绍了如何在Magento 1.7中添加评级以排序列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Magento中寻找一些帮助,以添加按评分"排序.我已经将代码片段添加到了toolbar.php中,该代码片段似乎添加了按评分"排序,但是当尝试选择它时,它卡住了,直到我重新加载页面.任何帮助将不胜感激.可以在下面找到代码:这是Toolbar.php文件.

Looking for some help adding sort by Rating in Magento. I have added code snippets to toolbar.php which seem to add the sort by Rating but when trying to select it, it gets stuck until I reload the page. Any help would be greatly appreciated. Code can be found below: This is the Toolbar.php file.

//开始新代码

    $this->getCollection()->joinField('rating',
        'review/review_aggregate',
        'rating_summary',
        'entity_pk_value=entity_id',
        '{{table}}.store_id=1',
        'left');
    // End new Code 

AND

//为排序依据"添加评分

// Add rating to "Sort by"

$_availableOrder = $this->_availableOrder;
$_availableOrder['rating'] = 'Rating';

return $_availableOrder;

$this->_availableOrder = array(
‘rating_summary’ => Mage::helper(’catalog’)->__(’Rating’),
‘price’ => Mage::helper(’catalog’)->__(’Price’),
‘newest’ => Mage::helper(’catalog’)->__(’Newest’),
‘name’ => Mage::helper(’catalog’)->__(’Name’)        
);

推荐答案

最好是在一个模块中制作一个,但是在这里:

Best is to make this in a module but here you go:

首先,我们将更改从数据库中检索产品的方式,以包括总体评分(显示为产品上的星级)以及其他产品属性.将文件app/code/core/Mage/Catalog/Block/Product/List.php复制到app/code/local/Mage/Catalog/Block/Product/List.php并打开以进行编辑.

First we shall alter the way products are retrieved from the database, to include the overall rating (shown as the number of stars on the product) along with the rest of the product attributes. Copy the file app/code/core/Mage/Catalog/Block/Product/List.php to app/code/local/Mage/Catalog/Block/Product/List.php and open it for editing.

在新的List.php文件中,找到以下行(约86行):

In the new List.php file find the following line (around line 86):

$this->_productCollection = $layer->getProductCollection();

在此之后添加以下内容:

After this add the following:

$this->_productCollection->joinField('rating_summary', 'review_entity_summary', 'rating_summary', 'entity_pk_value=entity_id', array('entity_type'=>1, 'store_id'=> Mage::app()->getStore()->getId()), 'left');

现在,我们需要添加一个选项,以便客户可以选择评级"作为排序依据.将文件app/code/core/Mage/Catalog/Model/Config.php复制到app/code/local/Mage/Catalog/Model/Config.php并进行编辑.

Now we need to add in an option so that the customer can select "Rating" as an attribute to sort by. Copy the file app/code/core/Mage/Catalog/Model/Config.php to app/code/local/Mage/Catalog/Model/Config.php and edit.

在新的Config.php文件中,找到以下代码(应从298行开始):

In the new Config.php file find the following code (which should start around line 298):

$options = array(
    'position'  => Mage::helper('catalog')->__('Position')
);

替换为以下代码:

$options = array(
    'position'  => Mage::helper('catalog')->__('Position'),
    'rating_summary' => Mage::helper('catalog')->__('Rating')
);

现在,在网站上查看类别时,除了其他类别外,您还应该选择评分".请注意,排序顺序默认为升序,因此评分最低的产品将首先显示.客户可以通过单击下拉框旁边的箭头来更改排序顺序.除了这一警告之外,新的类别还很容易实现,并扩展了评级的用途.

Now when viewing categories on your website you should have an option of "Rating" in addition to the others. Note that the sort order defaults to ascending so the lowest rated products will be displayed first. The sort order can be changed by the customer by clicking the arrow next to the drop-down box. Aside from this caveat the new sort is fairly easy to implement and extends the usefulness of the ratings.

信用: https://www.fontis.com.au/blog/排序产品评分

这篇关于如何在Magento 1.7中添加评级以排序列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆