Skip to content

Commit

Permalink
Review list - filter by category / manufacturer. Closes #47
Browse files Browse the repository at this point in the history
  • Loading branch information
getdatakick committed Feb 14, 2019
1 parent d56938b commit ad95b32
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
21 changes: 21 additions & 0 deletions php/classes/review-query.php
Expand Up @@ -19,6 +19,7 @@

namespace Revws;
use \Context;
use \Category;

class ReviewQuery {
private $settings;
Expand Down Expand Up @@ -102,6 +103,26 @@ private function getTables() {
if ($this->includeCustomerInfo()) {
$from .= ' LEFT JOIN ' . _DB_PREFIX_ . 'customer cust ON (r.id_customer = cust.id_customer)';
}
if ($this->hasOption('category')) {
$category = $this->getInt('category');
$from .= ' INNER JOIN '. _DB_PREFIX_ . "category_product cp ON (r.entity_type = 'product' AND r.id_entity = cp.id_product AND cp.id_category = $category)";
}
if ($this->hasOption('categoryTree')) {
$category = $this->getInt('categoryTree');
$categories = Category::getChildren($category, $lang);
$cats = [ $category ];
if ($categories) {
foreach ($categories as $cat) {
$cats[] = (int)$cat['id_category'];
}
}
$cats = implode(',', $cats);
$from .= ' INNER JOIN '. _DB_PREFIX_ . "category_product cpr ON (r.entity_type = 'product' AND r.id_entity = cpr.id_product AND cpr.id_category in ($cats))";
}
if ($this->hasOption('manufacturer')) {
$manufacturer = $this->getInt('manufacturer');
$from .= ' INNER JOIN '. _DB_PREFIX_ ."product p ON (r.entity_type = 'product' AND r.id_entity = p.id_product AND p.id_manufacturer = $manufacturer)";
}
return $from;
}

Expand Down
22 changes: 3 additions & 19 deletions php/revws.php
Expand Up @@ -606,25 +606,9 @@ public function hookDisplayRevwsReviewList($params) {
];

$conditions = [];

if (isset($params['product'])) {
$product = (int)$params['product'];
if ($product > 0) {
$conditions['product'] = $product;
}
}

if (isset($params['customer'])) {
$customer = (int)$params['customer'];
if ($customer > 0) {
$conditions['customer'] = $customer;
}
}

if (isset($params['guest'])) {
$guest = (int)$params['guest'];
if ($guest > 0) {
$conditions['guest'] = $guest;
foreach (['product', 'customer', 'guest', 'category', 'categoryTree', 'manufacturer'] as $param) {
if (isset($params[$param])) {
$conditions[$param] = (int)$params[$param];
}
}

Expand Down

0 comments on commit ad95b32

Please sign in to comment.