Jump to content

(Hide category) Call a function in tpl theme or another workaround?


Crazy-P

Recommended Posts

** 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

The fix I made (PS v1.4.4.1)

 

To hide all subcategories you gotta do the following:

  1. Open "Category.php" in the classes folder
  2. 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.
  3. 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';
    }

  4. 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;
    }
    }
    }

  5.  
    Now you're done with the "Category.php" file. So save and upload it

  6.  
    Open the "category.tpl" in your theme folder

  7.  
    Go to " <!-- Subcategories --> "

  8.  
    A few lines down, insert this " {if $subcategory.legend2} " right before the <li> tag

  9.  
    And add this " {/if} " right after the </li> end tag

  10.  
    You are now done with the "category.tpl" file. So save it and upload it.

  11.  
    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

  • 9 months later...

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...