mr tom Posted September 22, 2010 Share Posted September 22, 2010 Hello I am new to prestashop i have found most of it easy to edit, I am having one big issue ...I have a horizontal navigation for the main departments of the shop Kitchen, bathroom etc. I need to make the shop change the left column catogories depending on the department so kitchen woul display links to sink, cupboards etc..Any help would be great please as i have tried with no joy..I tried modifing a few posts i have seen on here to add unique code depending on the categorie ID but it didnt work.. Link to comment Share on other sites More sharing options...
mr tom Posted September 22, 2010 Author Share Posted September 22, 2010 I know it must be diffucult anyone up to the challenge Link to comment Share on other sites More sharing options...
rocky Posted September 23, 2010 Share Posted September 23, 2010 Try changing lines 123-141 of modules/blockcategories/blockcategories.php (in PrestaShop v1.3.1) from: $blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH')); $isDhtml = (Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false); if (isset($_GET['id_category'])) { $cookie->last_visited_category = intval($_GET['id_category']); $smarty->assign('currentCategoryId', intval($_GET['id_category'])); } if (isset($_GET['id_product'])) { if (!isset($cookie->last_visited_category) OR !Product::idIsOnCategoryId(intval($_GET['id_product']), array('0' => array('id_category' => $cookie->last_visited_category)))) { $product = new Product(intval($_GET['id_product'])); if (isset($product) AND Validate::isLoadedObject($product)) $cookie->last_visited_category = intval($product->id_category_default); } $smarty->assign('currentCategoryId', intval($cookie->last_visited_category)); } $smarty->assign('blockCategTree', $blockCategTree); to: $isDhtml = (Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false); $currentCategoryId = 1; if (isset($_GET['id_category'])) { $currentCategoryId = intval($_GET['id_category']); $cookie->last_visited_category = $currentCategoryId; $smarty->assign('currentCategoryId', $currentCategoryId); } if (isset($_GET['id_product'])) { if (!isset($cookie->last_visited_category) OR !Product::idIsOnCategoryId(intval($_GET['id_product']), array('0' => array('id_category' => $cookie->last_visited_category)))) { $product = new Product(intval($_GET['id_product'])); if (isset($product) AND Validate::isLoadedObject($product)) $cookie->last_visited_category = intval($product->id_category_default); } $currentCategoryId = intval($cookie->last_visited_category); $smarty->assign('currentCategoryId', $currentCategoryId); } $blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH'), $currentCategoryId); $smarty->assign('blockCategTree', $blockCategTree); Link to comment Share on other sites More sharing options...
mr tom Posted September 23, 2010 Author Share Posted September 23, 2010 Try changing lines 123-141 of modules/blockcategories/blockcategories.php (in PrestaShop v1.3.1) from: $blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH')); $isDhtml = (Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false); if (isset($_GET['id_category'])) { $cookie->last_visited_category = intval($_GET['id_category']); $smarty->assign('currentCategoryId', intval($_GET['id_category'])); } if (isset($_GET['id_product'])) { if (!isset($cookie->last_visited_category) OR !Product::idIsOnCategoryId(intval($_GET['id_product']), array('0' => array('id_category' => $cookie->last_visited_category)))) { $product = new Product(intval($_GET['id_product'])); if (isset($product) AND Validate::isLoadedObject($product)) $cookie->last_visited_category = intval($product->id_category_default); } $smarty->assign('currentCategoryId', intval($cookie->last_visited_category)); } $smarty->assign('blockCategTree', $blockCategTree); to: $isDhtml = (Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false); $currentCategoryId = 1; if (isset($_GET['id_category'])) { $currentCategoryId = intval($_GET['id_category']); $cookie->last_visited_category = $currentCategoryId; $smarty->assign('currentCategoryId', $currentCategoryId)); } if (isset($_GET['id_product'])) { if (!isset($cookie->last_visited_category) OR !Product::idIsOnCategoryId(intval($_GET['id_product']), array('0' => array('id_category' => $cookie->last_visited_category)))) { $product = new Product(intval($_GET['id_product'])); if (isset($product) AND Validate::isLoadedObject($product)) $cookie->last_visited_category = intval($product->id_category_default); } $currentCategoryId = intval($cookie->last_visited_category); $smarty->assign('currentCategoryId', $currentCategoryId); } $blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH'), $currentCategoryId); $smarty->assign('blockCategTree', $blockCategTree); Thank you for the reply but this makes the website not show up at all, i made sure to place it correctly but nothing but white scene show up.. Link to comment Share on other sites More sharing options...
rocky Posted September 23, 2010 Share Posted September 23, 2010 I accidentally added an extra ) on one of the lines. I've corrected my code above. Please try again. Link to comment Share on other sites More sharing options...
mr tom Posted September 23, 2010 Author Share Posted September 23, 2010 Thank you works a treat if you have the time could you explain the code to me ..... only if you have time if not dont worry thanx a lot Link to comment Share on other sites More sharing options...
rocky Posted September 23, 2010 Share Posted September 23, 2010 Basically, it passes the current category ID into the getTree function instead of the home category ID, so that it generates a subtree instead of the whole tree. Link to comment Share on other sites More sharing options...
mr tom Posted September 23, 2010 Author Share Posted September 23, 2010 That is great what is best place to learn more about smarty php as i know basic php and html but prestashop also has smarty php doesnt it.... Link to comment Share on other sites More sharing options...
rocky Posted September 23, 2010 Share Posted September 23, 2010 See here. Link to comment Share on other sites More sharing options...
mr tom Posted September 23, 2010 Author Share Posted September 23, 2010 Thank you again i will start to learn it ... Link to comment Share on other sites More sharing options...
SonnyBoyII Posted May 3, 2011 Share Posted May 3, 2011 Hi,Let say I have 5 category levels0,1, 2, 3, etcI would like to display in "block categories" only 2 current levels.If I click on level 2 - only categories from lev 2 and lev 3 will be displaing. If I click on category level 3 - only level 3 and 4 will be displaing. I hope that makes sense.HOW TO DO THAT IN PS 1.4??Please, help me Link to comment Share on other sites More sharing options...
SonnyBoyII Posted May 4, 2011 Share Posted May 4, 2011 Any help, please?... Rocky? Link to comment Share on other sites More sharing options...
rocky Posted May 4, 2011 Share Posted May 4, 2011 My AJAX Sliding Categories module has the option to hide parent categories and sub-subcategories like you want. Unfortunately, the code is too complex for me to simply paste the part of my code that does it here. Link to comment Share on other sites More sharing options...
SonnyBoyII Posted May 4, 2011 Share Posted May 4, 2011 I dont need AJAX sliding feature, just the simpler way to display curent category and their subcategory. Hardcoded sollution. Please, help me, I need to finish the project ASAP. Link to comment Share on other sites More sharing options...
SonnyBoyII Posted May 4, 2011 Share Posted May 4, 2011 Rocky, can you give me just a guide, which varaiable shall I play with in blockcategory.php? Link to comment Share on other sites More sharing options...
rocky Posted May 4, 2011 Share Posted May 4, 2011 I had a quick look and it looks like you change the query on lines 150-158 of modules/blockcategories/blockcategories.php (in PrestaShop v1.4.1): if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT c.id_parent, c.id_category, 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.' ORDER BY `level_depth` ASC, c.`position` ASC') Change 1 to the current category (or leave it at 1 for other pages), then add a subquery to get the child categories of the current category and another subquery to get the children of those categories. Link to comment Share on other sites More sharing options...
SonnyBoyII Posted May 4, 2011 Share Posted May 4, 2011 Is that the only way? I am not good at SQL quarys... I thought I might use some simple php if/else statements ... Link to comment Share on other sites More sharing options...
rocky Posted May 4, 2011 Share Posted May 4, 2011 You could modify the Smarty templates instead of the SQL query, but then every category will be loaded and just the ones you want displayed, which will slow down your website. Change the query from: if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT c.id_parent, c.id_category, 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` = '.$id_category.' OR c.`id_category` IN (SELECT `id_category` FROM `'._DB_PREFIX_.'category` WHERE `id_parent` = '.$id_category.') OR (SELECT `id_category` FROM `'._DB_PREFIX_.'category` WHERE `id_parent` IN (SELECT `id_category` FROM `'._DB_PREFIX_.'category` WHERE `id_parent` = '.$id_category.')) AND cg.`id_group` = '.$id_group.' ORDER BY `level_depth` ASC, c.`position` ASC') to: if (isset($_GET['id_category'])) $category = (int)$_GET['id_category']; elseif (isset($_GET['id_product']) AND isset($cookie->last_visited_category)) $category = (int)$cookie->last_visited_category; elseif (isset($_GET['id_product'])) { $product = new Product((int)$_GET['id_product']); if (Validate::isLoadedObject($product)) $category = $product->id_category_default; } else $category = 1; if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT c.id_parent, c.id_category, 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` = '.$category.') AND (c.`id_category` = '.$category.' OR c.`id_parent` = '.$category.' OR c.`id_parent` IN (SELECT `id_category` FROM `'._DB_PREFIX_.'category` WHERE `id_parent` = '.$category.')) AND cg.`id_group` = '.$id_group.' ORDER BY `level_depth` ASC, c.`position` ASC') ) return; and line 183 from: $blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH')); to: $blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH'), $category); Link to comment Share on other sites More sharing options...
SonnyBoyII Posted May 4, 2011 Share Posted May 4, 2011 THANKS ROCKY!You saved my life! I would never found the sollution without your help. Link to comment Share on other sites More sharing options...
SonnyBoyII Posted May 4, 2011 Share Posted May 4, 2011 uuups, there is a small bug. Now, subcategories in the category box are displaing twice.like this: mens:-red tshirt-red tshirt-blue shorts-blue shortswomens:green skirtgreen skirtetc Link to comment Share on other sites More sharing options...
SonnyBoyII Posted May 4, 2011 Share Posted May 4, 2011 can you help me, Rocky, pleeease? Link to comment Share on other sites More sharing options...
rocky Posted May 5, 2011 Share Posted May 5, 2011 Strange. It's working fine on my PrestaShop v1.4.1 test site. Check to see whether $id_lang is being defined above the code you replaced. If not, you will need to change $id_lang to (int)$cookie->id_lang Link to comment Share on other sites More sharing options...
SonnyBoyII Posted May 5, 2011 Share Posted May 5, 2011 if i replace$id_lang = (int)($params['cookie']->id_lang);to(int)$cookie->id_lang = (int)($params['cookie']->id_lang);category box displays nothing....It must be an issue with cashing or something, i'm sure it was working properly for just few minutes of tests at the begining.Now, im getting all subcategories doubledI have my PS14 switched to 'developing mode' (cashing off, etc) Link to comment Share on other sites More sharing options...
rocky Posted May 5, 2011 Share Posted May 5, 2011 In that case, you shoudn't have changed that line. It should be working. I have no idea why it isn't. Link to comment Share on other sites More sharing options...
SonnyBoyII Posted May 10, 2011 Share Posted May 10, 2011 uuups, there is a small bug. Now, subcategories in the category box are displaing twice.like this: mens:-red tshirt-red tshirt-blue shorts-blue shortswomens:green skirtgreen skirtetc There is a bug in PS1.4, thats why Im getting duplicated category.http://forge.prestashop.com/browse/PSCFI-1616?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel#issue-tabsRocky's modification WORKS PERFECT!!!Thanks for your time Rocky!!regardsSonnyBoyII Link to comment Share on other sites More sharing options...
irina231 Posted May 26, 2011 Share Posted May 26, 2011 Thanks a lot Rocky !!! Link to comment Share on other sites More sharing options...
irina231 Posted May 26, 2011 Share Posted May 26, 2011 Sorry for my english, but, how can I do with the block categories to display only the parent category (level depth 2) and children ?I would like the same behaviour that the original blockcategories (without javascript) but without other categories than the current one with children.To resume, I would like to hide the other level 2 categories and just show the current one with children.Maybe better with an example HereAgain, sorry for my english... I hope you will understand. Thank you Link to comment Share on other sites More sharing options...
rocky Posted May 27, 2011 Share Posted May 27, 2011 The code above gets the subcategories and sub-subcategories of the current category. To get the subcategories only, use: if (isset($_GET['id_category'])) $category = (int)$_GET['id_category']; elseif (isset($_GET['id_product']) AND isset($cookie->last_visited_category)) $category = (int)$cookie->last_visited_category; elseif (isset($_GET['id_product'])) { $product = new Product((int)$_GET['id_product']); if (Validate::isLoadedObject($product)) $category = $product->id_category_default; } else $category = 1; if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT c.id_parent, c.id_category, 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` = '.$category.') AND (c.`id_category` = '.$category.' OR c.`id_parent` = '.$category.')) AND cg.`id_group` = '.$id_group.' ORDER BY `level_depth` ASC, c.`position` ASC') ) return; Link to comment Share on other sites More sharing options...
irina231 Posted May 27, 2011 Share Posted May 27, 2011 The code above gets the subcategories and sub-subcategories of the current category. To get the subcategories only, use: if (isset($_GET['id_category'])) $category = (int)$_GET['id_category']; elseif (isset($_GET['id_product']) AND isset($cookie->last_visited_category)) $category = (int)$cookie->last_visited_category; elseif (isset($_GET['id_product'])) { $product = new Product((int)$_GET['id_product']); if (Validate::isLoadedObject($product)) $category = $product->id_category_default; } else $category = 1; if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT c.id_parent, c.id_category, 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` = '.$category.') AND (c.`id_category` = '.$category.' OR c.`id_parent` = '.$category.')) AND cg.`id_group` = '.$id_group.' ORDER BY `level_depth` ASC, c.`position` ASC') ) return; Thanks for your response but that code doesn't return anything. I would like to have the same behaviour that this website for my bloc categories module..I attached a quick mock up of what I would like. (Fruits & Legumes is a child of "Accueil" category)Thank you for your time Link to comment Share on other sites More sharing options...
SonnyBoyII Posted June 3, 2011 Share Posted June 3, 2011 Now, something mutch easier, I hope How to display always just categories from level 2 and 3 ??If we go eaven deeper, level 2 and 3 still will be displayed on category block.thanks guys! Link to comment Share on other sites More sharing options...
SonnyBoyII Posted June 3, 2011 Share Posted June 3, 2011 You could modify the Smarty templates instead of the SQL query, but then every category will be loaded and just the ones you want displayed, which will slow down your website. Change the query from: if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT c.id_parent, c.id_category, 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` = '.$id_category.' OR c.`id_category` IN (SELECT `id_category` FROM `'._DB_PREFIX_.'category` WHERE `id_parent` = '.$id_category.') OR (SELECT `id_category` FROM `'._DB_PREFIX_.'category` WHERE `id_parent` IN (SELECT `id_category` FROM `'._DB_PREFIX_.'category` WHERE `id_parent` = '.$id_category.')) AND cg.`id_group` = '.$id_group.' ORDER BY `level_depth` ASC, c.`position` ASC') to: if (isset($_GET['id_category'])) $category = (int)$_GET['id_category']; elseif (isset($_GET['id_product']) AND isset($cookie->last_visited_category)) $category = (int)$cookie->last_visited_category; elseif (isset($_GET['id_product'])) { $product = new Product((int)$_GET['id_product']); if (Validate::isLoadedObject($product)) $category = $product->id_category_default; } else $category = 1; if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT c.id_parent, c.id_category, 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` = '.$category.') AND (c.`id_category` = '.$category.' OR c.`id_parent` = '.$category.' OR c.`id_parent` IN (SELECT `id_category` FROM `'._DB_PREFIX_.'category` WHERE `id_parent` = '.$category.')) AND cg.`id_group` = '.$id_group.' ORDER BY `level_depth` ASC, c.`position` ASC') ) return; and line 183 from: $blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH')); to: $blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH'), $category); Rocky,could you help me please? how to modify this code to display only level 2 and 3? If you go to level 4 for example nothing will change. Module will still display 2 and 3 level. Link to comment Share on other sites More sharing options...
SonnyBoyII Posted June 3, 2011 Share Posted June 3, 2011 any help, please ...I think I could use standard code, set max level deph to 3, swith off ajax feature, and modify the code to ignore just level 1.Do you have any idea how to do it? ive been trying but no succes .... Link to comment Share on other sites More sharing options...
rocky Posted June 4, 2011 Share Posted June 4, 2011 I don't really understand what you are trying to do, but if I wanted to ignore the first-level categories, I'd change lines 33-37 of modules/blockcategories/blockcategories.tpl from: {if $smarty.foreach.blockCategTree.last} {include file="$branche_tpl_path" node=$child last='true'} {else} {include file="$branche_tpl_path" node=$child} {/if} to: {if $smarty.foreach.blockCategTree.last} {include file="$branche_tpl_path" node=$child depth=1 last='true'} {else} {include file="$branche_tpl_path" node=$child depth=1} {/if} and modules/blockcategories/category-tree-branch.tpl from: > <a href="{$node.link}" {if isset($currentCategoryId) && ($node.id == $currentCategoryId)}class="selected"{/if} title="{$node.desc|escape:html:'UTF-8'}">{$node.name|escape:html:'UTF-8'} {if $node.children|@count > 0} </pre> <ul> {foreach from=$node.children item=child name=categoryTreeBranch} {if isset($smarty.foreach.categoryTreeBranch) && $smarty.foreach.categoryTreeBranch.last} {include file="$branche_tpl_path" node=$child last='true'} {else} {include file="$branche_tpl_path" node=$child last='false'} {/if} {/foreach} </ul> <br> {/if}<br to: > {if $depth > 1} <a href="{$node.link}" {if isset($currentCategoryId) && ($node.id == $currentCategoryId)}class="selected"{/if} title="{$node.desc|escape:html:'UTF-8'}">{$node.name|escape:html:'UTF-8'}{/if} {if $node.children|@count > 0} {if $depth > 1}</pre> <ul>{/if} {foreach from=$node.children item=child name=categoryTreeBranch} {if isset($smarty.foreach.categoryTreeBranch) && $smarty.foreach.categoryTreeBranch.last} {include file="$branche_tpl_path" node=$child last='true'} {else} {include file="$branche_tpl_path" node=$child last='false'} {/if} {/foreach} {if $depth > 1}</ul>{/if}<br> {/if}<br>{if $depth > 1}{/if Link to comment Share on other sites More sharing options...
SonnyBoyII Posted June 4, 2011 Share Posted June 4, 2011 Thanks rocky! I generally will have first level hardcoded on the top menu. On the side standard categories module will be displaing allays only second and third level. If you go deeper nothing happens. Side category still will be displaing 3, 4 level Link to comment Share on other sites More sharing options...
rocky Posted June 4, 2011 Share Posted June 4, 2011 Try changing: if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT c.id_parent, c.id_category, 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` = '.$id_category.' OR c.`id_category` IN (SELECT `id_category` FROM `'._DB_PREFIX_.'category` WHERE `id_parent` = '.$id_category.') OR (SELECT `id_category` FROM `'._DB_PREFIX_.'category` WHERE `id_parent` IN (SELECT `id_category` FROM `'._DB_PREFIX_.'category` WHERE `id_parent` = '.$id_category.')) AND cg.`id_group` = '.$id_group.' ORDER BY `level_depth` ASC, c.`position` ASC') to: if (isset($_GET['id_category'])) $category = (int)$_GET['id_category']; elseif (isset($_GET['id_product']) AND isset($cookie->last_visited_category)) $category = (int)$cookie->last_visited_category; elseif (isset($_GET['id_product'])) { $product = new Product((int)$_GET['id_product']); if (Validate::isLoadedObject($product)) $category = $product->id_category_default; } else $category = 1; $categoryObject = new Category($category); while (Validate::isLoadedObject($categoryObject) AND $categoryObject->id_parent > 1) $categoryObject = new Category($categoryObject->id_parent); $category = $categoryObject->id_category; if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT c.id_parent, c.id_category, 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` = '.$category.') AND (c.`id_category` = '.$category.' OR c.`id_parent` = '.$category.' OR c.`id_parent` IN (SELECT `id_category` FROM `'._DB_PREFIX_.'category` WHERE `id_parent` = '.$category.')) AND cg.`id_group` = '.$id_group.' ORDER BY `level_depth` ASC, c.`position` ASC') ) return; This should find the top-level parent category of the current category, then get the first two levels. Link to comment Share on other sites More sharing options...
SonnyBoyII Posted June 4, 2011 Share Posted June 4, 2011 Thanks rocky! I generally will have first level hardcoded on the top menu. On the side standard categories module will be displaing allays only second and third level. If you go deeper nothing happens. Side category still will be displaing 3, 4 level Sorry, i ment allways second and third , if you go by clicking categorie thumbnails to for example 7th level, side category module still shows 2,3 . Link to comment Share on other sites More sharing options...
rocky Posted June 4, 2011 Share Posted June 4, 2011 I thought the code in my previous post did that. Did it not work? Link to comment Share on other sites More sharing options...
SonnyBoyII Posted June 4, 2011 Share Posted June 4, 2011 It works if I add this line $blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH'), $category); but not exactly like I want.I would like to display only level 2, 3 but counting always from the level 1 (home).If we go to level 8 module should display level 2,3 of this branch.Deeper levels will be available from category thumbnails. Link to comment Share on other sites More sharing options...
rocky Posted June 5, 2011 Share Posted June 5, 2011 It seems what you want is too complicated. Unfortunately, I can't understand what you want. Link to comment Share on other sites More sharing options...
SonnyBoyII Posted June 5, 2011 Share Posted June 5, 2011 It seems what you want is too complicated. Unfortunately, I can't understand what you want. I would like to display in category box only level 2,3 from current branch. only thismens >> tshirt >> funny_tshirt >> >> red>>tshirts >> tshirt_with_stripes >>we_are_hereorwomens >> skirts>> short_skirts>> >> dark_skirts>>we_are_here >> .....sorry for confusionregards,Matt Link to comment Share on other sites More sharing options...
rocky Posted June 5, 2011 Share Posted June 5, 2011 I just tested the code I last posted and the code you last posted and it seems to be doing what you want. I had to go to Preferences > Performance and disable the Smarty cache for the category tree to be regenerated though. Link to comment Share on other sites More sharing options...
rocky Posted June 6, 2011 Share Posted June 6, 2011 Turns out there was a bug in my code above. I wasn't testing with a high enough depth. I've now fixed my code above. Link to comment Share on other sites More sharing options...
SonnyBoyII Posted June 6, 2011 Share Posted June 6, 2011 Turns out there was a bug in my code above. I wasn't testing with a low enough depth. I've now fixed my code above. THANK YOU ROCKY !!! Link to comment Share on other sites More sharing options...
she Posted July 1, 2011 Share Posted July 1, 2011 i happened to have this problem too.. thank to Mr. Rocky..You Rock ;-) Link to comment Share on other sites More sharing options...
maxkdiv Posted July 4, 2011 Share Posted July 4, 2011 I'm running PS 1.4.3. it's not clear to me which files have to be changed to display only the subcategories of the selected category. may someone please help me? Link to comment Share on other sites More sharing options...
she Posted July 8, 2011 Share Posted July 8, 2011 hello mr. rockyi have a question please.is it possible to make the blockcategories to start from a selected category down the last subcategory?wat i was able to do with the help of your posts was to make the blockcategories display JUST TWO subcategories and when i click into the subcategory the tree is gone because there is no subcategoryIs it possible sir? Link to comment Share on other sites More sharing options...
[email protected] Posted September 21, 2011 Share Posted September 21, 2011 Hi Rocky, thanks for u r continuous support for the new users in Prestashop, Iam very new to prestashop and am using version 1.4.1 now i have an issue regarding displaying the categories, the thing is that i want to display only active Category (the one i have selected) and its Subcategories in my page and other categories should not be displayed is that possible and please brief me all the steps in respective files to do the needed changes that will help me a lot. Anil Bangalore Link to comment Share on other sites More sharing options...
juanmiguelfp Posted January 3, 2013 Share Posted January 3, 2013 Hi People, I'm trying to do this for prestashop 1.5 i show you my code. this is my ../blockcategories.tpl {if $page_name!="index"} <!-- Block categories module --> <div id="categories_block_left" class="block"> <!-- <h4>{l s='Categories' mod='blockcategories'}</h4> --> <div class="block_content"> <ul class="tree"> <!-- <ul class="tree {if $isDhtml}dhtml{/if}"> --> {foreach from=$blockCategTree.children item=child name=blockCategTree} {* here i need to put the correct principal child from a root category and show it *} {* now it only works for the first child of the tree and if i click on this in the horizontal menu*} {if $currentCategoryId == $child.id} {if $smarty.foreach.blockCategTree.last} {include file="$branche_tpl_path" node=$child last='true' } {else} {include file="$branche_tpl_path" node=$child } {/if} {/if} {/foreach} </ul> {* Javascript moved here to fix bug #PSCFI-151 *} <!-- <script type="text/javascript"> // <![CDATA[ // we hide the tree only if JavaScript is activated $('div#categories_block_left ul.dhtml').hide(); // ]]> </script> --> </div> </div> <!-- /Block categories module --> {/if} I only need to pass the principal child that content the currentcategory. i´m thinking in 3 options: A - Create with smarty a recurrent function (i had been looking for information in http://www.smarty.net but is a little confused and i suppose is slow) B - With Javascript DOM. To Hidden the unnecesary nodes. (but i will have to change the actual code i had here) C - Generate the blockCategoryTree correct in each time. I think it's the most efficient choice but i need some help. It would be more easy if the code in prestashop was commented. (it's is a suggestion for developers) Link to comment Share on other sites More sharing options...
juanmiguelfp Posted January 3, 2013 Share Posted January 3, 2013 (edited) This is more or less what i mean {foreach from=$blockCategTree.children item=child name=blockCategTree} {* is $currentCategoryId descendant of $child.id *} {if is_descendant_of($currentCategoryId , $child.id)} {if $smarty.foreach.blockCategTree.last} {include file="$branche_tpl_path" node=$child last='true' } {else} {include file="$branche_tpl_path" node=$child } {/if} {/if} {/foreach} Edited January 3, 2013 by juanmiguelfp (see edit history) 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