nogy Posted November 13, 2013 Share Posted November 13, 2013 Hello guys! I saw a lot of information about that, but I can't got the solution. I would like to put DIFFERENT and CUSTOM icons for my Category's on Vertical Menu, like the image below. Is it possible? Thank you! Link to comment Share on other sites More sharing options...
Paul de Cocq Posted November 15, 2013 Share Posted November 15, 2013 (edited) Hi, with css it's pretty easy, u can add the following code in style.css in you're theme. you only have to adjust it to your own preferences. excuse me if it's not what you meant. option 1: Add a class to each category like: li.image-1 {background:url('your-image.png') left top no-repeat;} li.image-1 > a {padding-left:20px;} option 2: Add an "after" to the list item (be sure you're list-item is position:relative;) like: li {position:relative;} li:after {content:'';background:url('your-image.png') left top no-repeat;position:absolute;top:0;left:0;width:20px;height:20px;} option 3: Give the list item an data-attribute like: *html <li data-attr="image-1"> <li data-attr="image-2"> *css [data-attr] {display:inline-block;height:20px;width:20px;background-position:left top;} [data-attr=image-1] {background-image:url(your-image-1.png);} [data-attr=image-2] {background:url(your-image-2.png);} Edited November 15, 2013 by Paul de Cocq (see edit history) 1 Link to comment Share on other sites More sharing options...
ALMAJ Posted March 21, 2014 Share Posted March 21, 2014 (edited) Hi, with css it's pretty easy, u can add the following code in style.css in you're theme. you only have to adjust it to your own preferences. excuse me if it's not what you meant. option 1: Add a class to each category like: li.image-1 {background:url('your-image.png') left top no-repeat;} li.image-1 > a {padding-left:20px;} option 2: Add an "after" to the list item (be sure you're list-item is position:relative;) like: li {position:relative;} li:after {content:'';background:url('your-image.png') left top no-repeat;position:absolute;top:0;left:0;width:20px;height:20px;} option 3: Give the list item an data-attribute like: *html <li data-attr="image-1"> <li data-attr="image-2"> *css [data-attr] {display:inline-block;height:20px;width:20px;background-position:left top;} [data-attr=image-1] {background-image:url(your-image-1.png);} [data-attr=image-2] {background:url(your-image-2.png);} Hey Paul de Cocq, thanks for your help but if i want fontawesome on my icons for example where do I put this?: <i class="fa fa-laptop"></i> thanks! Edited March 22, 2014 by majority (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted March 22, 2014 Share Posted March 22, 2014 in this case it's necessary to modify blockcategories module template file it will be a bit hard to achieve because you have to create many if conditions: category-tree-branch.tpl there is a code: <a href="{$node.link|escape:'html':'UTF-8'}" {if isset($currentCategoryId) && $node.id == $currentCategoryId}class="selected"{/if} title="{$node.desc|strip_tags|trim|truncate:255:'...'|escape:'html':'UTF-8'}"> {$node.name|escape:'html':'UTF-8'} </a> add there if condition like: {if $node.id==5} <i class="fa fa-laptop"></i> {/if} {if $node.id==10} <i class="fa fa-anothericon"></i> {/if} {if $node.id==12} <i class="fa fa-example"></i> {/if} example: <a href="{$node.link|escape:'html':'UTF-8'}" {if isset($currentCategoryId) && $node.id == $currentCategoryId}class="selected"{/if} title="{$node.desc|strip_tags|trim|truncate:255:'...'|escape:'html':'UTF-8'}"> {if $node.id==5} <i class="fa fa-laptop"></i> {/if} {if $node.id==10} <i class="fa fa-anothericon"></i> {/if} {if $node.id==12} <i class="fa fa-example"></i> {/if} {$node.name|escape:'html':'UTF-8'} </a> 3 Link to comment Share on other sites More sharing options...
ALMAJ Posted March 22, 2014 Share Posted March 22, 2014 (edited) Thanks Vekia, it works great! you make everything easy man there is already a module made from OnlineRSI developer here to add icons (images) to Category, but it's not working since prestashop 1.5.6.x, and do not support for vector icons (fontawesome) Since all your modules are great and very professional, I think YOU should make a module like this (paid module) with support for prestashop 1.5.x.x and Prestashop 1.6.x.x, support for images and vector (fontawesome) icons, look at this great category: here The comunity would love it, even I would buy it! Thanks Edited March 22, 2014 by majority (see edit history) Link to comment Share on other sites More sharing options...
ALMAJ Posted March 22, 2014 Share Posted March 22, 2014 (edited) So this is the result of a many hours of customization and the comparison between my custom category block a the default prestashop 1.5.x.x block beautiful, better than prestashop 1.6 default category block Edited March 22, 2014 by majority (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted March 22, 2014 Share Posted March 22, 2014 majority... WOW! looks amazing i think that it should be a part of default module features, possibility to define icon for category nice idea about new module i think that i include this feature to my multiple categories block addon 3 Link to comment Share on other sites More sharing options...
ALMAJ Posted March 22, 2014 Share Posted March 22, 2014 (edited) Thanks Yes, I think this design should be part of default modules features of prestashop icons make a huge visual impact for customers! and its more practical having an icon to describe a category than just text, it can substantially help customers to find a category much more quickly specially for mobile devices. I'm very proud how the final design turns out, the icons part was thanks to you Vekia! THANK YOU! I just need more one thing to make it perfect, and that is: How to toggle hide and show the content of the category block? Thanks again! Edited March 22, 2014 by majority (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted March 22, 2014 Share Posted March 22, 2014 and that is: How to toggle hide and show the content of the category block? you mean that you want to disable the [+] [-] ? (you want to dsplay all categories with their subcategories?) 1 Link to comment Share on other sites More sharing options...
ALMAJ Posted March 22, 2014 Share Posted March 22, 2014 No, what i mean is collapsing all the content inside category main block like this: I've tried various methods but fail miserably cheers Link to comment Share on other sites More sharing options...
ALMAJ Posted March 23, 2014 Share Posted March 23, 2014 (edited) Hi again vekia, I have another question and would be great if you could answer the solution you made on post #4 works great but if I want to make the same thing on Top Menu Block based on the same logic, it seams impossible (at least for me) as I don't have any nodes Ids to call like in the category branch, I want to achieve this: has you can see in the image (made in photoshop) I want to have an icon instead of Text (HOME) how can this be possible? UPDATE: I've found this in BO: it's not a "li class" but a "Option Value" how can i implement this? I've tried this: {/if} {if $option.value==LNK2} <i class="fa fa-bolt"></i> {/if} nothing! then this: {/if} <option value="LNK2">HOME</option> <i class="fa fa-bolt"></i> {/if} nothing! PS: sorry nogy for hijacking your topic Tanks again. Best regards Edited March 23, 2014 by ALMAJ (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted March 23, 2014 Share Posted March 23, 2014 it's more complicated. it's because block top menu generates contents in php file, not as it is in blockcategories module. in this case it's necessary to modify php file. you can use the same idea, but code will be a little different. $this->_menu .= '<li '.$selected.'>'; $this->_menu .= '<a href="'.Tools::HtmlEntitiesUTF8($category_link).'">'.$category->name.'</a>'; change to: $this->_menu .= '<li '.$selected.'>'; $this->_menu .= '<a href="'.Tools::HtmlEntitiesUTF8($category_link).'">'.(if $category->id==2 ? '<i class="fa fa-anothericon"></i>':'').$category->name.'</a>'; create as many if conditions as you want (in the same way, it's a shorthand if ) Link to comment Share on other sites More sharing options...
ALMAJ Posted March 23, 2014 Share Posted March 23, 2014 (edited) it's more complicated. it's because block top menu generates contents in php file, not as it is in blockcategories module. in this case it's necessary to modify php file. you can use the same idea, but code will be a little different. $this->_menu .= '<li '.$selected.'>'; $this->_menu .= '<a href="'.Tools::HtmlEntitiesUTF8($category_link).'">'.$category->name.'</a>'; change to: $this->_menu .= '<li '.$selected.'>'; $this->_menu .= '<a href="'.Tools::HtmlEntitiesUTF8($category_link).'">'.(if $category->id==2 ? '<i class="fa fa-anothericon"></i>':'').$category->name.'</a>'; create as many if conditions as you want (in the same way, it's a shorthand if ) Tanks for the quickly reply vekia but unfortunately I can't make it work I get the logic but it's not working with me What I did: open the file "/modules/blocktopmenu/blocktopmenu.php Find: $this->_menu .= '<li '.$selected.'>'; $this->_menu .= '<a href="'.Tools::HtmlEntitiesUTF8($category_link).'">'.$category->name.'</a>'; and Changed to: $this->_menu .= '<li '.$selected.'>'; $this->_menu .= '<a href="'.Tools::HtmlEntitiesUTF8($category_link).'">'.(if $category->id==2 ? '<i class="fa fa-home"></i>':'').$category->Home.'</a>'; I get a blank page tanks again Edited March 23, 2014 by ALMAJ (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted March 24, 2014 Share Posted March 24, 2014 its probably my mistake in code remove "if" instead of (if $category->id==2 ? '<i class="fa fa-home"></i>':'') use ($category->id==2 ? '<i class="fa fa-home"></i>':'') Link to comment Share on other sites More sharing options...
ALMAJ Posted March 24, 2014 Share Posted March 24, 2014 Tanks vekia but It's not working, (at least now I don't get a blank page) this means the code it's not broken but i cannot get to see the icon, do I must change this values?: ($category_link).'">'.$category->name. to this: ($http://www.tekcenter.pt/store).'">'.$category->Home. i think I'm missing something... tanks again for your effort Vekia, I really appreciate your valuable help Regards Link to comment Share on other sites More sharing options...
vekia Posted March 24, 2014 Share Posted March 24, 2014 now try to rebuild module, it's necessary. go to module configuration page and just hit save button module code will be regenerated hope that with new icon Link to comment Share on other sites More sharing options...
sooroos Posted March 24, 2014 Share Posted March 24, 2014 (edited) i didnt exactly understand what are you trying to achieve. but if you want to set background for top menus you can simply use some thing like: .sf-menu>li+li+li {background:url('../img/menu1.jpg') no-repeat top} or .sf-menu li:nth-child(3) {background:url('../img/menu2.jpg') no-repeat top} ihave used here Edited March 24, 2014 by sooroos (see edit history) Link to comment Share on other sites More sharing options...
ALMAJ Posted March 24, 2014 Share Posted March 24, 2014 sorry vekia it's not working I've rebuild the module top menu as you said and I get no icon... but if i put the "<i class="fa fa-home"></i>" from here: $this->_menu .= '<li '.$selected.'>'; $this->_menu .= '<a href="'.Tools::HtmlEntitiesUTF8($category_link).'">'.($category->id==3 ? '<i class="fa fa-home"></i>':'').$category->name.'</a>'; to here: $this->_menu .= '<li '.$selected.'>'; $this->_menu .= '<a href="'.Tools::HtmlEntitiesUTF8($category_link).'">'.($category->id==3 ? '':'<i class="fa fa-home"></i>').$category->name.'</a>'; i get the icon in all of the categories, that's a good thing right?, at least the icon it's working , the only thing its failing its the right place, as you can see here: Link to comment Share on other sites More sharing options...
ALMAJ Posted March 24, 2014 Share Posted March 24, 2014 (edited) i didnt exactly understand what are you trying to achieve. but if you want to set background for top menus you can simply use some thing like: .sf-menu>li+li+li {background:url('../img/menu1.jpg') no-repeat top} or .sf-menu li:nth-child(3) {background:url('../img/menu2.jpg') no-repeat top} ihave used here thanks for the reply, but what I'm actually trying to achieve here, is to get font icons (vector icons like font awesome) working on the top menu, not images (raster images like jpg, png etc) its more better for performance and is scalable, great for mobile devices. Regards Edited March 24, 2014 by ALMAJ (see edit history) Link to comment Share on other sites More sharing options...
Evelyna Posted March 24, 2014 Share Posted March 24, 2014 Hi! First, thanks for your amazing contribution. Just I have to do something very similiar to this, but editable from administrator. I mean the image must assign each time you create a category, through a field and / or attribute in the category, not css. Some guidance? Link to comment Share on other sites More sharing options...
sooroos Posted March 24, 2014 Share Posted March 24, 2014 Hi! First, thanks for your amazing contribution. Just I have to do something very similiar to this, but editable from administrator. I mean the image must assign each time you create a category, through a field and / or attribute in the category, not css. Some guidance? sounds like you need a module for that. prepare to pay a developer if you dont how to code it 2 Link to comment Share on other sites More sharing options...
Evelyna Posted March 24, 2014 Share Posted March 24, 2014 sounds like you need a module for that. prepare to pay a developer if you dont how to code it I'm willing to pay for the module, but first I wanted to know if it was possible by modifying the code. Link to comment Share on other sites More sharing options...
ALMAJ Posted March 24, 2014 Share Posted March 24, 2014 (edited) Hi! First, thanks for your amazing contribution. Just I have to do something very similiar to this, but editable from administrator. I mean the image must assign each time you create a category, through a field and / or attribute in the category, not css. Some guidance? The one you must tanks is to Vekia he has contributed a lot for prestashop community I'm willing to pay for the module, but first I wanted to know if it was possible by modifying the code. With money, everything is possible Edited March 24, 2014 by ALMAJ (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted March 24, 2014 Share Posted March 24, 2014 to be honest, i wrote everything without testing now i tested it, and this is what i achieved: change: $html .= '<a href="'.$link.'" title="'.$category['name'].'">'.$category['name'].'</a>'; to: $html .= '<a href="'.$link.'" title="'.$category['name'].'">'.($category['id_category']==3 ? '<i class="fa fa-home"></i>':'').$category['name'].'</a>'; Link to comment Share on other sites More sharing options...
ALMAJ Posted March 24, 2014 Share Posted March 24, 2014 to be honest, i wrote everything without testing now i tested it, and this is what i achieved: change: $html .= '<a href="'.$link.'" title="'.$category['name'].'">'.$category['name'].'</a>'; to: $html .= '<a href="'.$link.'" title="'.$category['name'].'">'.($category['id_category']==3 ? '<i class="fa fa-home"></i>':'').$category['name'].'</a>'; Hello vekia, I've try to find the this code you described in the blocktopmenu.php: $html .= '<a href="'.$link.'" title="'.$category['name'].'">'.$category['name'].'</a>'; my prestashop version is 1.5.6.2 my blocktopmenu code is this: require (dirname(__FILE__).'/menutoplinks.class.php'); class Blocktopmenu extends Module { private $_menu = ''; private $_html = ''; private $user_groups; /* * Pattern for matching config values */ private $pattern = '/^([A-Z_]*)[0-9]+/'; /* * Name of the controller * Used to set item selected or not in top menu */ private $page_name = ''; /* * Spaces per depth in BO */ private $spacer_size = '5'; public function __construct() { $this->name = 'blocktopmenu'; $this->tab = 'front_office_features'; $this->version = 1.7; $this->author = 'PrestaShop'; parent::__construct(); $this->displayName = $this->l('Top horizontal menu'); $this->description = $this->l('Add a new horizontal menu to the top of your e-commerce website.'); } public function install() { if (!parent::install() || !$this->registerHook('displayTop') || !Configuration::updateGlobalValue('MOD_BLOCKTOPMENU_ITEMS', 'CAT1,CMS1,CMS2,PRD1') || !Configuration::updateGlobalValue('MOD_BLOCKTOPMENU_SEARCH', '1') || !$this->registerHook('actionObjectCategoryUpdateAfter') || !$this->registerHook('actionObjectCategoryDeleteAfter') || !$this->registerHook('actionObjectCategoryAddAfter') || !$this->registerHook('actionObjectCmsUpdateAfter') || !$this->registerHook('actionObjectCmsDeleteAfter') || !$this->registerHook('actionObjectCmsAddAfter') || !$this->registerHook('actionObjectSupplierUpdateAfter') || !$this->registerHook('actionObjectSupplierDeleteAfter') || !$this->registerHook('actionObjectSupplierAddAfter') || !$this->registerHook('actionObjectManufacturerUpdateAfter') || !$this->registerHook('actionObjectManufacturerDeleteAfter') || !$this->registerHook('actionObjectManufacturerAddAfter') || !$this->registerHook('actionObjectProductUpdateAfter') || !$this->registerHook('actionObjectProductDeleteAfter') || !$this->registerHook('actionObjectProductAddAfter') || !$this->registerHook('categoryUpdate') || !$this->registerHook('actionShopDataDuplication') || !$this->installDB()) return false; return true; } public function installDb() { return (Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'linksmenutop` ( `id_linksmenutop` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, `id_shop` INT(11) UNSIGNED NOT NULL, `new_window` TINYINT( 1 ) NOT NULL, INDEX (`id_shop`) ) ENGINE = '._MYSQL_ENGINE_.' CHARACTER SET utf8 COLLATE utf8_general_ci;') && Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'linksmenutop_lang` ( `id_linksmenutop` INT(11) UNSIGNED NOT NULL, `id_lang` INT(11) UNSIGNED NOT NULL, `id_shop` INT(11) UNSIGNED NOT NULL, `label` VARCHAR( 128 ) NOT NULL , `link` VARCHAR( 128 ) NOT NULL , INDEX ( `id_linksmenutop` , `id_lang`, `id_shop`) ) ENGINE = '._MYSQL_ENGINE_.' CHARACTER SET utf8 COLLATE utf8_general_ci;')); } public function uninstall() { if (!parent::uninstall() || !Configuration::deleteByName('MOD_BLOCKTOPMENU_ITEMS') || !Configuration::deleteByName('MOD_BLOCKTOPMENU_SEARCH') || !$this->uninstallDB()) return false; return true; } private function uninstallDb() { Db::getInstance()->execute('DROP TABLE `'._DB_PREFIX_.'linksmenutop`'); Db::getInstance()->execute('DROP TABLE `'._DB_PREFIX_.'linksmenutop_lang`'); return true; } public function getContent() { $id_lang = (int)Context::getContext()->language->id; $languages = $this->context->controller->getLanguages(); $default_language = (int)Configuration::get('PS_LANG_DEFAULT'); $labels = Tools::getValue('label') ? array_filter(Tools::getValue('label'), 'strlen') : array(); $links_label = Tools::getValue('link') ? array_filter(Tools::getValue('link'), 'strlen') : array(); $spacer = str_repeat(' ', $this->spacer_size); $divLangName = 'link_label'; $update_cache = false; if (Tools::isSubmit('submitBlocktopmenu')) { if (Configuration::updateValue('MOD_BLOCKTOPMENU_ITEMS', Tools::getValue('items'))) $this->_html .= $this->displayConfirmation($this->l('The settings have been updated.')); else $this->_html .= $this->displayError($this->l('Unable to update settings.')); Configuration::updateValue('MOD_BLOCKTOPMENU_SEARCH', (bool)Tools::getValue('search')); $update_cache = true; } else if (Tools::isSubmit('submitBlocktopmenuLinks')) { if ((!count($links_label)) && (!count($labels))) ; else if (!count($links_label)) $this->_html .= $this->displayError($this->l('Please complete the "link" field.')); else if (!count($labels)) $this->_html .= $this->displayError($this->l('Please add a label')); else if (!isset($labels[$default_language])) $this->_html .= $this->displayError($this->l('Please add a label for your default language.')); else { MenuTopLinks::add(Tools::getValue('link'), Tools::getValue('label'), Tools::getValue('new_window', 0), (int)Shop::getContextShopID()); $this->_html .= $this->displayConfirmation($this->l('The link has been added.')); } $update_cache = true; } else if (Tools::isSubmit('submitBlocktopmenuRemove')) { $id_linksmenutop = Tools::getValue('id_linksmenutop', 0); MenuTopLinks::remove($id_linksmenutop, (int)Shop::getContextShopID()); Configuration::updateValue('MOD_BLOCKTOPMENU_ITEMS', str_replace(array('LNK'.$id_linksmenutop.',', 'LNK'.$id_linksmenutop), '', Configuration::get('MOD_BLOCKTOPMENU_ITEMS'))); $this->_html .= $this->displayConfirmation($this->l('The link has been removed')); $update_cache = true; } else if (Tools::isSubmit('submitBlocktopmenuEdit')) { $id_linksmenutop = (int)Tools::getValue('id_linksmenutop', 0); $id_shop = (int)Shop::getContextShopID(); if (!Tools::isSubmit('link')) { $tmp = MenuTopLinks::getLinkLang($id_linksmenutop, $id_shop); $links_label_edit = $tmp['link']; $labels_edit = $tmp['label']; $new_window_edit = $tmp['new_window']; } else { MenuTopLinks::update(Tools::getValue('link'), Tools::getValue('label'), Tools::getValue('new_window', 0), (int)$id_shop, (int)$id_linksmenutop, (int)$id_linksmenutop); $this->_html .= $this->displayConfirmation($this->l('The link has been edited')); } $update_cache = true; } if ($update_cache) $this->clearMenuCache(); $this->_html .= ' <fieldset> <div class="multishop_info"> '.$this->l('The modifications will be applied to').' '.(Shop::getContext() == Shop::CONTEXT_SHOP ? $this->l('shop').' '.$this->context->shop->name : $this->l('all shops')).'. </div> <legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Settings').'</legend> <form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post" id="form"> <div style="display: none"> <label>'.$this->l('Items').'</label> <div class="margin-form"> <input type="text" name="items" id="itemsInput" value="'.Tools::safeOutput(Configuration::get('MOD_BLOCKTOPMENU_ITEMS')).'" size="70" /> </div> </div> <div class="clear"> </div> <table style="margin-left: 130px;"> <tbody> <tr> <td style="padding-left: 20px;"> <select multiple="multiple" id="availableItems" style="width: 300px; height: 160px;">'; // BEGIN CMS $this->_html .= '<optgroup label="'.$this->l('CMS').'">'; $this->getCMSOptions(0, 1, $id_lang); $this->_html .= '</optgroup>'; // BEGIN SUPPLIER $this->_html .= '<optgroup label="'.$this->l('Supplier').'">'; // Option to show all Suppliers $this->_html .= '<option value="ALLSUP0">'.$this->l('All suppliers').'</option>'; $suppliers = Supplier::getSuppliers(false, $id_lang); foreach ($suppliers as $supplier) $this->_html .= '<option value="SUP'.$supplier['id_supplier'].'">'.$spacer.$supplier['name'].'</option>'; $this->_html .= '</optgroup>'; // BEGIN Manufacturer $this->_html .= '<optgroup label="'.$this->l('Manufacturer').'">'; // Option to show all Manufacturers $this->_html .= '<option value="ALLMAN0">'.$this->l('All manufacturers').'</option>'; $manufacturers = Manufacturer::getManufacturers(false, $id_lang); foreach ($manufacturers as $manufacturer) $this->_html .= '<option value="MAN'.$manufacturer['id_manufacturer'].'">'.$spacer.$manufacturer['name'].'</option>'; $this->_html .= '</optgroup>'; // BEGIN Categories $this->_html .= '<optgroup label="'.$this->l('Categories').'">'; $this->getCategoryOption(1, (int)$id_lang, (int)Shop::getContextShopID()); $this->_html .= '</optgroup>'; // BEGIN Shops if (Shop::isFeatureActive()) { $this->_html .= '<optgroup label="'.$this->l('Shops').'">'; $shops = Shop::getShopsCollection(); foreach ($shops as $shop) { if (!$shop->setUrl() && !$shop->getBaseURL()) continue; $this->_html .= '<option value="SHOP'.(int)$shop->id.'">'.$spacer.$shop->name.'</option>'; } $this->_html .= '</optgroup>'; } // BEGIN Products $this->_html .= '<optgroup label="'.$this->l('Products').'">'; $this->_html .= '<option value="PRODUCT" style="font-style:italic">'.$spacer.$this->l('Choose product ID').'</option>'; $this->_html .= '</optgroup>'; // BEGIN Menu Top Links $this->_html .= '<optgroup label="'.$this->l('Menu Top Links').'">'; $links = MenuTopLinks::gets($id_lang, null, (int)Shop::getContextShopID()); foreach ($links as $link) { if ($link['label'] == '') { $link = MenuTopLinks::get($link['id_linksmenutop'], $default_language, (int)Shop::getContextShopID()); $this->_html .= '<option value="LNK'.(int)$link[0]['id_linksmenutop'].'">'.$spacer.$link[0]['label'].'</option>'; } else $this->_html .= '<option value="LNK'.(int)$link['id_linksmenutop'].'">'.$spacer.$link['label'].'</option>'; } $this->_html .= '</optgroup>'; $this->_html .= '</select><br /> <br /> <a href="#" id="addItem" style="border: 1px solid rgb(170, 170, 170); margin: 2px; padding: 2px; text-align: center; display: block; text-decoration: none; background-color: rgb(250, 250, 250); color: rgb(18, 52, 86);">'.$this->l('Add').' >></a> </td> <td> <select multiple="multiple" id="items" style="width: 300px; height: 160px;">'; $this->makeMenuOption(); $this->_html .= '</select><br/> <br/> <a href="#" id="removeItem" style="border: 1px solid rgb(170, 170, 170); margin: 2px; padding: 2px; text-align: center; display: block; text-decoration: none; background-color: rgb(250, 250, 250); color: rgb(18, 52, 86);"><< '.$this->l('Remove').'</a> </td> <td style="vertical-align:top;padding:5px 15px;"> <h4 style="margin-top:5px;">'.$this->l('Change position').'</h4> <a href="#" id="menuOrderUp" class="button" style="font-size:20px;display:block;">↑</a><br/> <a href="#" id="menuOrderDown" class="button" style="font-size:20px;display:block;">↓</a><br/> </td> </tr> </tbody> </table> <div class="clear"> </div> <script type="text/javascript"> function add() { $("#availableItems option:selected").each(function(i){ var val = $(this).val(); var text = $(this).text(); text = text.replace(/(^\s*)|(\s*$)/gi,""); if (val == "PRODUCT") { val = prompt("'.$this->l('Set ID product').'"); if (val == null || val == "" || isNaN(val)) return; text = "'.$this->l('Product ID').' "+val; val = "PRD"+val; } $("#items").append("<option value=\""+val+"\">"+text+"</option>"); }); serialize(); return false; } function remove() { $("#items option:selected").each(function(i){ $(this).remove(); }); serialize(); return false; } function serialize() { var options = ""; $("#items option").each(function(i){ options += $(this).val() + ","; }); $("#itemsInput").val(options.substr(0, options.length - 1)); } function move(up) { var tomove = $("#items option:selected"); if (tomove.length >1) { alert(\''.Tools::htmlentitiesUTF8($this->l('Please select just one item')).'\'); return false; } if (up) tomove.prev().insertAfter(tomove); else tomove.next().insertBefore(tomove); serialize(); return false; } $(document).ready(function(){ $("#addItem").click(add); $("#availableItems").dblclick(add); $("#removeItem").click(remove); $("#items").dblclick(remove); $("#menuOrderUp").click(function(e){ e.preventDefault(); move(true); }); $("#menuOrderDown").click(function(e){ e.preventDefault(); move(); }); }); </script> <label for="s">'.$this->l('Search Bar').'</label> <div class="margin-form"> <input type="checkbox" name="search" id="s" value="1"'.((Configuration::get('MOD_BLOCKTOPMENU_SEARCH')) ? ' checked=""': '').'/> </div> <p class="center"> <input type="submit" name="submitBlocktopmenu" value="'.$this->l('Save ').'" class="button" /> </p> </form> </fieldset><br />'; $this->_html .= ' <fieldset> <legend><img src="../img/admin/add.gif" alt="" title="" />'.$this->l('Add Menu Top Link').'</legend> <form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post" id="form"> '; foreach ($languages as $language) { $this->_html .= ' <div id="link_label_'.(int)$language['id_lang'].'" style="display: '.($language['id_lang'] == $id_lang ? 'block' : 'none').';"> <label>'.$this->l('Label').'</label> <div class="margin-form"> <input type="text" name="label['.(int)$language['id_lang'].']" id="label_'.(int)$language['id_lang'].'" size="70" value="'.(isset($labels_edit[$language['id_lang']]) ? $labels_edit[$language['id_lang']] : '').'" /> </div> '; $this->_html .= ' <label>'.$this->l('Link').'</label> <div class="margin-form"> <input type="text" name="link['.(int)$language['id_lang'].']" id="link_'.(int)$language['id_lang'].'" value="'.(isset($links_label_edit[$language['id_lang']]) ? $links_label_edit[$language['id_lang']] : '').'" size="70" /> </div> </div>'; } $this->_html .= '<label>'.$this->l('Language').'</label> <div class="margin-form">'.$this->displayFlags($languages, (int)$id_lang, $divLangName, 'link_label', true).'</div><p style="clear: both;"> </p>'; $this->_html .= '<label style="clear: both;">'.$this->l('New Window').'</label> <div class="margin-form"> <input style="clear: both;" type="checkbox" name="new_window" value="1" '.(isset($new_window_edit) && $new_window_edit ? 'checked' : '').'/> </div> <div class="margin-form">'; if (Tools::isSubmit('id_linksmenutop')) $this->_html .= '<input type="hidden" name="id_linksmenutop" value="'.(int)Tools::getValue('id_linksmenutop').'" />'; if (Tools::isSubmit('submitBlocktopmenuEdit')) $this->_html .= '<input type="submit" name="submitBlocktopmenuEdit" value="'.$this->l('Edit').'" class="button" />'; $this->_html .= ' <input type="submit" name="submitBlocktopmenuLinks" value="'.$this->l('Add ').'" class="button" /> </div> </form> </fieldset><br />'; $links = MenuTopLinks::gets((int)$id_lang, null, (int)Shop::getContextShopID()); if (!count($links)) return $this->_html; $this->_html .= ' <fieldset> <legend><img src="../img/admin/details.gif" alt="" title="" />'.$this->l('List Menu Top Link').'</legend> <table style="width:100%;"> <thead> <tr style="text-align: left;"> <th>'.$this->l('Id Link').'</th> <th>'.$this->l('Label').'</th> <th>'.$this->l('Link').'</th> <th>'.$this->l('New Window').'</th> <th>'.$this->l('Action').'</th> </tr> </thead> <tbody>'; foreach ($links as $link) { $this->_html .= ' <tr> <td>'.(int)$link['id_linksmenutop'].'</td> <td>'.Tools::safeOutput($link['label']).'</td> <td><a href="'.Tools::safeOutput($link['link']).'"'.(($link['new_window']) ? ' target="_blank"' : '').'>'.Tools::safeOutput($link['link']).'</a></td> <td>'.(($link['new_window']) ? $this->l('Yes') : $this->l('No')).'</td> <td> <form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post"> <input type="hidden" name="id_linksmenutop" value="'.(int)$link['id_linksmenutop'].'" /> <input type="submit" name="submitBlocktopmenuEdit" value="'.$this->l('Edit').'" class="button" /> <input type="submit" name="submitBlocktopmenuRemove" value="'.$this->l('Remove').'" class="button" /> </form> </td> </tr>'; } $this->_html .= '</tbody> </table> </fieldset>'; return $this->_html; } private function getMenuItems() { return explode(',', Configuration::get('MOD_BLOCKTOPMENU_ITEMS')); } private function makeMenuOption() { $menu_item = $this->getMenuItems(); $id_lang = (int)$this->context->language->id; $id_shop = (int)Shop::getContextShopID(); foreach ($menu_item as $item) { if (!$item) continue; preg_match($this->pattern, $item, $values); $id = (int)substr($item, strlen($values[1]), strlen($item)); switch (substr($item, 0, strlen($values[1]))) { case 'CAT': $category = new Category((int)$id, (int)$id_lang); if (Validate::isLoadedObject($category)) $this->_html .= '<option value="CAT'.$id.'">'.$category->name.'</option>'.PHP_EOL; break; case 'PRD': $product = new Product((int)$id, true, (int)$id_lang); if (Validate::isLoadedObject($product)) $this->_html .= '<option value="PRD'.$id.'">'.$product->name.'</option>'.PHP_EOL; break; case 'CMS': $cms = new CMS((int)$id, (int)$id_lang); if (Validate::isLoadedObject($cms)) $this->_html .= '<option value="CMS'.$id.'">'.$cms->meta_title.'</option>'.PHP_EOL; break; case 'CMS_CAT': $category = new CMSCategory((int)$id, (int)$id_lang); if (Validate::isLoadedObject($category)) $this->_html .= '<option value="CMS_CAT'.$id.'">'.$category->name.'</option>'.PHP_EOL; break; // Case to handle the option to show all Manufacturers case 'ALLMAN': $this->_html .= '<option value="ALLMAN0">'.$this->l('All manufacturers').'</option>'.PHP_EOL; break; case 'MAN': $manufacturer = new Manufacturer((int)$id, (int)$id_lang); if (Validate::isLoadedObject($manufacturer)) $this->_html .= '<option value="MAN'.$id.'">'.$manufacturer->name.'</option>'.PHP_EOL; break; // Case to handle the option to show all Suppliers case 'ALLSUP': $this->_html .= '<option value="ALLSUP0">'.$this->l('All suppliers').'</option>'.PHP_EOL; break; case 'SUP': $supplier = new Supplier((int)$id, (int)$id_lang); if (Validate::isLoadedObject($supplier)) $this->_html .= '<option value="SUP'.$id.'">'.$supplier->name.'</option>'.PHP_EOL; break; case 'LNK': $link = MenuTopLinks::get((int)$id, (int)$id_lang, (int)$id_shop); if (count($link)) { if (!isset($link[0]['label']) || ($link[0]['label'] == '')) { $default_language = Configuration::get('PS_LANG_DEFAULT'); $link = MenuTopLinks::get($link[0]['id_linksmenutop'], (int)$default_language, (int)Shop::getContextShopID()); } $this->_html .= '<option value="LNK'.$link[0]['id_linksmenutop'].'">'.$link[0]['label'].'</option>'; } break; case 'SHOP': $shop = new Shop((int)$id); if (Validate::isLoadedObject($shop)) $this->_html .= '<option value="SHOP'.(int)$id.'">'.$shop->name.'</option>'.PHP_EOL; break; } } } private function makeMenu() { $menu_items = $this->getMenuItems(); $id_lang = (int)$this->context->language->id; $id_shop = (int)Shop::getContextShopID(); foreach ($menu_items as $item) { if (!$item) continue; preg_match($this->pattern, $item, $value); $id = (int)substr($item, strlen($value[1]), strlen($item)); switch (substr($item, 0, strlen($value[1]))) { case 'CAT': $this->getCategory($id, $id_lang, $id_shop); break; case 'PRD': $selected = ($this->page_name == 'product' && (Tools::getValue('id_product') == $id)) ? ' class="sfHover"' : ''; $product = new Product((int)$id, true, (int)$id_lang); if (!is_null($product->id)) $this->_menu .= '<li'.$selected.'><a href="'.Tools::HtmlEntitiesUTF8($product->getLink()).'">'.$product->name.'</a></li>'.PHP_EOL; break; case 'CMS': $selected = ($this->page_name == 'cms' && (Tools::getValue('id_cms') == $id)) ? ' class="sfHover"' : ''; $cms = CMS::getLinks((int)$id_lang, array($id)); if (count($cms)) $this->_menu .= '<li'.$selected.'><a href="'.Tools::HtmlEntitiesUTF8($cms[0]['link']).'">'.$cms[0]['meta_title'].'</a></li>'.PHP_EOL; break; case 'CMS_CAT': $category = new CMSCategory((int)$id, (int)$id_lang); if (count($category)) { $this->_menu .= '<li><a href="'.Tools::HtmlEntitiesUTF8($category->getLink()).'">'.$category->name.'</a>'; $this->getCMSMenuItems($category->id); $this->_menu .= '</li>'.PHP_EOL; } break; // Case to handle the option to show all Manufacturers case 'ALLMAN': $link = new Link; $this->_menu .= '<li><a href="'.$link->getPageLink('manufacturer').'">'.$this->l('All manufacturers').'</a><ul>'.PHP_EOL; $manufacturers = Manufacturer::getManufacturers(); foreach ($manufacturers as $key => $manufacturer) $this->_menu .= '<li><a href="'.$link->getManufacturerLink((int)$manufacturer['id_manufacturer'], $manufacturer['link_rewrite']).'">'.$manufacturer['name'].'</a></li>'.PHP_EOL; $this->_menu .= '</ul>'; break; case 'MAN': $selected = ($this->page_name == 'manufacturer' && (Tools::getValue('id_manufacturer') == $id)) ? ' class="sfHover"' : ''; $manufacturer = new Manufacturer((int)$id, (int)$id_lang); if (!is_null($manufacturer->id)) { if (intval(Configuration::get('PS_REWRITING_SETTINGS'))) $manufacturer->link_rewrite = Tools::link_rewrite($manufacturer->name); else $manufacturer->link_rewrite = 0; $link = new Link; $this->_menu .= '<li'.$selected.'><a href="'.Tools::HtmlEntitiesUTF8($link->getManufacturerLink((int)$id, $manufacturer->link_rewrite)).'">'.$manufacturer->name.'</a></li>'.PHP_EOL; } break; // Case to handle the option to show all Suppliers case 'ALLSUP': $link = new Link; $this->_menu .= '<li><a href="'.$link->getPageLink('supplier').'">'.$this->l('All suppliers').'</a><ul>'.PHP_EOL; $suppliers = Supplier::getSuppliers(); foreach ($suppliers as $key => $supplier) $this->_menu .= '<li><a href="'.$link->getSupplierLink((int)$supplier['id_supplier'], $supplier['link_rewrite']).'">'.$supplier['name'].'</a></li>'.PHP_EOL; $this->_menu .= '</ul>'; break; case 'SUP': $selected = ($this->page_name == 'supplier' && (Tools::getValue('id_supplier') == $id)) ? ' class="sfHover"' : ''; $supplier = new Supplier((int)$id, (int)$id_lang); if (!is_null($supplier->id)) { $link = new Link; $this->_menu .= '<li'.$selected.'><a href="'.Tools::HtmlEntitiesUTF8($link->getSupplierLink((int)$id, $supplier->link_rewrite)).'">'.$supplier->name.'</a></li>'.PHP_EOL; } break; case 'SHOP': $selected = ($this->page_name == 'index' && ($this->context->shop->id == $id)) ? ' class="sfHover"' : ''; $shop = new Shop((int)$id); if (Validate::isLoadedObject($shop)) { $link = new Link; $this->_menu .= '<li'.$selected.'><a href="'.Tools::HtmlEntitiesUTF8($shop->getBaseURL()).'">'.$shop->name.'</a></li>'.PHP_EOL; } break; case 'LNK': $link = MenuTopLinks::get((int)$id, (int)$id_lang, (int)$id_shop); if (count($link)) { if (!isset($link[0]['label']) || ($link[0]['label'] == '')) { $default_language = Configuration::get('PS_LANG_DEFAULT'); $link = MenuTopLinks::get($link[0]['id_linksmenutop'], $default_language, (int)Shop::getContextShopID()); } $this->_menu .= '<li><a href="'.Tools::HtmlEntitiesUTF8($link[0]['link']).'"'.(($link[0]['new_window']) ? ' target="_blank"': '').'>'.$link[0]['label'].'</a></li>'.PHP_EOL; } break; } } } private function getCategoryOption($id_category = 1, $id_lang = false, $id_shop = false, $recursive = true) { $id_lang = $id_lang ? (int)$id_lang : (int)Context::getContext()->language->id; $category = new Category((int)$id_category, (int)$id_lang, (int)$id_shop); if (is_null($category->id)) return; if ($recursive) { $children = Category::getChildren((int)$id_category, (int)$id_lang, true, (int)$id_shop); $spacer = str_repeat(' ', $this->spacer_size * (int)$category->level_depth); } $shop = (object) Shop::getShop((int)$category->getShopID()); $this->_html .= '<option value="CAT'.(int)$category->id.'">'.(isset($spacer) ? $spacer : '').$category->name.' ('.$shop->name.')</option>'; if (isset($children) && count($children)) foreach ($children as $child) $this->getCategoryOption((int)$child['id_category'], (int)$id_lang, (int)$child['id_shop']); } private function getCategory($id_category, $id_lang = false, $id_shop = false) { $id_lang = $id_lang ? (int)$id_lang : (int)Context::getContext()->language->id; $category = new Category((int)$id_category, (int)$id_lang); if ($category->level_depth > 1) $category_link = $category->getLink(); else $category_link = $this->context->link->getPageLink('index'); if (is_null($category->id)) return; $children = Category::getChildren((int)$id_category, (int)$id_lang, true, (int)$id_shop); $selected = ($this->page_name == 'category' && ((int)Tools::getValue('id_category') == $id_category)) ? ' class="sfHoverForce"' : ''; $is_intersected = array_intersect($category->getGroups(), $this->user_groups); // filter the categories that the user is allowed to see and browse if (!empty($is_intersected)) { $this->_menu .= '<li '.$selected.'>'; $this->_menu .= '<a href="'.Tools::HtmlEntitiesUTF8($category_link).'">'.$category->name.'</a>'; if (count($children)) { $this->_menu .= '<ul>'; foreach ($children as $child) $this->getCategory((int)$child['id_category'], (int)$id_lang, (int)$child['id_shop']); $this->_menu .= '</ul>'; } $this->_menu .= '</li>'; } } private function getCMSMenuItems($parent, $depth = 1, $id_lang = false) { $id_lang = $id_lang ? (int)$id_lang : (int)Context::getContext()->language->id; if ($depth > 3) return; $categories = $this->getCMSCategories(false, (int)$parent, (int)$id_lang); $pages = $this->getCMSPages((int)$parent); if (count($categories) || count($pages)) { $this->_menu .= '<ul>'; foreach ($categories as $category) { $this->_menu .= '<li>'; $this->_menu .= '<a href="#">'.$category['name'].'</a>'; $this->getCMSMenuItems($category['id_cms_category'], (int)$depth + 1); $this->_menu .= '</li>'; } foreach ($pages as $page) { $cms = new CMS($page['id_cms'], (int)$id_lang); $links = $cms->getLinks((int)$id_lang, array((int)$cms->id)); $selected = ($this->page_name == 'cms' && ((int)Tools::getValue('id_cms') == $page['id_cms'])) ? ' class="sfHoverForce"' : ''; $this->_menu .= '<li '.$selected.'>'; $this->_menu .= '<a href="'.$links[0]['link'].'">'.$cms->meta_title.'</a>'; $this->_menu .= '</li>'; } $this->_menu .= '</ul>'; } } private function getCMSOptions($parent = 0, $depth = 1, $id_lang = false) { $id_lang = $id_lang ? (int)$id_lang : (int)Context::getContext()->language->id; $categories = $this->getCMSCategories(false, (int)$parent, (int)$id_lang); $pages = $this->getCMSPages((int)$parent, false, (int)$id_lang); $spacer = str_repeat(' ', $this->spacer_size * (int)$depth); foreach ($categories as $category) { $this->_html .= '<option value="CMS_CAT'.$category['id_cms_category'].'" style="font-weight: bold;">'.$spacer.$category['name'].'</option>'; $this->getCMSOptions($category['id_cms_category'], (int)$depth + 1, (int)$id_lang); } foreach ($pages as $page) $this->_html .= '<option value="CMS'.$page['id_cms'].'">'.$spacer.$page['meta_title'].'</option>'; } protected function getCacheId($name = null) { parent::getCacheId($name); $page_name = in_array($this->page_name, array('category', 'supplier', 'manufacturer', 'cms', 'product')) ? $this->page_name : 'index'; return 'blocktopmenu|'.(int)Tools::usingSecureMode().'|'.$page_name.'|'.(int)$this->context->shop->id.'|'.implode(', ',$this->user_groups).'|'.(int)$this->context->language->id.'|'.(int)Tools::getValue('id_category').'|'.(int)Tools::getValue('id_manufacturer').'|'.(int)Tools::getValue('id_supplier').'|'.(int)Tools::getValue('id_cms').'|'.(int)Tools::getValue('id_product'); } public function hookDisplayTop($param) { $this->user_groups = ($this->context->customer->isLogged() ? $this->context->customer->getGroups() : array(Configuration::get('PS_UNIDENTIFIED_GROUP'))); $this->page_name = Dispatcher::getInstance()->getController(); if (!$this->isCached('blocktopmenu.tpl', $this->getCacheId())) { $this->makeMenu(); $this->smarty->assign('MENU_SEARCH', Configuration::get('MOD_BLOCKTOPMENU_SEARCH')); $this->smarty->assign('MENU', $this->_menu); $this->smarty->assign('this_path', $this->_path); } $this->context->controller->addJS($this->_path.'js/hoverIntent.js'); $this->context->controller->addJS($this->_path.'js/superfish-modified.js'); $this->context->controller->addCSS($this->_path.'css/superfish-modified.css'); $html = $this->display(__FILE__, 'blocktopmenu.tpl', $this->getCacheId()); return $html; } private function getCMSCategories($recursive = false, $parent = 1, $id_lang = false) { $id_lang = $id_lang ? (int)$id_lang : (int)Context::getContext()->language->id; if ($recursive === false) { $sql = 'SELECT bcp.`id_cms_category`, bcp.`id_parent`, bcp.`level_depth`, bcp.`active`, bcp.`position`, cl.`name`, cl.`link_rewrite` FROM `'._DB_PREFIX_.'cms_category` bcp INNER JOIN `'._DB_PREFIX_.'cms_category_lang` cl ON (bcp.`id_cms_category` = cl.`id_cms_category`) WHERE cl.`id_lang` = '.(int)$id_lang.' AND bcp.`id_parent` = '.(int)$parent; return Db::getInstance()->executeS($sql); } else { $sql = 'SELECT bcp.`id_cms_category`, bcp.`id_parent`, bcp.`level_depth`, bcp.`active`, bcp.`position`, cl.`name`, cl.`link_rewrite` FROM `'._DB_PREFIX_.'cms_category` bcp INNER JOIN `'._DB_PREFIX_.'cms_category_lang` cl ON (bcp.`id_cms_category` = cl.`id_cms_category`) WHERE cl.`id_lang` = '.(int)$id_lang.' AND bcp.`id_parent` = '.(int)$parent; $results = Db::getInstance()->executeS($sql); foreach ($results as $result) { $sub_categories = $this->getCMSCategories(true, $result['id_cms_category'], (int)$id_lang); if ($sub_categories && count($sub_categories) > 0) $result['sub_categories'] = $sub_categories; $categories[] = $result; } return isset($categories) ? $categories : false; } } private function getCMSPages($id_cms_category, $id_shop = false, $id_lang = false) { $id_shop = ($id_shop !== false) ? (int)$id_shop : (int)Context::getContext()->shop->id; $id_lang = $id_lang ? (int)$id_lang : (int)Context::getContext()->language->id; $sql = 'SELECT c.`id_cms`, cl.`meta_title`, cl.`link_rewrite` FROM `'._DB_PREFIX_.'cms` c INNER JOIN `'._DB_PREFIX_.'cms_shop` cs ON (c.`id_cms` = cs.`id_cms`) INNER JOIN `'._DB_PREFIX_.'cms_lang` cl ON (c.`id_cms` = cl.`id_cms`) WHERE c.`id_cms_category` = '.(int)$id_cms_category.' AND cs.`id_shop` = '.(int)$id_shop.' AND cl.`id_lang` = '.(int)$id_lang.' AND c.`active` = 1 ORDER BY `position`'; return Db::getInstance()->executeS($sql); } public function hookActionObjectCategoryAddAfter($params) { $this->clearMenuCache(); } public function hookActionObjectCategoryUpdateAfter($params) { $this->clearMenuCache(); } public function hookActionObjectCategoryDeleteAfter($params) { $this->clearMenuCache(); } public function hookActionObjectCmsUpdateAfter($params) { $this->clearMenuCache(); } public function hookActionObjectCmsDeleteAfter($params) { $this->clearMenuCache(); } public function hookActionObjectCmsAddAfter($params) { $this->clearMenuCache(); } public function hookActionObjectSupplierUpdateAfter($params) { $this->clearMenuCache(); } public function hookActionObjectSupplierDeleteAfter($params) { $this->clearMenuCache(); } public function hookActionObjectSupplierAddAfter($params) { $this->clearMenuCache(); } public function hookActionObjectManufacturerUpdateAfter($params) { $this->clearMenuCache(); } public function hookActionObjectManufacturerDeleteAfter($params) { $this->clearMenuCache(); } public function hookActionObjectManufacturerAddAfter($params) { $this->clearMenuCache(); } public function hookActionObjectProductUpdateAfter($params) { $this->clearMenuCache(); } public function hookActionObjectProductDeleteAfter($params) { $this->clearMenuCache(); } public function hookActionObjectProductAddAfter($params) { $this->clearMenuCache(); } public function hookCategoryUpdate($params) { $this->clearMenuCache(); } private function clearMenuCache() { $this->_clearCache('blocktopmenu.tpl'); } public function hookActionShopDataDuplication($params) { $linksmenutop = Db::getInstance()->executeS(' SELECT * FROM '._DB_PREFIX_.'linksmenutop WHERE id_shop = '.(int)$params['old_id_shop'] ); foreach($linksmenutop as $id => $link) { Db::getInstance()->execute(' INSERT IGNORE INTO '._DB_PREFIX_.'linksmenutop (id_linksmenutop, id_shop, new_window) VALUES (null, '.(int)$params['new_id_shop'].', '.(int)$link['new_window'].')'); $linksmenutop[$id]['new_id_linksmenutop'] = Db::getInstance()->Insert_ID(); } foreach($linksmenutop as $id => $link) { $lang = Db::getInstance()->executeS(' SELECT id_lang, '.(int)$params['new_id_shop'].', label, link FROM '._DB_PREFIX_.'linksmenutop_lang WHERE id_linksmenutop = '.(int)$link['id_linksmenutop'].' AND id_shop = '.(int)$params['old_id_shop']); foreach($lang as $l) Db::getInstance()->execute(' INSERT IGNORE INTO '._DB_PREFIX_.'linksmenutop_lang (id_linksmenutop, id_lang, id_shop, label, link) VALUES ('.(int)$link['new_id_linksmenutop'].', '.(int)$l['id_lang'].', '.(int)$params['new_id_shop'].', '.(int)$l['label'].', '.(int)$l['link'].' )'); } } } tanks Link to comment Share on other sites More sharing options...
vekia Posted March 24, 2014 Share Posted March 24, 2014 you use 1.5.6.2?! i just thought that 1.6, you use font awesome with 1.5.6.2? your block cateogries module looks like module from 1.6 are you 100% sure? :| 1 Link to comment Share on other sites More sharing options...
ALMAJ Posted March 24, 2014 Share Posted March 24, 2014 lol yeah sorry for not been clear... guess your are giving me codes for working on prestashop 1.6 lol yes i use font awesome with prestashop 1.5.6.2 I've integrated and yes the block categories have similarities with prestashop 1.6 because I've copy the design from it Link to comment Share on other sites More sharing options...
vekia Posted March 25, 2014 Share Posted March 25, 2014 i'm so clumsy lol we talked about updates of modules in other section :/ anyway, here is the solution 1.5 $this->_menu .= '<a href="'.Tools::HtmlEntitiesUTF8($category_link).'">'.$category->name.'</a>'; change it to: $this->_menu .= '<a href="'.Tools::HtmlEntitiesUTF8($category_link).'">'.($category->id_category==2 ? '<i class="fa fa-home"></i>':'').$category->name.'</a>'; to add more icons just add another (condition) $this->_menu .= '<a href="'.Tools::HtmlEntitiesUTF8($category_link).'">'.($category->id_category==2 ? '<i class="fa fa-home"></i>':'').($category->id_category==3 ? '<i class="fa fa-camera"></i>':'').$category->name.'</a>'; don't forget to regenerate menu! 1 Link to comment Share on other sites More sharing options...
ALMAJ Posted March 25, 2014 Share Posted March 25, 2014 i'm so clumsy lol we talked about updates of modules in other section :/ anyway, here is the solution 1.5 $this->_menu .= '<a href="'.Tools::HtmlEntitiesUTF8($category_link).'">'.$category->name.'</a>'; change it to: $this->_menu .= '<a href="'.Tools::HtmlEntitiesUTF8($category_link).'">'.($category->id_category==2 ? '<i class="fa fa-home"></i>':'').$category->name.'</a>'; to add more icons just add another (condition) $this->_menu .= '<a href="'.Tools::HtmlEntitiesUTF8($category_link).'">'.($category->id_category==2 ? '<i class="fa fa-home"></i>':'').($category->id_category==3 ? '<i class="fa fa-camera"></i>':'').$category->name.'</a>'; don't forget to regenerate menu! Hi Vekia thanks for trying help me again, but unfortunately your code above did not worked I've rebuild the module, clean the browser cache, and deleted my prestashop cache , also my shop is in force compilation mode. I've also test this previous code Meant for prestashop 1.6 on another webstore but with prestashop 1.6: $html .= '<a href="'.$link.'" title="'.$category['name'].'">'.($category['id_category']==3 ? '<i class="fa fa-home"></i>':'').$category['name'].'</a>'; and also did'n worked did worked with your prestashop installation? If so, then I think something is wrong in my end I apologize for this puzzle taking your time Vekia Best regards Link to comment Share on other sites More sharing options...
vekia Posted March 25, 2014 Share Posted March 25, 2014 can you please check what code your menu generated? does the <i class> exists in your menu code? (when you check front office page source) i think the problem is with this, code appears, but doesnt display icon Link to comment Share on other sites More sharing options...
ALMAJ Posted March 25, 2014 Share Posted March 25, 2014 can you please check what code your menu generated? does the <i class> exists in your menu code? (when you check front office page source) i think the problem is with this, code appears, but doesnt display icon I get this: <a href="/store">Home</a> no <i class> you can see it here: www.tekcenter.pt/store if you want i can give you access to my ftp and BO Link to comment Share on other sites More sharing options...
vekia Posted March 25, 2014 Share Posted March 25, 2014 i know that this may sounds obvious but you use correct id_category? Link to comment Share on other sites More sharing options...
vekia Posted March 25, 2014 Share Posted March 25, 2014 can you grant me access? im desperated Link to comment Share on other sites More sharing options...
ALMAJ Posted March 25, 2014 Share Posted March 25, 2014 i know that this may sounds obvious but you use correct id_category? Yes the id_category is 3 because it says in the module configuration here: I will send you a private message with the access details thanks Link to comment Share on other sites More sharing options...
vekia Posted March 25, 2014 Share Posted March 25, 2014 ok i will check it today evening, im going out to a dinner about 6pm ... but i will be thinking about this all the time lol, im no-life 1 Link to comment Share on other sites More sharing options...
ALMAJ Posted March 25, 2014 Share Posted March 25, 2014 me too lol Link to comment Share on other sites More sharing options...
vekia Posted March 25, 2014 Share Posted March 25, 2014 i decided to quote here what i send to you via PM, it's worth to do it, maybe someone looking for the same solution lol i know where the problem is your "home" is a simple link button, not category! my code is for categories, you can for example add laptop icon to category like i added a second ago (please verify it) you can add as many category images as you want (in the same way as i described in the topic) if you want to add image to your simple link, like home change:$this->_menu .= '<li><a href="'.Tools::HtmlEntitiesUTF8($link[0]['link']).'"'.(($link[0]['new_window']) ? ' target="_blank"': '').'>'.$link[0]['label'].'</a></li>'.PHP_EOL; to: $this->_menu .= '<li><a href="'.Tools::HtmlEntitiesUTF8($link[0]['link']).'"'.(($link[0]['new_window']) ? ' target="_blank"': '').'>'.(strtolower($link[0]['label'])=="home" ? '<i class="facat fa-home"></i> ':'').$link[0]['label'].'</a></li>'.PHP_EOL; effect: 2 Link to comment Share on other sites More sharing options...
ALMAJ Posted March 25, 2014 Share Posted March 25, 2014 Thanks Vekia, i don't know how i can thank you enough Now I can see THE logic now I will polish the top menu bar Thanks again, Link to comment Share on other sites More sharing options...
nanovector Posted July 22, 2014 Share Posted July 22, 2014 Greetings everyone, I realize this is old topic. Should I start a new topic? I have problem following Vekia's #4 example . Regards Link to comment Share on other sites More sharing options...
vekia Posted July 22, 2014 Share Posted July 22, 2014 what kind of problems you've got? can you said something more, please? Link to comment Share on other sites More sharing options...
nanovector Posted July 23, 2014 Share Posted July 23, 2014 (edited) Thanks for responding Vekia. I'm trying to add icon in front of my category list, too. Following your example, I inserted below's code into category-tree-branch.tpl under default-bootstrap/modules/blockcategories/ <li {if isset($last) && $last == 'true'}class="last"{/if}> <a href="{$node.link|escape:'html':'UTF-8'}"{if isset($currentCategoryId) && $node.id == $currentCategoryId} class="selected"{/if} title="{$node.desc|strip_tags|trim|escape:'html':'UTF-8'}"> {$node.name|escape:'html':'UTF-8'} {if $node.id==3} <i class="fa fa-camera-retro"></i> {/if} </a> {if $node.children|@count > 0} <ul> {foreach from=$node.children item=child name=categoryTreeBranch} {if $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> {/if} </li> But, the icon doesn't show. Do I need to define the usage of font awesome somewhere else too? I'm using default bootstrap theme, prestashop 1.6.0.5 and there's only one category (women) my prestashop link is http://popdiving.com/pres/ Edited July 23, 2014 by nanovector (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted July 23, 2014 Share Posted July 23, 2014 in your code (page source) icon doesnt appear do you recompiled theme? Link to comment Share on other sites More sharing options...
nanovector Posted July 24, 2014 Share Posted July 24, 2014 Vekia, I have recompiled theme as you suggested. But, I don't know what you mean by (page source) icon doesn't appear. I have to confess, I have limited programming knowledge and very new at prestashop. Link to comment Share on other sites More sharing options...
vekia Posted July 24, 2014 Share Posted July 24, 2014 code that i pasted is a part of source of your website i checked it, and i don't see there icon code <i class="fa fa-camera-retro"></i> it means that: - module still shows old conent from .tpl files Link to comment Share on other sites More sharing options...
nanovector Posted July 24, 2014 Share Posted July 24, 2014 I see what you mean. Can you see the icon code now? Link to comment Share on other sites More sharing options...
josias Posted July 24, 2014 Share Posted July 24, 2014 I inserted in category-tree-branch.tpl before: <a href="{$node.link|escape:'html':'UTF-8'}"{if isset($currentCategoryId) && $node.id == $currentCategoryId} class="selected"{/if} title="{$node.desc|strip_tags|trim|escape:'html':'UTF-8'}"> {$node.name|escape:'html':'UTF-8'} </a> the code: <img src="{$img_dir}categorias/ico{$node.id}.png" style="float:left" > I uploaded the pictures inside a folder named categories, and each picture have as name the category id. works fine, but have a problem: all categories shows an image, and I want to disable for the third level (in my menu only have pictures the first and second level). I tried: {if $node.depth < 2} <img src="{$img_dir}categorias/ico{$node.id}.png" style="float:left" width="28" height="28"/> {/if} But is not working. Also I tried a filexists with no results: {if $node.children|@count > 0} <img src="{$img_dir}categorias/ico{$node.id}.png" style="float:left" width="28" height="28"/> {/if} Any idea? Thank you in advance Link to comment Share on other sites More sharing options...
vekia Posted July 25, 2014 Share Posted July 25, 2014 and if you use just {$node.depth} it displays value of category depth lvl ? Link to comment Share on other sites More sharing options...
josias Posted July 26, 2014 Share Posted July 26, 2014 and if you use just {$node.depth} it displays value of category depth lvl ? I tried with different sentences and I haven't a code for showing the depth level yet. If I use {$node.depth}, no results. I noticed depth is for the max depth. I configured blockcategories to depth 0 (infinite) and when I use node.deth allways shows 0 Link to comment Share on other sites More sharing options...
vekia Posted July 26, 2014 Share Posted July 26, 2014 so, the easiest way at the moment to see all possible variables: {$node|print_r} use it, and then you will see possible variables, hope that level variable will be there Link to comment Share on other sites More sharing options...
josias Posted July 26, 2014 Share Posted July 26, 2014 so, the easiest way at the moment to see all possible variables: {$node|print_r} use it, and then you will see possible variables, hope that level variable will be there Thank you very much for your answer. I tried and variables appearing are: ID, LINK, NAME AND DESC . no depth variable :-( Link to comment Share on other sites More sharing options...
vekia Posted July 27, 2014 Share Posted July 27, 2014 so we have a little problem ;-) blockcategories.php $return = array( 'id' => $id_category, 'link' => $this->context->link->getCategoryLink($id_category, $resultIds[$id_category]['link_rewrite']), 'name' => $resultIds[$id_category]['name'], 'desc'=> $resultIds[$id_category]['description'], 'children' => $children ); it will be necessary to add there 'level_depth' => $resultIds($id_category]['level_depth'], Link to comment Share on other sites More sharing options...
josias Posted July 28, 2014 Share Posted July 28, 2014 so we have a little problem ;-) blockcategories.php $return = array( 'id' => $id_category, 'link' => $this->context->link->getCategoryLink($id_category, $resultIds[$id_category]['link_rewrite']), 'name' => $resultIds[$id_category]['name'], 'desc'=> $resultIds[$id_category]['description'], 'children' => $children ); it will be necessary to add there 'level_depth' => $resultIds($id_category]['level_depth'], Thank you again for your help. When I inserted your line I received a syntax error message in dreamweaver, and website crashes $return = array( 'id' => $id_category, 'link' => $this->context->link->getCategoryLink($id_category, $resultIds[$id_category]['link_rewrite']), 'name' => $resultIds[$id_category]['name'], 'desc'=> $resultIds[$id_category]['description'], 'level_depth' => $resultIds($id_category]['level_depth'], 'children' => $children ); Link to comment Share on other sites More sharing options...
vekia Posted July 28, 2014 Share Posted July 28, 2014 what error exactly? can you show error, please? btw. in dreamweaver? Link to comment Share on other sites More sharing options...
josias Posted July 28, 2014 Share Posted July 28, 2014 what error exactly? can you show error, please? btw. in dreamweaver? In dreamweaver cc appears: "sintaxis mistake". when you start the website the page appears white, till you remove the extra sentence Link to comment Share on other sites More sharing options...
vekia Posted July 28, 2014 Share Posted July 28, 2014 there is a typo my bad instead 'level_depth' => $resultIds($id_category]['level_depth'], use 'level_depth' => $resultIds[$id_category]['level_depth'], Link to comment Share on other sites More sharing options...
vekia Posted July 28, 2014 Share Posted July 28, 2014 one more thing change: SELECT DISTINCT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite to SELECT DISTINCT c.level_depth, c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite Link to comment Share on other sites More sharing options...
josias Posted July 28, 2014 Share Posted July 28, 2014 there is a typo my bad instead 'level_depth' => $resultIds($id_category]['level_depth'], use 'level_depth' => $resultIds[$id_category]['level_depth'], omg! you are right, I dont see the ( even I rechecked some times :-) thank you one more thing change: SELECT DISTINCT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite to SELECT DISTINCT c.level_depth, c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite I made these changes and now no sintaxis mistakes. However my sentence {if $node.level_depth <2} <img src="{$img_dir}categorias/ico{$node.id}.png" style="float:left" width="28" height="28"/> {/if} inside category-tree-branch.tpl still no working. When I place {$node|print_r} I noticed all time the same answer for all nodes: [level_depth] => [children] while for the other properties you have an specific answer (for example ID => 72 , link => http://wwww, desc => description of the product...) Thank you Link to comment Share on other sites More sharing options...
vekia Posted July 28, 2014 Share Posted July 28, 2014 you changed also sql query? Link to comment Share on other sites More sharing options...
josias Posted July 28, 2014 Share Posted July 28, 2014 you changed also sql query? I change the line "SELECT DISTINCT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite" and inserted the new one "'level_depth' => $resultIds[$id_category]['level_depth'],", anything more. Im sorry but Im not a programmer, just a seller with prestashop store trying to learn to do the things by myself. what you mean when you said "sql query"? Thank you very much again for your help Link to comment Share on other sites More sharing options...
vekia Posted July 28, 2014 Share Posted July 28, 2014 im confused what you did can you show full code, how it looks like after your changes? im testing code on my own and its allright, so i bet that you have something strange there Link to comment Share on other sites More sharing options...
josias Posted July 28, 2014 Share Posted July 28, 2014 im confused what you did can you show full code, how it looks like after your changes? im testing code on my own and its allright, so i bet that you have something strange there Sure: blockcategories.php: <?php /* * 2007-2014 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Academic Free License (AFL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/afl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA <[email protected]> * @copyright 2007-2014 PrestaShop SA * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ if (!defined('_PS_VERSION_')) exit; class BlockCategories extends Module { public function __construct() { $this->name = 'blockcategories'; $this->tab = 'front_office_features'; $this->version = '2.8'; $this->author = 'PrestaShop'; $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('Categories block'); $this->description = $this->l('Adds a block featuring product categories.'); $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_); } public function install() { // Prepare tab $tab = new Tab(); $tab->active = 1; $tab->class_name = "AdminBlockCategories"; $tab->name = array(); foreach (Language::getLanguages(true) as $lang) $tab->name[$lang['id_lang']] = 'BlockCategories'; $tab->id_parent = -1; $tab->module = $this->name; if (!$tab->add() || !parent::install() || !$this->registerHook('footer') || !$this->registerHook('header') || // Temporary hooks. Do NOT hook any module on it. Some CRUD hook will replace them as soon as possible. !$this->registerHook('categoryAddition') || !$this->registerHook('categoryUpdate') || !$this->registerHook('categoryDeletion') || !$this->registerHook('actionAdminMetaControllerUpdate_optionsBefore') || !$this->registerHook('actionAdminLanguagesControllerStatusBefore') || !$this->registerHook('displayBackOfficeCategory') || !Configuration::updateValue('BLOCK_CATEG_MAX_DEPTH', 4) || !Configuration::updateValue('BLOCK_CATEG_DHTML', 1) || !Configuration::updateValue('BLOCK_CATEG_ROOT_CATEGORY', 1)) return false; // Hook the module either on the left or right column $theme = new Theme(Context::getContext()->shop->id_theme); if ((!$theme->default_left_column || !$this->registerHook('leftColumn')) && (!$theme->default_right_column || !$this->registerHook('rightColumn'))) { // If there are no colums implemented by the template, throw an error and uninstall the module $this->_errors[] = $this->l('This module need to be hooked in a column and your theme does not implement one'); parent::uninstall(); return false; } return true; } public function uninstall() { $id_tab = (int)Tab::getIdFromClassName('AdminBlockCategories'); if ($id_tab) { $tab = new Tab($id_tab); $tab->delete(); } if (!parent::uninstall() || !Configuration::deleteByName('BLOCK_CATEG_MAX_DEPTH') || !Configuration::deleteByName('BLOCK_CATEG_DHTML') || !Configuration::deleteByName('BLOCK_CATEG_ROOT_CATEGORY')) return false; return true; } public function getContent() { $output = ''; if (Tools::isSubmit('submitBlockCategories')) { $maxDepth = (int)(Tools::getValue('BLOCK_CATEG_MAX_DEPTH')); $dhtml = Tools::getValue('BLOCK_CATEG_DHTML'); $nbrColumns = Tools::getValue('BLOCK_CATEG_NBR_COLUMN_FOOTER', 4); if ($maxDepth < 0) $output .= $this->displayError($this->l('Maximum depth: Invalid number.')); elseif ($dhtml != 0 && $dhtml != 1) $output .= $this->displayError($this->l('Dynamic HTML: Invalid choice.')); else { Configuration::updateValue('BLOCK_CATEG_MAX_DEPTH', (int)$maxDepth); Configuration::updateValue('BLOCK_CATEG_DHTML', (int)$dhtml); Configuration::updateValue('BLOCK_CATEG_NBR_COLUMN_FOOTER', (int)$nbrColumns); Configuration::updateValue('BLOCK_CATEG_SORT_WAY', Tools::getValue('BLOCK_CATEG_SORT_WAY')); Configuration::updateValue('BLOCK_CATEG_SORT', Tools::getValue('BLOCK_CATEG_SORT')); Configuration::updateValue('BLOCK_CATEG_ROOT_CATEGORY', Tools::getValue('BLOCK_CATEG_ROOT_CATEGORY')); $this->_clearBlockcategoriesCache(); Tools::redirectAdmin(AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&conf=6'); } } return $output.$this->renderForm(); } public function getTree($resultParents, $resultIds, $maxDepth, $id_category = null, $currentDepth = 0) { if (is_null($id_category)) $id_category = $this->context->shop->getCategory(); $children = array(); if (isset($resultParents[$id_category]) && count($resultParents[$id_category]) && ($maxDepth == 0 || $currentDepth < $maxDepth)) foreach ($resultParents[$id_category] as $subcat) $children[] = $this->getTree($resultParents, $resultIds, $maxDepth, $subcat['id_category'], $currentDepth + 1); if (!isset($resultIds[$id_category])) return false; $return = array( 'id' => $id_category, 'link' => $this->context->link->getCategoryLink($id_category, $resultIds[$id_category]['link_rewrite']), 'name' => $resultIds[$id_category]['name'], 'desc'=> $resultIds[$id_category]['description'], 'level_depth' => $resultIds[$id_category]['level_depth'], 'children' => $children ); return $return; } public function hookDisplayBackOfficeCategory($params) { $category = new Category((int)Tools::getValue('id_category')); $files = array(); if ($category->level_depth != 2) return; for ($i=0;$i<3;$i++) { if (file_exists(_PS_CAT_IMG_DIR_.(int)$category->id.'-'.$i.'_thumb.jpg')) { $files[$i]['type'] = HelperImageUploader::TYPE_IMAGE; $files[$i]['image'] = ImageManager::thumbnail(_PS_CAT_IMG_DIR_.(int)$category->id.'-'.$i.'_thumb.jpg', $this->context->controller->table.'_'.(int)$category->id.'-'.$i.'_thumb.jpg', 100, 'jpg', true, true); $files[$i]['delete_url'] = Context::getContext()->link->getAdminLink('AdminBlockCategories').'&deleteThumb='.$i.'&id_category='.(int)$category->id; } } $helper = new HelperImageUploader(); $helper->setMultiple(true)->setUseAjax(true)->setName('thumbnail')->setFiles($files)->setMaxFiles(3)->setUrl( Context::getContext()->link->getAdminLink('AdminBlockCategories').'&ajax=1&id_category='.$category->id .'&action=uploadThumbnailImages'); $this->smarty->assign('helper', $helper->render()); return $this->display(__FILE__, 'views/blockcategories_admin.tpl'); } public function hookLeftColumn($params) { $this->setLastVisitedCategory(); $phpself = $this->context->controller->php_self; $current_allowed_controllers = array('category'); $from_category = Configuration::get('PS_HOME_CATEGORY'); if ($phpself != null && in_array($phpself, $current_allowed_controllers) && Configuration::get('BLOCK_CATEG_ROOT_CATEGORY') && isset($this->context->cookie->last_visited_category) && $this->context->cookie->last_visited_category) $from_category = $this->context->cookie->last_visited_category; $category = new Category($from_category, $this->context->language->id); $cacheId = $this->getCacheId($category ? $category->id : null); if (!$this->isCached('blockcategories.tpl', $cacheId)) { $range = ''; $maxdepth = Configuration::get('BLOCK_CATEG_MAX_DEPTH'); if ($category) { if ($maxdepth > 0) $maxdepth += $category->level_depth; $range = 'AND nleft >= '.$category->nleft.' AND nright <= '.$category->nright; } $resultIds = array(); $resultParents = array(); $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 INNER JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = '.(int)$this->context->language->id.Shop::addSqlRestrictionOnLang('cl').') INNER JOIN `'._DB_PREFIX_.'category_shop` cs ON (cs.`id_category` = c.`id_category` AND cs.`id_shop` = '.(int)$this->context->shop->id.') WHERE (c.`active` = 1 OR c.`id_category` = '.(int)Configuration::get('PS_HOME_CATEGORY').') AND c.`id_category` != '.(int)Configuration::get('PS_ROOT_CATEGORY').' '.((int)$maxdepth != 0 ? ' AND `level_depth` <= '.(int)$maxdepth : '').' '.$range.' AND c.id_category IN ( SELECT id_category FROM `'._DB_PREFIX_.'category_group` WHERE `id_group` IN ('.pSQL(implode(', ', Customer::getGroupsStatic((int)$this->context->customer->id))).') ) ORDER BY `level_depth` ASC, '.(Configuration::get('BLOCK_CATEG_SORT') ? 'cl.`name`' : 'cs.`position`').' '.(Configuration::get('BLOCK_CATEG_SORT_WAY') ? 'DESC' : 'ASC')); foreach ($result as &$row) { $resultParents[$row['id_parent']][] = &$row; $resultIds[$row['id_category']] = &$row; } $blockCategTree = $this->getTree($resultParents, $resultIds, $maxdepth, ($category ? $category->id : null)); $this->smarty->assign('blockCategTree', $blockCategTree); if ((Tools::getValue('id_product') || Tools::getValue('id_category')) && isset($this->context->cookie->last_visited_category) && $this->context->cookie->last_visited_category) { $category = new Category($this->context->cookie->last_visited_category, $this->context->language->id); if (Validate::isLoadedObject($category)) $this->smarty->assign(array('currentCategory' => $category, 'currentCategoryId' => $category->id)); } $this->smarty->assign('isDhtml', Configuration::get('BLOCK_CATEG_DHTML')); if (file_exists(_PS_THEME_DIR_.'modules/blockcategories/blockcategories.tpl')) $this->smarty->assign('branche_tpl_path', _PS_THEME_DIR_.'modules/blockcategories/category-tree-branch.tpl'); else $this->smarty->assign('branche_tpl_path', _PS_MODULE_DIR_.'blockcategories/category-tree-branch.tpl'); } return $this->display(__FILE__, 'blockcategories.tpl', $cacheId); } protected function getCacheId($name = null) { $cache_id = parent::getCacheId(); if ($name !== null) $cache_id .= '|'.$name; if ((Tools::getValue('id_product') || Tools::getValue('id_category')) && isset($this->context->cookie->last_visited_category) && $this->context->cookie->last_visited_category) $cache_id .= '|'.(int)$this->context->cookie->last_visited_category; return $cache_id.'|'.implode('-', Customer::getGroupsStatic($this->context->customer->id)); } public function setLastVisitedCategory() { $cache_id = 'blockcategories::setLastVisitedCategory'; if (!Cache::isStored($cache_id)) { if (method_exists($this->context->controller, 'getCategory') && ($category = $this->context->controller->getCategory())) $this->context->cookie->last_visited_category = $category->id; elseif (method_exists($this->context->controller, 'getProduct') && ($product = $this->context->controller->getProduct())) if (!isset($this->context->cookie->last_visited_category) || !Product::idIsOnCategoryId($product->id, array(array('id_category' => $this->context->cookie->last_visited_category))) || !Category::inShopStatic($this->context->cookie->last_visited_category, $this->context->shop)) $this->context->cookie->last_visited_category = (int)$product->id_category_default; Cache::store($cache_id, $this->context->cookie->last_visited_category); } return Cache::retrieve($cache_id); } public function hookFooter($params) { $this->setLastVisitedCategory(); if (!$this->isCached('blockcategories_footer.tpl', $this->getCacheId())) { $maxdepth = Configuration::get('BLOCK_CATEG_MAX_DEPTH'); // Get all groups for this customer and concatenate them as a string: "1,2,3..." $groups = implode(', ', Customer::getGroupsStatic((int)$this->context->customer->id)); if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT DISTINCT c.level_depth, c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite FROM `'._DB_PREFIX_.'category` c '.Shop::addSqlAssociation('category', 'c').' LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = '.(int)$this->context->language->id.Shop::addSqlRestrictionOnLang('cl').') 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` IN ('.pSQL($groups).') ORDER BY `level_depth` ASC, '.(Configuration::get('BLOCK_CATEG_SORT') ? 'cl.`name`' : 'category_shop.`position`').' '.(Configuration::get('BLOCK_CATEG_SORT_WAY') ? 'DESC' : 'ASC'))) return; $resultParents = array(); $resultIds = array(); foreach ($result as &$row) { $resultParents[$row['id_parent']][] = &$row; $resultIds[$row['id_category']] = &$row; } //$nbrColumns = Configuration::get('BLOCK_CATEG_NBR_COLUMNS_FOOTER'); $nbrColumns = (int)Configuration::get('BLOCK_CATEG_NBR_COLUMN_FOOTER'); if (!$nbrColumns or empty($nbrColumns)) $nbrColumns = 3; $numberColumn = abs(count($result) / $nbrColumns); $widthColumn = floor(100 / $nbrColumns); $this->smarty->assign('numberColumn', $numberColumn); $this->smarty->assign('widthColumn', $widthColumn); $blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH')); unset($resultParents, $resultIds); $isDhtml = (Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false); $id_category = (int)Tools::getValue('id_category'); $id_product = (int)Tools::getValue('id_product'); $this->smarty->assign('blockCategTree', $blockCategTree); if (file_exists(_PS_THEME_DIR_.'modules/blockcategories/blockcategories_footer.tpl')) $this->smarty->assign('branche_tpl_path', _PS_THEME_DIR_.'modules/blockcategories/category-tree-branch.tpl'); else $this->smarty->assign('branche_tpl_path', _PS_MODULE_DIR_.'blockcategories/category-tree-branch.tpl'); $this->smarty->assign('isDhtml', $isDhtml); } $display = $this->display(__FILE__, 'blockcategories_footer.tpl', $this->getCacheId()); return $display; } public function hookRightColumn($params) { return $this->hookLeftColumn($params); } public function hookHeader() { $this->context->controller->addJS(_THEME_JS_DIR_.'tools/treeManagement.js'); $this->context->controller->addCSS(($this->_path).'blockcategories.css', 'all'); } private function _clearBlockcategoriesCache() { $this->_clearCache('blockcategories.tpl'); $this->_clearCache('blockcategories_footer.tpl'); } public function hookCategoryAddition($params) { $this->_clearBlockcategoriesCache(); } public function hookCategoryUpdate($params) { $this->_clearBlockcategoriesCache(); } public function hookCategoryDeletion($params) { $this->_clearBlockcategoriesCache(); } public function hookActionAdminMetaControllerUpdate_optionsBefore($params) { $this->_clearBlockcategoriesCache(); } public function renderForm() { $fields_form = array( 'form' => array( 'legend' => array( 'title' => $this->l('Settings'), 'icon' => 'icon-cogs' ), 'input' => array( array( 'type' => 'radio', 'label' => $this->l('Category root'), 'name' => 'BLOCK_CATEG_ROOT_CATEGORY', 'values' => array( array( 'id' => 'home', 'value' => 0, 'label' => $this->l('Home category') ), array( 'id' => 'current', 'value' => 1, 'label' => $this->l('Current category') ), ) ), array( 'type' => 'text', 'label' => $this->l('Maximum depth'), 'name' => 'BLOCK_CATEG_MAX_DEPTH', 'desc' => $this->l('Set the maximum depth of category sublevels displayed in this block (0 = infinite).'), ), array( 'type' => 'switch', 'label' => $this->l('Dynamic'), 'name' => 'BLOCK_CATEG_DHTML', 'desc' => $this->l('Activate dynamic (animated) mode for category sublevels.'), 'values' => array( array( 'id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled') ), array( 'id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled') ) ), ), array( 'type' => 'radio', 'label' => $this->l('Sort'), 'name' => 'BLOCK_CATEG_SORT', 'values' => array( array( 'id' => 'name', 'value' => 1, 'label' => $this->l('By name') ), array( 'id' => 'position', 'value' => 0, 'label' => $this->l('By position') ), ) ), array( 'type' => 'radio', 'label' => $this->l('Sort order'), 'name' => 'BLOCK_CATEG_SORT_WAY', 'values' => array( array( 'id' => 'name', 'value' => 1, 'label' => $this->l('Descending') ), array( 'id' => 'position', 'value' => 0, 'label' => $this->l('Ascending') ), ) ), array( 'type' => 'text', 'label' => $this->l('How many footer columns would you like?'), 'name' => 'BLOCK_CATEG_NBR_COLUMN_FOOTER', ), ), 'submit' => array( 'title' => $this->l('Save'), ) ), ); $helper = new HelperForm(); $helper->show_toolbar = false; $helper->table = $this->table; $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT')); $helper->default_form_language = $lang->id; $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0; $helper->identifier = $this->identifier; $helper->submit_action = 'submitBlockCategories'; $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->tpl_vars = array( 'fields_value' => $this->getConfigFieldsValues(), 'languages' => $this->context->controller->getLanguages(), 'id_language' => $this->context->language->id ); return $helper->generateForm(array($fields_form)); } public function getConfigFieldsValues() { return array( 'BLOCK_CATEG_MAX_DEPTH' => Tools::getValue('BLOCK_CATEG_MAX_DEPTH', Configuration::get('BLOCK_CATEG_MAX_DEPTH')), 'BLOCK_CATEG_DHTML' => Tools::getValue('BLOCK_CATEG_DHTML', Configuration::get('BLOCK_CATEG_DHTML')), 'BLOCK_CATEG_NBR_COLUMN_FOOTER' => Tools::getValue('BLOCK_CATEG_NBR_COLUMN_FOOTER', Configuration::get('BLOCK_CATEG_NBR_COLUMN_FOOTER')), 'BLOCK_CATEG_SORT_WAY' => Tools::getValue('BLOCK_CATEG_SORT_WAY', Configuration::get('BLOCK_CATEG_SORT_WAY')), 'BLOCK_CATEG_SORT' => Tools::getValue('BLOCK_CATEG_SORT', Configuration::get('BLOCK_CATEG_SORT')), 'BLOCK_CATEG_ROOT_CATEGORY' => Tools::getValue('BLOCK_CATEG_ROOT_CATEGORY', Configuration::get('BLOCK_CATEG_ROOT_CATEGORY')) ); } } category-tree-branch.tpl {* * 2007-2014 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Academic Free License (AFL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/afl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA <[email protected]> * @copyright 2007-2014 PrestaShop SA * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA *} <li {if isset($last) && $last == 'true'}class="last"{/if}> {if $node.level_depth <2} <img src="{$img_dir}categorias/ico{$node.id}.png" style="float:left" width="28" height="28"/> {/if} <a href="{$node.link|escape:'html':'UTF-8'}"{if isset($currentCategoryId) && $node.id == $currentCategoryId} class="selected"{/if} title="{$node.desc|strip_tags|trim|escape:'html':'UTF-8'}"> {$node.name|escape:'html':'UTF-8'} </a> {if $node.children|@count > 0} <ul> {foreach from=$node.children item=child name=categoryTreeBranch} {if $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> {/if} </li> Prestashop 1.6.0.8 Link to comment Share on other sites More sharing options...
vekia Posted July 28, 2014 Share Posted July 28, 2014 additonal change necessary: SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite to SELECT c.level_depth, c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite Link to comment Share on other sites More sharing options...
josias Posted July 28, 2014 Share Posted July 28, 2014 additonal change necessary: SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite to SELECT c.level_depth, c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite Now works perfect Thank you very much! Link to comment Share on other sites More sharing options...
vekia Posted July 28, 2014 Share Posted July 28, 2014 finally ! any chance to see it live? if it will be ready, let me know Link to comment Share on other sites More sharing options...
josias Posted July 28, 2014 Share Posted July 28, 2014 finally ! any chance to see it live? if it will be ready, let me know Im working on local yet, soon alive .. I will let you know Thank you again Link to comment Share on other sites More sharing options...
josias Posted August 1, 2014 Share Posted August 1, 2014 One simple question: changes I have made in blockcategories.php will be loosed if n future I upgrade the module. How to avoid it? I know for certain modifications are a "override folder" but this module havent. I tried to upload the modified file to "themes/mytheme/modules/blockcategories and its not working. Thank you in advance Link to comment Share on other sites More sharing options...
nanovector Posted August 7, 2014 Share Posted August 7, 2014 code that i pasted is a part of source of your website i checked it, and i don't see there icon code <i class="fa fa-camera-retro"></i> it means that: - module still shows old conent from .tpl files Vekia, I found out the problem, i think. Seems like I have font awesome v3; thus 'fa fa-camera-retro' which is for v4, doesn't work. But, I realize going with image icons are better for me since there are only a few diving font awesome icons. Is it possible to get the image icons next to subcategories (masks, snorkel, etc) like in the image? Link to comment Share on other sites More sharing options...
vekia Posted August 7, 2014 Share Posted August 7, 2014 yes it is, but instead of <i class="fa fa-camera-retro"></i> you will need to use some other code (blocks with associated images in background) for example: <div class="snorkel"></div> and in css styles: .snorkel { background:url('http://mysnorkel.com/image.png'); width:20px; height:20px; } Link to comment Share on other sites More sharing options...
nanovector Posted March 2, 2015 Share Posted March 2, 2015 (edited) Vekia. Sorry, for the overdue thank you. I got overwhelmed by codes (not a programmer by nature) and ended putting the site off I came back, followed your instruction and finally solved it. Now, I'm trying to add a second line (short Category description) like the arrow in the attached image. I tried with the codes below but fail. Could you help? Thank you again. {if $node.id==13} <div class="wetsuit"> </div> <div class="wetest"> baju selam</div> {/if} .wetsuit { background-image:url(http://www.popdiving.com/images/s_icon_wetsuit.gif); background-repeat:no-repeat; background-position: 0px 0px 25px 0px; width:25px; height:35px; clear: right; display: inline-block; } .wetest{ text-overflow: ellipsis; white-space: nowrap; padding-top:0px; padding-left:25px; } Edited March 2, 2015 by nanovector (see edit history) Link to comment Share on other sites More sharing options...
lovemyseo Posted March 5, 2015 Share Posted March 5, 2015 yes it is, but instead of <i class="fa fa-camera-retro"></i> you will need to use some other code (blocks with associated images in background) for example: <div class="snorkel"></div> and in css styles: .snorkel { background:url('http://mysnorkel.com/image.png'); width:20px; height:20px; } Hi Vekia is it possible to display category block as vertical menu instead of + sign opening ? in PS 1.6.0.13? Link to comment Share on other sites More sharing options...
chucurulo Posted July 3, 2015 Share Posted July 3, 2015 category-tree-branch.tpl {* * 2007-2014 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Academic Free License (AFL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/afl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA <[email protected]> * @copyright 2007-2014 PrestaShop SA * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA *} <li {if isset($last) && $last == 'true'}class="last"{/if}> {if $node.level_depth <2} <img src="{$img_dir}categorias/ico{$node.id}.png" style="float:left" width="28" height="28"/> {/if} <a href="{$node.link|escape:'html':'UTF-8'}"{if isset($currentCategoryId) && $node.id == $currentCategoryId} class="selected"{/if} title="{$node.desc|strip_tags|trim|escape:'html':'UTF-8'}"> {$node.name|escape:'html':'UTF-8'} </a> {if $node.children|@count > 0} <ul> {foreach from=$node.children item=child name=categoryTreeBranch} {if $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> {/if} </li> hello, With this code it worked perfect to put images. I'm interested in the images instead of placing icons FontAwesome, was making the first contributions in the tutorial does not work Vekia me. any ideas for cologar icons instead of images? Link to comment Share on other sites More sharing options...
Léo conesa Posted March 28, 2017 Share Posted March 28, 2017 (edited) Hello , i'm on Prestashop 1.6 and i found an easier solution. You just need to modify blockcategories.css ( themes/css/modules/blockcategories) First of all u must create a description on every catégories. So now you go to your Css file and do : #categories_block_left li a[title ="***Description***"]{ background-image: url("*****.png");( the img directory is \prestashop\themes\Test\css\modules\blockcategories) background-repeat: no-repeat; text-align: left; } Edited March 28, 2017 by Léo conesa (see edit history) Link to comment Share on other sites More sharing options...
zenky Posted April 19, 2017 Share Posted April 19, 2017 Good morning guys!, this module it's so good, I have a question. how can I get this module? Link to comment Share on other sites More sharing options...
italycarparts Posted June 21, 2017 Share Posted June 21, 2017 i didnt exactly understand what are you trying to achieve. but if you want to set background for top menus you can simply use some thing like: .sf-menu>li+li+li {background:url('../img/menu1.jpg') no-repeat top} or .sf-menu li:nth-child(3) {background:url('../img/menu2.jpg') no-repeat top} ihave used here Hello. I would like to have the "thumbnail menus" on the TOP HORIZONTAL MENU module (prestashop 1.6) Do you use the default form and this version? You can tell me what I should change or send the blocktopmenu.php file I would be very grateful to you Thanks in advance Link to comment Share on other sites More sharing options...
anu Posted December 29, 2017 Share Posted December 29, 2017 Helpfull forum discussion ...I want to 1 help in category menu .. So i want to display image in menu category to sub sub menu . How could display image with the title in menu label in prestashop 1.6 Link to comment Share on other sites More sharing options...
Andrey Dias Posted March 30, 2023 Share Posted March 30, 2023 Hello, I've seen a lot of information about this, but I can't seem to get the solution to this question! I would like to put DIFFERENT and CUSTOM icons for my Categories in the Horizontal Menu, as per the attached image, Prestashop version is 1.7.8.3 It's possible? 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