adammontague Posted May 10, 2011 Share Posted May 10, 2011 Hi,I'm in need of a bit of expert help.I would like to display the categories block with only the subcategories of the currently viewed category (does that make sense?!)Any help reeeally appreciated! Link to comment Share on other sites More sharing options...
apug Posted May 12, 2011 Share Posted May 12, 2011 1. Go to your modules folder and make a copy/duplicate of your blockcategories folder and rename it with blockcategories2 for example.2. Enter in the blockcategories2 folder and rename the blockcategories.tpl and blockcategories.php to blockcategories2.tpl and blockcategories2.php.3. Open up your blockcategories2.php and replace all blockcategories words to blockcategories2.4. in blockcategories2.php replace hookLeftColumn method with: public function hookLeftColumn($params) { global $smarty, $cookie; $id_customer = (int)($params['cookie']->id_customer); $id_group = $id_customer ? Customer::getDefaultGroupId($id_customer) : _PS_DEFAULT_CUSTOMER_GROUP_; $id_product = (int)(Tools::getValue('id_product', 0)); $id_category = (int)(Tools::getValue('id_category', 0)); $id_lang = (int)($params['cookie']->id_lang); $smartyCacheId = 'blockcategories2|'.$id_group.'_'.$id_lang.'_'.$id_product.'_'.$id_category; if($id_category) $category = new CategoryCore($id_category,$id_lang); else $category = Category::getRootCategory ($id_lang); $id_category = $category->id; Tools::enableCache(); if (!$this->isCached('blockcategories2.tpl', $smartyCacheId)) { $maxdepth = Configuration::get('BLOCK_CATEG_MAX_DEPTH'); if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT c.id_parent, c.id_category,c.nleft,c.nright, cl.name, cl.description, cl.link_rewrite FROM `'._DB_PREFIX_.'category` c LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = '.$id_lang.') LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = c.`id_category`) WHERE (c.`active` = 1 OR c.`id_category` = 1) '.((int)($maxdepth) != 0 ? ' AND `level_depth` <= '.(int)($maxdepth) : '').' AND cg.`id_group` = '.$id_group.' AND c.nleft >= '.$category->nleft.' AND c.nright <= '.$category->nright.' ORDER BY `level_depth` ASC, c.`position` ASC') ) return; $resultParents = array(); $resultIds = array(); foreach ($result as &$row) { $resultParents[$row['id_parent']][] = &$row; $resultIds[$row['id_category']] = &$row; } $blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH'),$id_category); unset($resultParents); unset($resultIds); $isDhtml = (Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false); if (Tools::isSubmit('id_category')) { $cookie->last_visited_category = $id_category; $smarty->assign('currentCategoryId', $cookie->last_visited_category); } if (Tools::isSubmit('id_product')) { if (!isset($cookie->last_visited_category) OR !Product::idIsOnCategoryId($id_product, array('0' => array('id_category' => $cookie->last_visited_category)))) { $product = new Product($id_product); if (isset($product) AND Validate::isLoadedObject($product)) $cookie->last_visited_category = (int)($product->id_category_default); } $smarty->assign('currentCategoryId', (int)($cookie->last_visited_category)); } $smarty->assign('blockCategTree', $blockCategTree); if (file_exists(_PS_THEME_DIR_.'modules/blockcategories2/blockcategories2.tpl')) $smarty->assign('branche_tpl_path', _PS_THEME_DIR_.'modules/blockcategories2/category-tree-branch.tpl'); else $smarty->assign('branche_tpl_path', _PS_MODULE_DIR_.'blockcategories2/category-tree-branch.tpl'); $smarty->assign('isDhtml', $isDhtml); } $smarty->cache_lifetime = 31536000; // 1 Year $display = $this->display(__FILE__, 'blockcategories2.tpl', $smartyCacheId); Tools::restoreCacheSettings(); return $display; } Credits: steps 1, 2 and 3 come from Dharani's Blog 2 Link to comment Share on other sites More sharing options...
adammontague Posted May 17, 2011 Author Share Posted May 17, 2011 That's great!! I needed to change a couple of lines for it to work exactly how I needed but I wouldn't have had a chance without your help! Thank you! Link to comment Share on other sites More sharing options...
terresdesiem Posted August 23, 2011 Share Posted August 23, 2011 Hi, I would like to do exactly what Adammontague wanted to do. So I have followed all your explanation, but I do not know how to activate my second module "blockcategories2.tpl ". I tried trough the Back Office, but I don't succeded to find how to install this second module : there is no "add new module" button... I'm sure it's very simple... Thanks in advance !! Link to comment Share on other sites More sharing options...
[email protected] Posted September 21, 2011 Share Posted September 21, 2011 Hi All, I too am in need of the same solution i need to display only active or Current category and its subcategory in its respective category page not all the categories , please brief me the steps to do the changes in code in respective files more importantly i am using PRESTASHOP VERSION 1.4.1 please help me in this regard thanks in Advance. Anil Link to comment Share on other sites More sharing options...
divers972 Posted January 10, 2012 Share Posted January 10, 2012 That's work perfectly But how can we undisplay the block in the last category (display of the product list) ? Otherwise, it will display a empty block Link to comment Share on other sites More sharing options...
cheekymang Posted February 16, 2013 Share Posted February 16, 2013 Cracker! Works in 1.5.3.1 I too had trouble setting up a "blockcategories2" module. I was going to research it but I need this done. So I changed the code in my blockcategories.php (yeah I guess I probably shouldn't but it works) changing in the code any reference of "blockcategory2" to "blockcategory" in the code. I also want to undisplay the block in the last category. Time for research. Thanks heaps apug! Link to comment Share on other sites More sharing options...
Supermanzo Posted February 18, 2013 Share Posted February 18, 2013 I have tried this solution on 1.5.3.1 and it works, thanks a lot to apug. I'd like to have a slightly different behaviour, when i'm inside a subcategory (lvl2) if it doesn't have lower levels i don't see anything in the category block, and it's not useful to go back to parent level , Is it possible to change the code in a way that when in lvl2 subcategory it still shows also the lvl 1 parent category? Thanks 2 Link to comment Share on other sites More sharing options...
Claudio DiSouza Posted April 13, 2013 Share Posted April 13, 2013 I have tried this solution on 1.5.3.1 and it works, thanks a lot to apug. I'd like to have a slightly different behaviour, when i'm inside a subcategory (lvl2) if it doesn't have lower levels i don't see anything in the category block, and it's not useful to go back to parent level , Is it possible to change the code in a way that when in lvl2 subcategory it still shows also the lvl 1 parent category? Thanks Good Sugestion... Please Apug ... Help Us. 1 Link to comment Share on other sites More sharing options...
thkalam Posted May 13, 2013 Share Posted May 13, 2013 Hello i ve tried all these to 1.5.4 and nothing happened! Any suggestions? I have changed my allready blockcategory module cause i didn t want to use a new one Link to comment Share on other sites More sharing options...
kevin78 Posted December 17, 2013 Share Posted December 17, 2013 Hello the solution doesnt work on 1.5.4.1 any solution please ? 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