Forums / Bug Reports / typefilter not being applied to URLs on sort

typefilter not being applied to URLs on sort

Views: 1,011

Results 1 to 6 of 6
4 Feb 2025, 11:26 PM
#1
kmoodysoh avatar

kmoodysoh

New Zenner

Join Date:
Nov 2011
Posts:
12
Plugin Contributions:
0

typefilter not being applied to URLs on sort

Hi all!

I've been using ZenCart for a long time now and I've had this issue as long as I can remember. Going back several years. I have assumed this whole time that it was some rogue code on my part. With the 2.1.0 upgrade, I decided to meticulously replace my files and recreate my template from scratch based off of the responsive template. When that didn't fix these particular issues, I decided to finally figure out what was going on and now I have found the issue, but I am unsure on how to fix it.

When using the music_genre sidebox (just an easy way to call the genre), it takes me to a list of all my products within that genre as expected. It even Filters by category as expected.
However, when changing the Sort By, it always brings up a full list of products, not narrowed by the genre, despite showing the genre in at the top of the page. Upon further inspection, the Sort By is not adding "&typefilter=music_genre" to the URL. If I manually add that to the URL, all the filters are respected, including the Sort By. This is also an issue with the record_company sidebox/filter.

I've been scouring the files all day and can't seem to glean where the disconnect is. Thank you and I appreciate any guidance.

Site: https://selectohits.com
Zen: 2.1.0
PHP: 8.1.31
Plugins: as far as I can tell, this happens with no plugins, but it could be rogue code on my part.

30 Apr 2026, 9:58 PM
#2
kmoodysoh avatar

kmoodysoh

New Zenner

Join Date:
Nov 2011
Posts:
12
Plugin Contributions:
0

Re: typefilter not being applied to URLs on sort

kmoodysoh:

Hi all!

I've been using ZenCart for a long time now and I've had this issue as long as I can remember. Going back several years. I have assumed this whole time that it was some rogue code on my part. With the 2.1.0 upgrade, I decided to meticulously replace my files and recreate my template from scratch based off of the responsive template. When that didn't fix these particular issues, I decided to finally figure out what was going on and now I have found the issue, but I am unsure on how to fix it.

When using the music_genre sidebox (just an easy way to call the genre), it takes me to a list of all my products within that genre as expected. It even Filters by category as expected.
However, when changing the Sort By, it always brings up a full list of products, not narrowed by the genre, despite showing the genre in at the top of the page. Upon further inspection, the Sort By is not adding "&typefilter=music_genre" to the URL. If I manually add that to the URL, all the filters are respected, including the Sort By. This is also an issue with the record_company sidebox/filter.

I've been scouring the files all day and can't seem to glean where the disconnect is. Thank you and I appreciate any guidance.

Site: https://selectohits.com
Zen: 2.1.0
PHP: 8.1.31
Plugins: as far as I can tell, this happens with no plugins, but it could be rogue code on my part.

After updating to 2.2.2, I decided to again to try to fix this issue. I found that the typefilter was being set based on the GET parameter, but it wasn't accounting for the fact that the GET parameter might not be set. So, I added code to my files to auto-detect the typefilter based on the presence of GET parameters that are specific to the record_company and music_genre filters.

I am replying to my old post in case anyone else has this issue and wants to fix it.

I'm sure there is a more elegant way to do this, so I also wanted to post it in case it might be good for the next update.

in includes/modules/pages/index/header_php.php

Replace line 126 (technically just added the if/else statement before and a closing bracket after)

$typefilter = $_GET['typefilter'] ?? 'default';

with

// Auto-detect typefilter based on GET parameters if not explicitly set
if (!empty($_GET['record_company_id'])) {
  $typefilter = 'record_company';
} elseif (!empty($_GET['music_genre_id'])) {
  $typefilter = 'music_genre';
} elseif (!empty($_GET['manufacturers_id'])) {
  $typefilter = 'default';
} else {
  $typefilter = $_GET['typefilter'] ?? 'default';
}

and in includes/modules/pages/index/main_template_vars.php

Replace line 186 (again, just added an if/else around the existing typefilter code)

  $typefilter = $_GET['typefilter'] ?? 'default';

with

// Auto-detect typefilter based on GET parameters if not explicitly set
  if (!empty($_GET['record_company_id'])) {
    $typefilter = 'record_company';
  } elseif (!empty($_GET['music_genre_id'])) {
    $typefilter = 'music_genre';
  } elseif (!empty($_GET['manufacturers_id'])) {
    $typefilter = 'default';
  } else {
    $typefilter = $_GET['typefilter'] ?? 'default';
  }

I hope it helps!

30 Apr 2026, 10:22 PM
#3
kmoodysoh avatar

kmoodysoh

New Zenner

Join Date:
Nov 2011
Posts:
12
Plugin Contributions:
0

Re: typefilter not being applied to URLs on sort

I tried to reply to my existing thread, but it didn't look like it posted. Apologies if this ended up double posted.
The original thread asking for help is https://www.zen-cart.com/showthread.php/230580-typefilter-not-being-applied-to-URLs-on-sort

After updating to 2.2.2, I decided once again to try to fix this issue. I found that the typefilter was being set based on the GET parameter, but it wasn't accounting for the fact that the GET parameter might not be set. So I added code to my files to auto-detect the typefilter based on the presence of other GET parameters that are specific to the record_company and music_genre filters.

I am posting it here in case anyone else has this issue and wants to fix it and I'm sure there is probably a more elegant way to do this.

in includes/modules/pages/index/header_php.php

Replace line 126 (technically just added the if/else statement before and a closing bracket after)

$typefilter = $_GET['typefilter'] ?? 'default';

with

// Auto-detect typefilter based on GET parameters if not explicitly set
if (!empty($_GET['record_company_id'])) {
  $typefilter = 'record_company';
} elseif (!empty($_GET['music_genre_id'])) {
  $typefilter = 'music_genre';
} elseif (!empty($_GET['manufacturers_id'])) {
  $typefilter = 'default';
} else {
  $typefilter = $_GET['typefilter'] ?? 'default';
}

and in includes/modules/pages/index/main_template_vars.php

Replace line 186 (again, just adding an if/else around the existing line)

$typefilter = $_GET['typefilter'] ?? 'default';

with

// Auto-detect typefilter based on GET parameters if not explicitly set
  if (!empty($_GET['record_company_id'])) {
    $typefilter = 'record_company';
  } elseif (!empty($_GET['music_genre_id'])) {
    $typefilter = 'music_genre';
  } elseif (!empty($_GET['manufacturers_id'])) {
    $typefilter = 'default';
  } else {
    $typefilter = $_GET['typefilter'] ?? 'default';
  }

site URL: selectohits.com
ZC Version: 2.2.2
PHP version: 8.4.20

1 May 2026, 12:09 PM
#4
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,119
Plugin Contributions:
56

Re: typefilter not being applied to URLs on sort

I'll propose a teeny change to your suggested code. For each spot:

    if (!empty($_GET['record_company_id'])) {
        $typefilter = 'record_company';
    } elseif (!empty($_GET['music_genre_id'])) {
        $typefilter = 'music_genre';
    }
    $typefilter ??= $_GET['typefilter'] ?? 'default';

Let me know if that works for you and I'll get a PR submitted for the next Zen Cart release.

2 May 2026, 12:44 PM
#5
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,119
Plugin Contributions:
56

Re: typefilter not being applied to URLs on sort

lat9:

I'll propose a teeny change to your suggested code. For each spot:

if (!empty($_GET['record_company_id'])) {
    $typefilter = 'record_company';
} elseif (!empty($_GET['music_genre_id'])) {
    $typefilter = 'music_genre';
}
$typefilter ??= $_GET['typefilter'] ?? 'default';
> 
> Let me know if that works for you and I'll get a PR submitted for the next Zen Cart release.
PR submitted: <https://github.com/zencart/zencart/pull/7686>
2 May 2026, 3:00 PM
#6
kmoodysoh avatar

kmoodysoh

New Zenner

Join Date:
Nov 2011
Posts:
12
Plugin Contributions:
0

Re: typefilter not being applied to URLs on sort

Editing with your change breaks the sort for me again.

However, just removing

  } elseif (!empty($_GET['manufacturers_id'])) {
    $typefilter = 'default';

The sort still works.

So my current code in both is

if (!empty($_GET['record_company_id'])) {
  $typefilter = 'record_company';
} elseif (!empty($_GET['music_genre_id'])) {
  $typefilter = 'music_genre';
} else {
  $typefilter = $_GET['typefilter'] ?? 'default';
}