-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Filtering based on average Review/Comment scores and Sorting #569
base: dev
Are you sure you want to change the base?
Changes from all commits
0f75dba
1178dd9
a767762
db0fccc
080b08c
a029235
9666de2
8f2f4f7
f9f96a6
1c99bff
d50e526
a4b11d7
9a70fda
21a9f79
0d6b378
8ee9a3a
e049400
90354ff
aca5aa1
9191b0f
c13edac
e79531f
501fa80
b8cb6a1
ba9c020
c3eeabe
e3754c1
745d289
0073146
0a02241
3160ebd
4f79cb8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
/** | ||
* Copyright since 2007 PrestaShop SA and Contributors | ||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0) | ||
* that is bundled with this package in the file LICENSE.md. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://opensource.org/licenses/AFL-3.0 | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to [email protected] so we can send you a copy immediately. | ||
* | ||
* @author PrestaShop SA <[email protected]> | ||
* @copyright Since 2007 PrestaShop SA and Contributors | ||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) | ||
*/ | ||
require_once __DIR__ . '/../../config/config.inc.php'; | ||
require_once __DIR__ . '/ps_facetedsearch.php'; | ||
|
||
if (substr(Tools::encrypt('ps_facetedsearch/index'), 0, 10) != Tools::getValue('token') || !Module::isInstalled('ps_facetedsearch')) { | ||
exit('Bad token'); | ||
} | ||
|
||
if (!Module::isEnabled('productcomments')){ | ||
exit('Product Comment module is not installed or is disabled.'); | ||
} | ||
|
||
Shop::setContext(Shop::CONTEXT_ALL); | ||
|
||
$module = new Ps_Facetedsearch(); | ||
|
||
if (Tools::getValue('full')){ | ||
$module->rebuildCommentIndexTable(); | ||
echo $module->indexReviews(true); | ||
}else{ | ||
echo $module->indexReviews(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,6 +115,9 @@ public function getFilterBlock( | |
case 'price': | ||
$filterBlocks[] = $this->getPriceRangeBlock($filter, $selectedFilters, $nbProducts); | ||
break; | ||
case 'review': | ||
$filterBlocks[] = $this->getReviweBlock($filter, $selectedFilters); | ||
break; | ||
case 'weight': | ||
$filterBlocks[] = $this->getWeightRangeBlock($filter, $selectedFilters, $nbProducts); | ||
break; | ||
|
@@ -979,4 +982,74 @@ private function preparePriceSpecifications() | |
'currencySymbol' => $currency->sign, | ||
]; | ||
} | ||
|
||
/** | ||
* Get the reviews filter block | ||
* | ||
* @param array $filter | ||
* @param array $selectedFilters | ||
* | ||
* @return array | ||
*/ | ||
private function getReviweBlock($filter, $selectedFilters) | ||
{ | ||
$values = [ | ||
'4' => ['name'=>"4"], | ||
'3' => ['name'=>"3"], | ||
'2' => ['name'=>"2"], | ||
'1' => ['name'=>"1"], | ||
]; | ||
|
||
$idParent = (int) Tools::getValue( | ||
'id_category', | ||
Tools::getValue('id_category_layered', Configuration::get('PS_HOME_CATEGORY')) | ||
); | ||
|
||
$query = 'SELECT count(g.grade) as count ,g.grade FROM (SELECT t.id_product, case | ||
when t.avg_grade between 1 and 1.99 then "1" | ||
when t.avg_grade between 2 and 2.99 then "2" | ||
when t.avg_grade between 3 and 3.99 then "3" | ||
when t.avg_grade between 4 and 5 then "4" | ||
end as grade | ||
FROM (SELECT avg(h.grade) as avg_grade, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two much subqueries, I'm afraid of performance problems 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes you are right, I think at least 3 joins are inevitable, but an alternative could be another table which keeps counts for all categories, and can be calculated during indexing. |
||
h.id_product FROM | ||
(select pc.id_product, pc.grade from ' . _DB_PREFIX_ . 'product_comment as pc | ||
inner join (SELECT * FROM ' . _DB_PREFIX_ . 'category_product where id_category = '.$idParent.') cp | ||
on pc.id_product = cp.id_product) h | ||
group by id_product) t) g | ||
group by g.grade | ||
order by g.grade ASC'; | ||
$gradeCounts = $this->database->executeS($query); | ||
|
||
if (!empty($gradeCounts)){ | ||
foreach ($values as $value){ | ||
$nbr = 0; | ||
foreach ($gradeCounts as $count){ | ||
if ((int)$value['name'] <= $count['grade']){ | ||
$nbr += $count['count']; | ||
} | ||
} | ||
$values[$value['name']]['nbr'] = $nbr; | ||
} | ||
} | ||
|
||
if (isset($selectedFilters['review'])){ | ||
$reviewValues = $selectedFilters['review']; | ||
foreach ($reviewValues as $rv){ | ||
$values[$rv]['checked'] = true; | ||
} | ||
} | ||
|
||
$reviewBlock = [ | ||
'type_lite' => 'review', | ||
'type' => 'review', | ||
'id_key' => 0, | ||
'name' => $this->context->getTranslator()->trans('Avg. Customer Reviews', [], 'Modules.Facetedsearch.Shop'), | ||
'values' => $values, | ||
'filter_show_limit' => (int) $filter['filter_show_limit'], | ||
'filter_type' => Converter::WIDGET_TYPE_STAR, | ||
]; | ||
|
||
return $reviewBlock; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't be able to do 0.5 star? I think it costs nothing to start at 0 instead of 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually the average score can not be less than 1, because we do not have comments with 0 grade, user must choose between 1-5 values.