Show items in subcategories when main category is selected
This modification has been depreciated, and will not work on servers with PHP 5.4+. To show items in both a main and sub category, please assign those categories in the item edit screen. e.g. To show an item under 'Candles' and 'Candles > Votives', in the edit item screen in the storeadmin area, select both 'Candles' and 'Votives' as categories.
In version 2.7 and higher, selecting a main category only shows items assigned to that main category. It does not show items assigned to the category's subcategories, as was the case in 2.55. This was fixed to allow store owners to choose the products they'd like to have appear in the main category area.
To revert back to the old 2.55 method of showing all of the items assigned to a category's subcategories (as well as those assigned to the category itself), use the following modification:
-
Open the openinfo.php page in the /enc/ directory.
-
Find the following lines:
if ($parentrow[0] > 0) $maincat_set = "yes";
-
Just under those lines, add the following:
VERSION 2.72:
// START MOD - ALSO INCLUDE SUBCATS OF MAIN CATEGORY if (!function_exists("getsubcatids")) { function getsubcatids($initcat, &$catstring='') { global $dblink; $gsubquery = "SELECT ID FROM " .SB_DB_PREFIX ."_categories WHERE Parent='" .(int)$initcat ."' AND Active='Yes'"; $gsubresult = mysql_query($gsubquery, $dblink) or die (mysql_error() .$gsubquery); while ($gsubrow = mysql_fetch_row($gsubresult)) { $catstring .= " OR Category1='$gsubrow[0]' OR Category2='$gsubrow[0]' OR Category3='$gsubrow[0]'
OR Category4='$gsubrow[0]' OR Category5='$gsubrow[0]'"; getsubcatids($gsubrow[0], &$catstring); } return $catstring; } } if ($parentrow[0] > 0) $ctsearchquery = str_replace(")", getsubcatids($category) .")", $ctsearchquery); // END MOD - ALSO INCLUDE SUBCATS OF MAIN CATEGORYVERSION 2.8+ (or with 15 categories):
// START MOD - ALSO INCLUDE SUBCATS OF MAIN CATEGORY if (!function_exists("getsubcatids")) { function getsubcatids($initcat, &$catstring='') { global $dblink; $gsubquery = "SELECT ID FROM " .SB_DB_PREFIX ."_categories WHERE Parent='" .(int)$initcat ."' AND Active='Yes'"; $gsubresult = mysql_query($gsubquery, $dblink) or die (mysql_error() .$gsubquery); while ($gsubrow = mysql_fetch_row($gsubresult)) { $catstring .= " OR Category1='$gsubrow[0]' OR Category2='$gsubrow[0]' OR Category3='$gsubrow[0]'
OR Category4='$gsubrow[0]' OR Category5='$gsubrow[0]' OR Category6='$gsubrow[0]'
OR Category7='$gsubrow[0]' OR Category8='$gsubrow[0]' OR Category9='$gsubrow[0]'
OR Category10='$gsubrow[0]' OR Category11='$gsubrow[0]' OR Category12='$gsubrow[0]'
OR Category13='$gsubrow[0]' OR Category14='$gsubrow[0]' OR Category15='$gsubrow[0]'"; getsubcatids($gsubrow[0], &$catstring); } return $catstring; } } if ($parentrow[0] > 0) $ctsearchquery = str_replace(")", getsubcatids($category) .")", $ctsearchquery); // END MOD - ALSO INCLUDE SUBCATS OF MAIN CATEGORY -
Save and reload the openinfo.php file.
- In the storeadmin area, set Main Categories to Categories or Both.