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!