Post by Ganisek » Mon Mar 04, 2013 8:52 pm

OK.. it seem that im done :)
its only one file changes
catalog\model\catalog -> and replce product.php

I hope that this is it. :)

THIS is repair of price_filter archive pack!

Newbie

Posts

Joined
Mon Feb 18, 2013 7:37 pm

Post by leandrotruppa » Mon Mar 04, 2013 10:52 pm

maybe you can give us a changelog of whats lines are modified?

My themes:
Fleen Theme
My vqmods:
Remove description tab - Remove related products tab - Remove title from category page


Newbie

Posts

Joined
Fri Jan 27, 2012 11:11 pm

Post by Ganisek » Tue Mar 05, 2013 12:06 am

in catalog/model/catalog/product.php
this

if (!empty($data['filter_filter'])) {
$zaznamu_pole = count($implode);
$sql .= " HAVING COUNT(*) = " . $zaznamu_pole . "";
}


replace with this

if (!empty($data['filter_filter'])) {
$gquery = "SELECT COUNT(*) AS total FROM (SELECT COUNT(*) FROM filter WHERE filter_id IN (" . implode(',', $implode) . ") GROUP BY filter_group_id) as groupstotal";
$gsql = mysql_query($gquery);
$fgroup_count = mysql_fetch_array($gsql);
$sql .= " HAVING COUNT(*) = " . $fgroup_count['total'] . "";
}
in function GetProducts and getTotalProducts, so it 2x replace this code above
but still is here problem with product which has two or more filter options of the same filter group.. it mean product with color red and blue and more :-[

Newbie

Posts

Joined
Mon Feb 18, 2013 7:37 pm

Post by leandrotruppa » Tue Mar 05, 2013 2:26 am

That's the only one modified line to get working this? Not need to modify any other file?

My themes:
Fleen Theme
My vqmods:
Remove description tab - Remove related products tab - Remove title from category page


Newbie

Posts

Joined
Fri Jan 27, 2012 11:11 pm

Post by Ganisek » Tue Mar 05, 2013 7:07 am

Yees.. Problem solved... Now im posting completly working version of product.php in model/catalog
No more problem with product with 2 or more filter options in the same filter group!

For example of filtring:
COLOR MATERIAL <-filter groups
blue metal
red wood <-filter options
white

between all colors will be logical OR, the same between material type. Between color and material logical AND..
I hope that more bugs will not be detected..

For install: 1) product.php
rewrite catalog/model/catalog/product.php

for install whole pack: Just coppy all to root/catalog direcotry..
This was maded only for 1.5.5 and 1.5.5.1 version, on clean install..

Enjoy

Attachments

Complet pack

who has price filter already and needed to correct filtring. Options in the same group is like a OR and options between groups are AND


Newbie

Posts

Joined
Mon Feb 18, 2013 7:37 pm

Post by leandrotruppa » Tue Mar 05, 2013 10:20 am

Please guive me a changelog of the modified files. I am going to do this a vqmod. I dont want to modify core files.

Thanks.

My themes:
Fleen Theme
My vqmods:
Remove description tab - Remove related products tab - Remove title from category page


Newbie

Posts

Joined
Fri Jan 27, 2012 11:11 pm

Post by Ganisek » Wed Mar 06, 2013 12:31 am

i dont have a changelog... In this week when i got a piece of time to do, ill do this modification in vqmode..

Newbie

Posts

Joined
Mon Feb 18, 2013 7:37 pm

Post by leandrotruppa » Tue Mar 12, 2013 11:14 pm

Hi Ganisek i am still waiting for the Vqmod. You are working on this?

My themes:
Fleen Theme
My vqmods:
Remove description tab - Remove related products tab - Remove title from category page


Newbie

Posts

Joined
Fri Jan 27, 2012 11:11 pm

Post by Ganisek » Sat Mar 16, 2013 12:56 am

Hi. today i was trying that.. But i dont know for what is index="?"...
<search position="before" index="2"> example..
Anyway.. i compilate all change, you can try make it work. What i mentioned, almost of file modification didnt execute changes inside



and <file name="catalog/model/catalog/category.php"> didnt work without index equal 2 or more then 2 <search position="before" index="2">
maybe it should help..

Attachments

IT DOESNT WORK!


Newbie

Posts

Joined
Mon Feb 18, 2013 7:37 pm

Post by freddy87 » Thu Apr 11, 2013 3:49 pm

Hi, i modified vqmod, now it is working, but stil there is problem with special price. This vqmod is depend on normal price, no special, somebody who can help with it.

This is model file:

Code: Select all

public function getCategoryPriceRange($category_id) {

          $minmax = array();
            $query = 'SELECT MIN(price) AS min, MAX(price) AS max FROM ' . DB_PREFIX . 'product P
                    join ' . DB_PREFIX . 'product_to_category POC
                    on POC.product_id = P.product_id
                    where POC.category_id = ' . (int)$category_id . ' AND P.status = 1' ;
           
            $results = $this->db->query($query);
            $minmax = $results->row;
            if(empty($minmax['min']) and empty($minmax['max'])){
                return null;
            }

             $minmax = array(
            'minimum' => floor($minmax['min']),
            'maximum' =>  floor($minmax['max'])
         );
           return $minmax;

    }

New member

Posts

Joined
Mon Sep 03, 2012 1:19 am

Post by kalarena » Fri Apr 19, 2013 4:38 pm

@Ganisek: Thank you very much, Your work is absolutely amazing

Can you do something in this module so it uses the opencart's manufactures attribute as filter?

فروشگاه اینترنتی


Newbie

Posts

Joined
Wed Mar 07, 2012 11:09 pm

Post by midgette » Sun Apr 28, 2013 4:42 pm

I needed a filter that would use OR logic for items within each filter group and, at the same time, use AND logic on the groups of filters. For example, i needed to select red or blue or green shirts that are large. Pseudo code:
(filter_group_color.filter = 'red' OR filter_group_color.filter = 'blue' OR filter_group_color.filter = 'green') AND filter_group_size.filter = 'large' .

So I made these changes in catalog\model\catalog\product.php - same changes to functions getProducts() and getTotalProducts():

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)";
with:

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) ";
					}
				}
replace (lines 99-107):

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) . ")";				
with:

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;
					$f_count = 0;
					$last_fgid = -1;
					foreach ($query->rows as $frow) {
						$f_count += 1;
						if ($frow['filter_group_id'] != $last_fgid) {
							$g_count += 1;
							$f_count = 1;
							$last_fgid = $frow['filter_group_id'];
							$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'];
							}
						}
						if ($f_count == $frow['num_sel_filters_in_grp']) {
							$sql .= ")";
						}
					}
				}
replace (line 482):

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)";
with:

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) ";
					}
				}
replace (lines 500-508):

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) . ")";				
with:

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;
					$f_count = 0;
					$last_fgid = -1;
					foreach ($query->rows as $frow) {
						$f_count += 1;
						if ($frow['filter_group_id'] != $last_fgid) {
							$g_count += 1;
							$f_count = 1;
							$last_fgid = $frow['filter_group_id'];
							$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'];
							}
						}
						if ($f_count == $frow['num_sel_filters_in_grp']) {
							$sql .= ")";
						}
					}
				}
This did the trick for me.
Regards.
Last edited by midgette on Sun May 05, 2013 9:06 am, edited 3 times in total.

Newbie

Posts

Joined
Sun Apr 28, 2013 4:16 pm

Post by Q000 » Thu May 02, 2013 4:44 pm

midgette ... YOU ARE THE MAN ! 8)

to be true the filter module implemented in 1.5.5.x is the best by far than all extensions out there, no offence meant for extension creators, are all good but the new filter that comes with opencart is way faster, simple, etc. Despite the fact that are many people that are saying is redundant to make another set of rules for filters instead of using atributes, maybe so but in this way is more flexible. Anyway midgette your solution is the best, clean and easy, only one file to edit to keep it simple. Maybe they will implement your solution in next releases to complete the filter module functionality.

Best regards man, really awesome work there !

Newbie

Posts

Joined
Fri Mar 08, 2013 4:53 pm

Post by midgette » Fri May 03, 2013 1:22 pm

Q,
Thank You for your kind words!
Glad I could help : )

Best Regards,
midgette

Newbie

Posts

Joined
Sun Apr 28, 2013 4:16 pm

Post by Q000 » Fri May 03, 2013 3:58 pm

midgette, you deserve every word :P is a bit sad to see no other replies for such elegant/clean solution but hey .. maybe is too soon to talk ;D

There is a small change i wan't to add for those who want a live filter (to get rid of filter button), there is a small change in /catalog/view/theme/default/template/module/filter.tpl

Code: Select all

<script type="text/javascript"><!--
$(document).ready(function() {
	$('.box-filter li ul li input[type=\'checkbox\']').live('click', function() {
		filter = [];
		$('.box-filter input[type=\'checkbox\']:checked').each(function(element) {
			filter.push(this.value);
		});
		location = '<?php echo $action; ?>&filter=' + filter.join(',');
	});
});
//--></script>
Now, all that remains to achieve is refresh of product totals (in parenthesis next to the filter name) based on checked filter and i think this will be cleaner / fastest filter that opencart ever got. At least in my tests on each click to filter over 250 products, every filter applies in maximum 1sec. And why not the easiest filter to skin/customize.

Newbie

Posts

Joined
Fri Mar 08, 2013 4:53 pm

Post by mark4013 » Sat May 04, 2013 9:04 pm

My solution as a VQMod.. (only a few lines of code)

http://www.opencart.com/index.php?route ... n_id=11707

Newbie

Posts

Joined
Sat May 04, 2013 9:02 pm

Post by josrevalution » Fri May 17, 2013 1:14 am

Hi every one.. i have following this step
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).
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.
his work but the problem is,when user click the product ridirect from the hompage where is inside the latest module filters function not show/not come out is mean filters dont have in that product.. but if user click the product from categorie filters will show.... for sure....

Filters module will work id user go from here :

cateforie>perfume>gucci>product model.

Filters module not work if user from here:

homepage>product model.

And for more deteil please come my store here :http://perfumelovers.net/

Please anyone can fix this??.. tanks in advance

Newbie

Posts

Joined
Fri May 17, 2013 1:03 am

Post by azzido » Mon May 27, 2013 2:30 am

Hi all,

I am trying to modify product.php according to the changes provided by midgette and I get a Syntax MySQL error. Should I change other files ? Who can provide me these changes in a zip file ? I am using opencart version 1.5.5.1

Many thanks
Nicusor

New member

Posts

Joined
Mon May 27, 2013 2:27 am

Post by SteitSlings » Mon May 27, 2013 6:06 am

In addition to midgette's solution I added a devision by the number of languages, I use a cart in dutch and english and got the wrong number of filters back from the query
On lines 110 and 537 I changed

Code: Select all

count(filter_group_id)
into

Code: Select all

(count(filter_group_id)/count(DISTINCT language_id)) 
That solved my problem :-)

Newbie

Posts

Joined
Mon May 27, 2013 5:59 am

Post by azzido » Tue May 28, 2013 4:46 am

No one can tell me what I am doing wrong ? I made the changes exactly as midgette said and I got this error:

Notice: Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Error No: 1064
SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_product_to_category p2c LEFT JOIN oc_product_filter pf_1 ON (p2c.product_id = pf_1.product_id) LEFT JOIN oc_product p ON (p2c.product_id = p.product_id) LEFT JOIN oc_product_description pd ON (p.product_id = pd.product_id) LEFT JOIN oc_product_to_store p2s ON (p.product_id = p2s.product_id) WHERE pd.language_id = '2' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '0' AND p2c.category_id = '18' AND (pf_1.filter_id = 1 in /home/superlap/public_html/opencart/system/database/mysql.php on line 50

New member

Posts

Joined
Mon May 27, 2013 2:27 am
Who is online

Users browsing this forum: No registered users and 28 guests