any solution ? I also need several condition in same time.
công ty môi trường | dịch vụ seo | học kế toán thực hành | học kế toán tổng hợp | quan ao tre em | làm bằng đại học
I have opencart 1.5.6.4 and mariadb Ver 15.1 Distrib 10.0.9
There is a small change you need to make in midgette's mod in page 2
(http://forum.opencart.com/viewtopic.php ... 5&start=20)
in order for this fantastic mod to work.
For some reason, midgette's version leaves somewhere an open parenthesis that causes havoc
to newer versions of mysql or mariadb. Thankfully, the syntax error was reported
clearly in the error.log file.
After debugging the $sql output, I found the solution by making the AND / OR
operators look like this:
So my version of working code is below:
in catalog\model\catalog\product.php
replace (line 81):
with:
replace (lines 99-107):
with:
replace (line 482):
with:
replace (lines 500-508):
with:
Take note that this is the only mod that supports proper pagination.
Existing VQMOD for AND operator between filter groups has serious issues with pagination in opencart 1.5.6.4
Original thanks go to midgette, the code master!
There is a small change you need to make in midgette's mod in page 2
(http://forum.opencart.com/viewtopic.php ... 5&start=20)
in order for this fantastic mod to work.
For some reason, midgette's version leaves somewhere an open parenthesis that causes havoc
to newer versions of mysql or mariadb. Thankfully, the syntax error was reported
clearly in the error.log file.
After debugging the $sql output, I found the solution by making the AND / OR
operators look like this:
Code: Select all
... ' AND (pf_1.filter_id = 7 OR pf_1.filter_id = 8) AND (pf_2.filter_id = 17) AND (pf_3.filter_id = 23 OR pf_3.filter_id = 26) GROUP BY ...
in catalog\model\catalog\product.php
replace (line 81):
Code: Select all
$sql .= " LEFT JOIN " . DB_PREFIX . "product_filter pf ON (p2c.product_id = pf.product_id) LEFT JOIN " . DB_PREFIX . "product p ON (pf.product_id = p.product_id)";
Code: Select all
$sql .= " LEFT JOIN " . DB_PREFIX . "product_filter pf_1 ON (p2c.product_id = pf_1.product_id) LEFT JOIN " . DB_PREFIX . "product p ON (p2c.product_id = p.product_id)";
$fid_array = array();
$filters = explode(',', $data['filter_filter']);
foreach ($filters as $filter_id) {
$fid_array[] = (int)$filter_id;
}
$query = $this->db->query("SELECT COUNT(DISTINCT filter_group_id) AS num_fgid FROM " . DB_PREFIX . "filter_description WHERE filter_id IN(" . implode(',', $fid_array) . ")");
if(!empty($query->row['num_fgid'])) {
for ($thisgrp = 2; $thisgrp <= $query->row['num_fgid']; $thisgrp++) {
$sql .= " LEFT JOIN " . DB_PREFIX . "product_filter pf_" . $thisgrp . " ON (p2c.product_id = pf_" . $thisgrp . ".product_id) ";
}
}
Code: Select all
$implode = array();
$filters = explode(',', $data['filter_filter']);
foreach ($filters as $filter_id) {
$implode[] = (int)$filter_id;
}
$sql .= " AND pf.filter_id IN (" . implode(',', $implode) . ")";
Code: Select all
$query = $this->db->query("SELECT fd.filter_group_id, fd.filter_id, n.num_sel_filters_in_grp FROM " . DB_PREFIX . "filter_description fd left join (SELECT filter_group_id, count(filter_group_id) as num_sel_filters_in_grp FROM " . DB_PREFIX . "filter_description WHERE filter_id IN (" . implode(',', $fid_array) . ") GROUP BY filter_group_id) as n on fd.filter_group_id = n.filter_group_id WHERE filter_id IN (" . implode(',', $fid_array) . ") GROUP BY fd.filter_group_id, fd.filter_id");
if ($query->num_rows) {
$g_count = 0;
$last_fgid = -1;
foreach ($query->rows as $frow) {
if ($frow['filter_group_id'] != $last_fgid) {
$g_count++;
$last_fgid = $frow['filter_group_id'];
if ($g_count==1) $sql .= " ";
else $sql .= ") ";
$sql .= "AND (pf_" . $g_count . ".filter_id = " . $frow['filter_id'];
}
else {
if ($frow['num_sel_filters_in_grp'] > 1) {
$sql .= " OR pf_" . $g_count . ".filter_id = " . $frow['filter_id'];
}
}
}
$sql .= ")";
}
Code: Select all
$sql .= " LEFT JOIN " . DB_PREFIX . "product_filter pf ON (p2c.product_id = pf.product_id) LEFT JOIN " . DB_PREFIX . "product p ON (pf.product_id = p.product_id)";
Code: Select all
$sql .= " LEFT JOIN " . DB_PREFIX . "product_filter pf_1 ON (p2c.product_id = pf_1.product_id) LEFT JOIN " . DB_PREFIX . "product p ON (p2c.product_id = p.product_id)";
$fid_array = array();
$filters = explode(',', $data['filter_filter']);
foreach ($filters as $filter_id) {
$fid_array[] = (int)$filter_id;
}
$query = $this->db->query("SELECT COUNT(DISTINCT filter_group_id) AS num_fgid FROM " . DB_PREFIX . "filter_description WHERE filter_id IN(" . implode(',', $fid_array) . ")");
if(!empty($query->row['num_fgid'])) {
for ($thisgrp = 2; $thisgrp <= $query->row['num_fgid']; $thisgrp++) {
$sql .= " LEFT JOIN " . DB_PREFIX . "product_filter pf_" . $thisgrp . " ON (p2c.product_id = pf_" . $thisgrp . ".product_id) ";
}
}
Code: Select all
$implode = array();
$filters = explode(',', $data['filter_filter']);
foreach ($filters as $filter_id) {
$implode[] = (int)$filter_id;
}
$sql .= " AND pf.filter_id IN (" . implode(',', $implode) . ")";
Code: Select all
$query = $this->db->query("SELECT fd.filter_group_id, fd.filter_id, n.num_sel_filters_in_grp FROM " . DB_PREFIX . "filter_description fd left join (SELECT filter_group_id, count(filter_group_id) as num_sel_filters_in_grp FROM " . DB_PREFIX . "filter_description WHERE filter_id IN (" . implode(',', $fid_array) . ") GROUP BY filter_group_id) as n on fd.filter_group_id = n.filter_group_id WHERE filter_id IN (" . implode(',', $fid_array) . ") GROUP BY fd.filter_group_id, fd.filter_id");
if ($query->num_rows) {
$g_count = 0;
$last_fgid = -1;
foreach ($query->rows as $frow) {
if ($frow['filter_group_id'] != $last_fgid) {
$g_count++;
$last_fgid = $frow['filter_group_id'];
if ($g_count==1) $sql .= " ";
else $sql .= ") ";
$sql .= "AND (pf_" . $g_count . ".filter_id = " . $frow['filter_id'];
}
else {
if ($frow['num_sel_filters_in_grp'] > 1) {
$sql .= " OR pf_" . $g_count . ".filter_id = " . $frow['filter_id'];
}
}
}
$sql .= ")";
}
Existing VQMOD for AND operator between filter groups has serious issues with pagination in opencart 1.5.6.4
Original thanks go to midgette, the code master!
rph wrote:1. Go to Catalog > Filters and select Insert to create a filter group. Assign a filter group name (e.g. Color) and add filter name values (e.g. Blue, Red, Yellow).
Hi - I cant save the filter name values - As soon as I click on the save button the created filter names disappear -
I can create as many filter group names without any problems but I am not able to create filter name values in one of my filter groups!!
any help would be much appreciated
2. Go to Catalog > Categories and Edit a category. Under the Data tab add the filters you want to be able to apply to that category (e.g. Color > Blue, Color > Red).
3. Go to Catalog > Products and Edit a product. Under the Links tab add the filters which apply to the product (e.g. Color > Blue). Apply to as many products as applicable.
4. Go to Extensions > Modules > Filter. If not installed select Install. Click Edit. Click the Add Module button and under Layout select Category and set Status to Enabled. Set whatever position and sort order you would like.
Hi
@erebus
would this mod work in 2.0.1.1 version.
thank you
and sorry for my bad eanglis.
@erebus
would this mod work in 2.0.1.1 version.
thank you
and sorry for my bad eanglis.
I have just been revisiting this and was wondering if anyone would know how I would modify this code to only display filters applicable to the products displayed after each filter is applied?robertiulianstoica wrote:For all of you who are interested in getting the category filters from the products loaded in the category, not from the table category_filter you must go to catalog/model/catalog/category.php and modify the function "getCategoryFilters" by replacing
withCode: Select all
$query = $this->db->query("SELECT filter_id FROM " . DB_PREFIX . "category_filter WHERE category_id = '" . (int)$category_id . "'");
Code: Select all
$query = $this->db->query("SELECT pf.filter_id FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id) LEFT JOIN " . DB_PREFIX . "product_filter pf ON (p.product_id = pf.product_id) WHERE p2c.category_id = '" . (int)$category_id . "' AND p.status='1'");
To clarify, after a filter is applied this code should run again to load only the filters applicable to the products currently displayed in the refined list.
It's a shame that nobody can help with the above.
The default filter has the potential to be near perfect. However, a better user experience is required and for this to occur, filters that do not apply to the current product list need to be disabled or hidden.
This is the manner in which any decent filter works. The customer makes a filter selection, the product list is updated and the available filters are also updated accordingly.
The default filter has the potential to be near perfect. However, a better user experience is required and for this to occur, filters that do not apply to the current product list need to be disabled or hidden.
This is the manner in which any decent filter works. The customer makes a filter selection, the product list is updated and the available filters are also updated accordingly.
Thanks This works very wellerebus wrote:I have opencart 1.5.6.4 and mariadb Ver 15.1 Distrib 10.0.9
There is a small change you need to make in midgette's mod in page 2
(http://forum.opencart.com/viewtopic.php ... 5&start=20)
in order for this fantastic mod to work.
For some reason, midgette's version leaves somewhere an open parenthesis that causes havoc
to newer versions of mysql or mariadb. Thankfully, the syntax error was reported
clearly in the error.log file.
After debugging the $sql output, I found the solution by making the AND / OR
operators look like this:
So my version of working code is as above ................................Code: Select all
... ' AND (pf_1.filter_id = 7 OR pf_1.filter_id = 8) AND (pf_2.filter_id = 17) AND (pf_3.filter_id = 23 OR pf_3.filter_id = 26) GROUP BY ...
Freelance Opencart 1.5.x and 2.x Developer - Available For Hire
Latest Opencart 2 Project --> http://www.falcon-rangecookers.co.uk
Category > Data > Filters does not see filter I created.
And autocomplete doesn't work.
And autocomplete doesn't work.
Who is online
Users browsing this forum: No registered users and 31 guests