filter checkbox rule confuse me

  • Posts: 103
  • Thank you received: 1
  • Hikashop Essential
11 years 4 months ago #114675

Hi:
First I add one custom field with checkbox type.
then I add one checkbox filter apply on this custom field.
for example checkbox:A,B,C,D,E

what I want is when user check A and B and C,only products with A and B and C checked can be displayed.
But now the situation is all products with A OR B OR C checked displayed.

How to deal with it or configure the checkbox rule.

Thank you very much.

Jacky

Please Log in or Create an account to join the conversation.

  • Posts: 12953
  • Thank you received: 1778
11 years 4 months ago #114691

Hi,

I think that this should probably work with the "Submit on click" option turn off, then you'll be able to submit filter your product after that you checked all the parameters that you wanted for your search.

Please Log in or Create an account to join the conversation.

  • Posts: 103
  • Thank you received: 1
  • Hikashop Essential
11 years 4 months ago #114802

I already turned off the"submit on click" ,
But after I check A,B,C then submit,product only with A checked and product only with B checked also displayed in the searching result.
It was not what I want.

Jacky

Please Log in or Create an account to join the conversation.

  • Posts: 2334
  • Thank you received: 403
11 years 4 months ago #115020

Hi Jacky,

Indeed this is the normal behavior of our checkbox filter. Point is that if you apply your example with shirt size, it's sound totally logical to have product with size S, or M or L since having all these size in one shirt doesn't seems possible. If you really want the checkbox filter to work like this I can give you some php code to insert in a Hikashop file but it will change the checkbox behavior for every filters.

Please Log in or Create an account to join the conversation.

  • Posts: 103
  • Thank you received: 1
  • Hikashop Essential
11 years 4 months ago #115185

Dear Eliot:
Yes I believe it is a logical issue,
Because I am selling instrument not shirt,one model can test several parameters at the same time,
So wish you can give me the php code to change the logical algorithm,Before doing it I will backup relative files to avoid any mistake.
Thank you very much.

Best,
Jacky

Please Log in or Create an account to join the conversation.

  • Posts: 2334
  • Thank you received: 403
11 years 4 months ago #115194

Hi Jacky,

You have to edit the filter.php file in administrator/components/com_hikashop/classes and find this block:

if($filter->filter_data=='custom_field'){
				if(empty($filter->filter_value)){
					if(!($infoGet[0]==$filter->filter_namekey && count($infoGet)==1)){
						$fieldsList=array();
						foreach($infoGet as $field){
							if($field!=$filter->filter_namekey && $field!=' '){
									//$fieldsList.=' b.'.$filter->filter_options['custom_field'].' =  '.$database->Quote($field).' OR';
									$fieldsList[]='b.'.$filter->filter_options['custom_field'].' LIKE \'%'.hikashop_getEscaped($field,true).'%\'';
								}
						}
						if(!empty($fieldsList)){
							$fieldsList='('.implode(' OR ',$fieldsList).')';
							$filters[]=$fieldsList;
						}
					}
				}else{
					foreach($infoGet as $slice){
						$values=explode('::', $slice);
						if(empty($values[0])){ $limit[]=' b.'.$filter->filter_options['custom_field'].' <= '.(int)$values[1].' '; }
						else if(empty($values[1])){ $limit[]=' b.'.$filter->filter_options['custom_field'].' >= '.(int)$values[0].' '; }
						else{ $limit[]=' b.'.$filter->filter_options['custom_field'].' BETWEEN '.(int)$values[0].' AND '.(int)$values[1].' '; }
					}
					$filters[]=' ('.implode('OR', $limit).') ';

				}
			}

Then simply transform $fieldsList='('.implode(' OR ',$fieldsList).')'; to $fieldsList='('.implode(' AND ',$fieldsList).')';
and $filters[]=' ('.implode('OR', $limit).') '; to $filters[]=' ('.implode('AND', $limit).') ';

It should do the job.

Last edit: 9 years 11 months ago by nicolas.
The following user(s) said Thank You: lechong1

Please Log in or Create an account to join the conversation.

  • Posts: 103
  • Thank you received: 1
  • Hikashop Essential
11 years 4 months ago #115536

Thank you very much Eliot.it works well now.

Please Log in or Create an account to join the conversation.

  • Posts: 13
  • Thank you received: 0
9 years 11 months ago #182205

Hello

I also got a similar problem. However, when I checked two properties in filter I get this 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 'ANDb.zvrst_piva LIKE '%ale%') ORDER BY a.ordering ASC LIMIT 0, 24' at line 1 SQL=SELECT DISTINCT b.* FROM akzla_hikashop_product_category AS a LEFT JOIN akzla_hikashop_product AS b ON a.product_id=b.product_id WHERE b.product_published=1 AND b.product_type = 'main' AND a.category_id IN (12,13,14,15,16,17,18,19,22,21,23,24,25,26,27,28,29,30,31,32,33,34,2) AND (b.product_access = 'all' OR b.product_access LIKE '%,1,%') AND (b.zvrst_piva LIKE '%lager%' ANDb.zvrst_piva LIKE '%ale%') ORDER BY a.ordering ASC LIMIT 0, 24
*******************

What have I done wrong?

*******************
Here is my changed code:


if($filter->filter_data=='custom_field'){
if(empty($filter->filter_value)){
if(!($infoGet[0]==$filter->filter_namekey && count($infoGet)==1)){
$fieldsList=array();
foreach($infoGet as $field){
if($field!=$filter->filter_namekey && $field!=' '){
$fieldsList[]='b.'.$filter->filter_options.' LIKE \'%'.hikashop_getEscaped($field,true).'%\'';
}
}
if(!empty($fieldsList)){
$fieldsList='('.implode(' AND',$fieldsList).')';
$filters[]=$fieldsList;
}
}
}else{
foreach($infoGet as $slice){
$values=explode('::', $slice);
if(empty($values[0])){ $limit[]=' b.'.$filter->filter_options.' <= '.(int)$values[1].' '; }
else if(empty($values[1])){ $limit[]=' b.'.$filter->filter_options.' >= '.(int)$values[0].' '; }
else{ $limit[]=' b.'.$filter->filter_options.' BETWEEN '.(int)$values[0].' AND '.(int)$values[1].' '; }
}
$filters[]=' ('.implode('AND', $limit).') ';

}
}
******************

I would like to organize the store in such a way, that all

the checkbox options in filter would be permanently visible (as on picture) and would allowed customers to check the new possibilities and immediately get new results.




1. Is it possible to filter the multi checkbox options also with "Submit on click" version?
2. Is this possible also with a radio button version of the filter?
3. Is this possible to do with Hikashop?



Thx in advanced

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 82906
  • Thank you received: 13378
  • MODERATOR
9 years 11 months ago #182208

Hi,

0. There was a bug in the code of Eliot. I've modified it in his message. Try with the new changes and it should work better.

1. Yes
2. Yes
3. Yes

The following user(s) said Thank You: elenora

Please Log in or Create an account to join the conversation.

  • Posts: 13
  • Thank you received: 0
9 years 11 months ago #182283

First of all, I would like to thank you for a quick reply . By entering a new code, this works perfect.

Thank you


However, my soul is not calmed down yet. Now, at the first click on the FILTER option (with "Submit on click” is ON) we get Picture 1. That means that the client can’t choose another FILTER option from the filter options list. If "Submit on click" is OFF, then it work's fine.

With filtration in the filter we get the result shown on Picture 1. Is it possible to change the settings that the filter remains such as shown on Picture 2

Attachments:
Last edit: 9 years 11 months ago by elenora.

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
9 years 11 months ago #182286

Hi,

To remove the button, you can disable the option "Show filter button" in Configuration > Features > Filter.
In the filter settings, I am using the checkboxes and I have the same behaviour than on your picture 2.

Please give us a screenshot of your filter settings.

The following user(s) said Thank You: elenora

Please Log in or Create an account to join the conversation.

  • Posts: 13
  • Thank you received: 0
9 years 11 months ago #182364

With your hint I managed to solve my problem. I thought that there will be needed some changes in the code, but the whole problem was hiding in the "Deletable filter". My mistake ; - )

Thank you very much for your help.

I love Hikashop. ; - )

Last edit: 9 years 11 months ago by elenora.

Please Log in or Create an account to join the conversation.

  • Posts: 29
  • Thank you received: 3
9 years 9 months ago #191964

Hi to all the team,

I have the same problem right now but using the checkbox on category and not on custom_field,
Is there a mean for me to adapt the latest version of filter.php file (found on the forum) and change the behavior of the category checkbox with a logical AND instead of OR. The category menu used is based on ingredients, and I'd like to be able to select only products containing ingredient A AND ingredient B.

Thanks for your answer

JC from makedifferent


--
MAKE DIFFERENT, l'Agence web différente, Cergy.

Please Log in or Create an account to join the conversation.

  • Posts: 82906
  • Thank you received: 13378
  • MODERATOR
9 years 9 months ago #191973

Hi,

It's that code that you need to change for categories:

if($filter->filter_data=='category'){
				if(!($infoGet[0] == $filter->filter_namekey && count($infoGet) == 1)){
					$categoriesList='';
					foreach($infoGet as $cat){
						if($cat != $filter->filter_namekey && is_numeric($cat)){
							$categoriesList.=(int)$cat.',';
						}
					}
					if(!empty($categoriesList)){
						$categoriesList=substr($categoriesList,0,-1);

						$table = 'a';
						if($a=='#__hikashop_product AS b'){
							$table = 'b';
						}elseif($a[0]!='(' && strpos($a,') AS b') && preg_match('#hikashop_product AS ([a-z0-9_]+)#i',$a,$matches)){
							$table = $matches[1];
						}
						$on.=' INNER JOIN '.hikashop_table('product_category').' AS '.$filter->filter_namekey.$i.' ON '.$filter->filter_namekey.$i.'.product_id='.$table.'.product_id AND '.$filter->filter_namekey.$i.'.category_id IN ('.$categoriesList.')';
					}
				}
			}
it's however more complex as you need to either add an inner join for each category in the $categoriesList array, or run a query to load the ids of all the products in both categories and then add a condition on the product_id so that it is in that list of product_ids.

Last edit: 9 years 9 months ago by nicolas.
The following user(s) said Thank You: MAKEDIFFERENT

Please Log in or Create an account to join the conversation.

  • Posts: 29
  • Thank you received: 3
9 years 9 months ago #192011

Hi,

Here is the working code following your first given idea. Hope it will help other people. ;)

if($filter->filter_data=='category'){
				if(!($infoGet[0] == $filter->filter_namekey && count($infoGet) == 1)){
					$categoriesList='';
					foreach($infoGet as $cat){
						if($cat != $filter->filter_namekey && is_numeric($cat)){
							$categoriesList.=(int)$cat.',';
						}
					}
					
					if(!empty($categoriesList)){
						$table = 'a';
						if($a=='#__hikashop_product AS b'){
							$table = 'b';
						}elseif($a[0]!='(' && strpos($a,') AS b') && preg_match('#hikashop_product AS ([a-z0-9_]+)#i',$a,$matches)){
							$table = $matches[1];
						}
						
						$catarray=explode(',',$categoriesList);
						foreach ($catarray as $key=>$value){
							if ($value)
							$on.=' INNER JOIN '.hikashop_table('product_category').' AS '.$filter->filter_namekey.$key.' ON '.$filter->filter_namekey.$key.'.product_id='.$table.'.product_id AND '.$filter->filter_namekey.$key.'.category_id ='.$value.'';
							$table=$filter->filter_namekey.$key;
						}
					}
				}
			}

If someone see anything to improve, let me know.


--
MAKE DIFFERENT, l'Agence web différente, Cergy.
The following user(s) said Thank You: Xavier

Please Log in or Create an account to join the conversation.

Time to create page: 0.144 seconds
Powered by Kunena Forum