Crazy-P Posted November 21, 2011 Share Posted November 21, 2011 ** Note to staff. Perhaps should change the title to "How to hide subcategories with empty / non-active products" ** Hei again I am trying to automatically hide subcategories which do not have any active products or just empty. I've tried lots of ways to solve this problem... however another problem always occur me. The BASIC solution I've thought of which will work perfectly and yet not is following: //** REMOVED, Check the code in my second post **// Not perfect and needs to add some extra things to it and change some things of it too.. was just so u got my idea. in the tpl file it would be something like this: //** REMOVED, Check the code in my second post **// I hope u get the idea of what i want to do. So is there a way to do this? Is it even possible to call a function in the smarty tpl? Or do I have to this in another way? //** EDIT **// Found a solution. Will post it later. ** EDIT** It is now posted! Link to comment Share on other sites More sharing options...
Crazy-P Posted November 21, 2011 Author Share Posted November 21, 2011 The fix I made (PS v1.4.4.1) To hide all subcategories you gotta do the following: Open "Category.php" in the classes folder Add this " AND c.`id_category` IN (SELECT `id_category` FROM `'._DB_PREFIX_.'category_product`) " right after " '.($active ? 'AND `active` = 1' : '').' " in line 437. If you couldn't find the line, then go to "function getSubCategories". Then you'll quickly notice where the line should be. Now go a few lines down. You'll then see this: foreach ($result AS &$row) { $row['id_image'] = (file_exists(_PS_CAT_IMG_DIR_.$row['id_category'].'.jpg')) ? (int)($row['id_category']) : Language::getIsoById($id_lang).'-default'; $row['legend'] = 'no picture'; } Change it to this foreach ($result AS &$row) { $row['id_image'] = (file_exists(_PS_CAT_IMG_DIR_.$row['id_category'].'.jpg')) ? (int)($row['id_category']) : Language::getIsoById($id_lang).'-default'; $row['legend'] = 'no picture'; $myslqtv = mysql_query("SELECT * FROM `"._DB_PREFIX_."category_product` WHERE id_category='".$row['id_category']."'"); while ($rowtv = mysql_fetch_array($myslqtv)) { $mysqlpv = mysql_query("SELECT * FROM `"._DB_PREFIX_."product` WHERE id_product='".$rowtv['id_product']."' AND quantity>'0' AND active='1'"); if (mysql_num_rows($mysqlpv) == 1) { $row['legend2'] = "Products exists"; break; } } } Now you're done with the "Category.php" file. So save and upload it Open the "category.tpl" in your theme folder Go to " <!-- Subcategories --> " A few lines down, insert this " {if $subcategory.legend2} " right before the <li> tag And add this " {/if} " right after the </li> end tag You are now done with the "category.tpl" file. So save it and upload it. You are now all set. Remember to enable "Force compile" to make your new "category.tpl" file work. To enable "Force compile" you gotta go to your backend office. Then go to " Preferences " and now click on the tab " Performance ". After "Force compile" is enabled you should go to a category page in your webshop. Afterwards you should disable it again. Using this code on your webshop will be your own responsibility! Link to comment Share on other sites More sharing options...
mmsh Posted August 28, 2012 Share Posted August 28, 2012 hi, how to change the above to hide the THIRD zero products subcategory only? Example: 1main category - 2subcategory - 3subcategory... I have to hide the 3rd tree subcategories with zero products ONLY... thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now