Jump to content

Image/Icon in category menu


nogy

Recommended Posts

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!

 

 

4jis.jpg

Link to comment
Share on other sites

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 by Paul de Cocq (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 4 months later...

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 by majority (see edit history)
Link to comment
Share on other sites

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>
  • Like 3
Link to comment
Share on other sites

Thanks Vekia, it works great! you make everything easy man  :P

 

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! B)

 

Thanks

Edited by majority (see edit history)
Link to comment
Share on other sites

majority... WOW!

looks amazing :D

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

  • Like 3
Link to comment
Share on other sites

Thanks :D

 

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 by majority (see edit history)
Link to comment
Share on other sites

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: post-376986-0-02137400-1395588916_thumb.jpg

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:post-376986-0-91776500-1395590561_thumb.jpg

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! :unsure:  

then this: 

{/if}
<option value="LNK2">HOME</option>
<i class="fa fa-bolt"></i>
{/if}

 nothing!  :wacko:

 

 

 

PS: sorry nogy for hijacking your topic :ph34r:

 

Tanks again.

 

Best regards

Edited by ALMAJ (see edit history)
Link to comment
Share on other sites

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

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 by ALMAJ (see edit history)
Link to comment
Share on other sites

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... :wacko:

 

tanks again for your effort Vekia, I really appreciate your valuable help

 

Regards

Link to comment
Share on other sites

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 by sooroos (see edit history)
Link to comment
Share on other sites

sorry vekia it's not working :unsure:

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 :huh: , the only thing its failing its the right place, as you can see here:

post-376986-0-93583200-1395686848_thumb.jpg

 

 

Link to comment
Share on other sites

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 by ALMAJ (see edit history)
Link to comment
Share on other sites

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

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

  • Like 2
Link to comment
Share on other sites

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 by ALMAJ (see edit history)
Link to comment
Share on other sites

to be honest, i wrote everything without testing :D

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

 

to be honest, i wrote everything without testing :D

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

lol yeah :D  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  :P

and yes the block categories have similarities with prestashop 1.6 because I've copy the design from it  B)

Link to comment
Share on other sites

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!

  • Like 1
Link to comment
Share on other sites

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 :unsure:

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 :unsure:

did worked with your prestashop installation? If so, then I think something is wrong in my end :huh:

 

I apologize for this puzzle taking your time Vekia

 

Best regards

Link to comment
Share on other sites

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

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

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:

post-376986-0-37948500-1395763515_thumb.jpg

 

I will send you a private message with the access details :)

 

thanks

Link to comment
Share on other sites

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:
51i77Np.png

 

 

  • Like 2
Link to comment
Share on other sites

  • 3 months later...

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 by nanovector (see edit history)
Link to comment
Share on other sites

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

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

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

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

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

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

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

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

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

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

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

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

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?

image.jpg

Link to comment
Share on other sites

  • 6 months later...

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.

 

screenshot.gif

     {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 by nanovector (see edit history)
Link to comment
Share on other sites

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

  • 3 months later...

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

  • 1 year later...

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 by Léo conesa (see edit history)
Link to comment
Share on other sites

  • 4 weeks later...
  • 2 months later...

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

  • 6 months later...
  • 5 years later...

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!

Image2.jpg

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...