Why not display product in subcategory?

  • Posts: 168
  • Thank you received: 7
4 years 5 months ago #312959

how to display products in subcategory when select parnent category in Products listing type of menu item?
i have some category and subcategory.when user select category, hikashop only show products in that category and not show products in subcategory of that category.how to config that?
i set Including sub categories to yes as you can see in the picture but it is not display product in subcategories...


it seems a bug, because i set that in your demo but not work correctly in your demo site when i select an option in the left filter module...

Attachments:
Last edit: 4 years 5 months ago by sadaf3d.

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

  • Posts: 81476
  • Thank you received: 13059
  • MODERATOR
4 years 5 months ago #312981

Hi,

The first "category" setting of the filter allows you to restrict the display of the filter to only the selected categories.
And if you activate the "include sub categories" setting below, then the filter will also display for the sub categories.
However, the filter itself will only display the products directly linked to the selected category.
There is no option in category filters to allow the display of products of subcategories of the selected category.

The following user(s) said Thank You: sadaf3d

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

  • Posts: 168
  • Thank you received: 7
4 years 5 months ago #313057

nicolas wrote: There is no option in category filters to allow the display of products of subcategories of the selected category.

if i want develop this feature to show products in subcategory when i select a category that have subcategories in the filter, what need to do and what file must modified? is it need to create plugin to override that if it is Class? please advise me.

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

  • Posts: 81476
  • Thank you received: 13059
  • MODERATOR
4 years 5 months ago #313058

Hi,

In that case, you would have to modify the file administrator/components/com_hikashop/classes/filter.php
In it, you'll find the function addFilter with such code:

if($filter->filter_data=='category'){
			if(!($infoGet[0] == $filter->filter_namekey && count($infoGet) == 1)){
				$categoriesList='';
				foreach($infoGet as $cat){
					if($cat == $filter->filter_namekey || (int)$cat == 0)
						continue;

					if(is_numeric($cat)){
						$categoriesList.=(int)$cat.',';
					}elseif(is_string($cat)){
						$cat = explode('::',$cat);
						foreach($cat as $selectedCategory){
							$selectedCategory = trim($selectedCategory);
							if(!empty($selectedCategory))
								$categoriesList.=(int)$selectedCategory.',';
						}
					}
				}
				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];
					}
					$filter->filter_namekey = str_replace('-', '_', $filter->filter_namekey);
					$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.')';
				}
			}
		}
So you'll want to load the child categories of the categories in the array $categoriesList and add their ids to that array before the INNER JOIN is constructed.
And if you want to make it as an override, you can create a system plugin to load a copy of the modified file after HikaShop is loaded, before HikaShop has to load the filter class (you could load it in onAfterRoute for example).

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

Time to create page: 0.068 seconds
Powered by Kunena Forum