If you are using the Prestashop module “Product comments” you would probably like to be able to display product’s rating not only on the product page but on catalog pages as well.
One day, I got the following page design:
Since this is quite a frequently submitted task and I did not want to solve it again in future, I created the module “Belvg Product List Rating”:
It uses the hook “асtiоnPrоduсtListOverride” to transmit missing product’s rating data to the array data, which are used in the template product-list.tpl. The product rating data are taken from the tables of the module “prоduсtсоmments”.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
public function hookActionProductListOverride($params) { $order_by_values = array(0 => 'name', 1 => 'price', 2 => 'date_add', 3 => 'date_upd', 4 => 'position', 5 => 'manufacturer_name', 6 => 'quantity'); $order_way_values = array(0 => 'asc', 1 => 'desc'); $this->orderBy = Tools::strtolower(Tools::getValue('orderby', $order_by_values[(int)Configuration::get('PS_PRODUCTS_ORDER_BY')])); $this->orderWay = Tools::strtolower(Tools::getValue('orderway', $order_way_values[(int)Configuration::get('PS_PRODUCTS_ORDER_WAY')])); $this->n = abs((int)(Tools::getValue('n', ((isset($this->context->cookie->nb_item_per_page) && $this->context->cookie->nb_item_per_page >= 10) ? $this->context->cookie->nb_item_per_page : (int)Configuration::get('PS_PRODUCTS_PER_PAGE'))))); $this->p = abs((int)Tools::getValue('p', 1)); $this->category = new Category(Tools::getValue('id_category'), $this->context->language->id); if (!in_array($this->orderBy, $order_by_values)) { $this->orderBy = $order_by_values[0]; } if (!in_array($this->orderWay, $order_way_values)) { $this->orderWay = $order_way_values[0]; } $params['nbProducts'] = $this->category->getProducts(null, null, null, $this->orderBy, $this->orderWay, true); $params['catProducts'] = $this->category->getProducts($this->context->language->id, (int)$this->p, (int)$this->n, $this->orderBy, $this->orderWay); $params['hookExecuted'] = 1; foreach($params['catProducts'] as &$cat_product){ $tmp_average = ProductComment::getAverageGrade((int)$cat_product['id_product']); $cat_product['rating_review'] = $tmp_average['grade']; } } |
The received data I am using in the template “product-list.tpl”:
1 2 3 4 5 6 7 8 9 |
{if isset($product.rating_review)} {section name="i" start=0 loop=5 step=1} {if $product.rating_review le $smarty.section.i.index} <div class="star"></div> {else} <div class="star star_on"></div> {/if} {/section} {/if} |
Please note that if you want to use this module along with «Layered navigation block»,then the standard module should be located above our module:
You are welcome to download it here.
PrestaShop Development
Take your online store to the next level with BelVG PrestaShop Development
Visit the page
@Roland the link was updated
Is that module still available? Download link does not work anymore – shows a 404.
I’m looking for a solution for PS 1.6.0.14 – thanks for your feedback.
best regards, Roland
Hi, is it possible to make this work on homepage? I have product-list.tpl included in homepage and I would like to have the rating there too. It works just fine in category page.
Thanks
I confirm it’s not working for 1.6.0.14
Hope Alex can do an update ;)
Regards,
Pol
Hi Alex,
Did you try it in 1.6.14 version, please?
I already read that it is working in 1.6 version but not to me :(
Thank you
Jeremy
Koo,
Yes, as the Layered Navigation block changes the dynamic content. You can contact our support team at [email protected] for the solution.
I got this working, but after selecting something on Layered Navigation Block, the stars disappeared (from the source code too). The Layered Navigation block is above this as instructed. Any solution? Using version 1.5.4.0
Soufiane,
With what version does this work? I checked the class classes / PrestaShopAutoload.php, which is responsible for creating an index of classes and have not found any reference to modules.
Hi,
In prestashop1.6 we have possiblity to override de modules, go to the root/override/modules then create a folder called productcomments then create a file called productcomments.php
in this file we can make override without lost our code after upgrade.
Barrabas,
This article is applicable for the version 1.5. But I can say that there are no big differences if compared with the version 1.6, except for the bootstrap technology. Perhaps, you will just need to make some minor changes in the markup.
Work on prestashop 1.6.0.9??
thanks
Please give a solution for version 1.411
NIk,
here there is the Install function where the hook hookActionProductListOverride() is registered
Bit is clear.
Where in which to embed files
public function hookActionProductListOverride($params)
{………………………………………
———-
Tried to insert into class after the product is not going to request ((
Enrique,
As far as I understand you would like to know why this hook changed the data which are used in product-list. But this happens because when the hook is called the data are transmitted via the link with the help of “&”.
Nice tut, thanks. Though the way PS gives the possibility of changing product list presentation through hooks it’s not very intuitive. I expected a hook for each product in the list not change the entire list