From 87faae97173d51e1b7eca091cdc4e5d7ed279c78 Mon Sep 17 00:00:00 2001 From: Jerome Nadaud Date: Thu, 14 Nov 2013 11:52:24 +0100 Subject: [PATCH] // Add top menu to blockcategories --- modules/blockcategories/blockcategories.php | 29 ++++++++- .../blockcategories/blockcategories_top.tpl | 63 +++++++++++++++++++ .../blockcategories/upgrade/install-2.1.php | 2 +- .../blockcategories/blockcategories_top.tpl | 8 +++ 4 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 modules/blockcategories/blockcategories_top.tpl diff --git a/modules/blockcategories/blockcategories.php b/modules/blockcategories/blockcategories.php index c96fd37d4..cdeb1a424 100644 --- a/modules/blockcategories/blockcategories.php +++ b/modules/blockcategories/blockcategories.php @@ -67,6 +67,7 @@ class BlockCategories extends Module !$this->registerHook('actionAdminMetaControllerUpdate_optionsBefore') || !$this->registerHook('actionAdminLanguagesControllerStatusBefore') || !$this->registerHook('displayBackOfficeCategory') || + !$this->registerHook('displayTop') || !Configuration::updateValue('BLOCK_CATEG_MAX_DEPTH', 4) || !Configuration::updateValue('BLOCK_CATEG_DHTML', 1)) return false; @@ -129,13 +130,28 @@ class BlockCategories extends Module if (!isset($resultIds[$id_category])) return false; + + $thumbnails = array(); + + if ($currentDepth == 0) + { + $files = scandir(_PS_CAT_IMG_DIR_); + + foreach ($files as $file) + if (preg_match('/'.$id_category.'-([0-9])?_thumb.jpg/i', $file) === 1) + $thumbnails[] = ImageManager::thumbnail(_PS_CAT_IMG_DIR_.$file, 'category_'.$file, 100, 'jpg', true, true); + + } + $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 + 'children' => $children, + 'thumbnails' => $thumbnails ); + return $return; } @@ -165,6 +181,13 @@ class BlockCategories extends Module return $this->display(__FILE__, 'views/blockcategories_admin.tpl'); } + public function hookDisplayTop($params) + { + $params['is_top_menu'] = true; + $this->smarty->assign('numberColumn', 3); + return $this->hookLeftColumn($params); + } + public function hookLeftColumn($params) { $category = false; @@ -181,7 +204,7 @@ class BlockCategories extends Module } $cacheId = $this->getCacheId($category ? $category->id : null); - if (!$this->isCached('blockcategories.tpl', $cacheId)) + if (!$this->isCached('blockcategories'.((isset($params['is_top_menu']) && $params['is_top_menu']) ? '_top' : '').'.tpl', $cacheId)) { $range = ''; $maxdepth = Configuration::get('BLOCK_CATEG_MAX_DEPTH'); @@ -227,7 +250,7 @@ class BlockCategories extends Module else $this->smarty->assign('branche_tpl_path', _PS_MODULE_DIR_.'blockcategories/category-tree-branch.tpl'); } - return $this->display(__FILE__, 'blockcategories.tpl', $cacheId); + return $this->display(__FILE__, 'blockcategories'.((isset($params['is_top_menu']) && $params['is_top_menu']) ? '_top' : '').'.tpl', $cacheId); } protected function getCacheId($name = null) diff --git a/modules/blockcategories/blockcategories_top.tpl b/modules/blockcategories/blockcategories_top.tpl new file mode 100644 index 000000000..fa89a6aee --- /dev/null +++ b/modules/blockcategories/blockcategories_top.tpl @@ -0,0 +1,63 @@ +{* +* 2007-2013 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 license@prestashop.com 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 +* @copyright 2007-2013 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + + +
+
+
+
    + + {foreach from=$blockCategTree.children item=child name=blockCategTree} + + {if $smarty.foreach.blockCategTree.last} + {include file="$branche_tpl_path" node=$child last='true'} + {else} + {include file="$branche_tpl_path" node=$child} + {/if} + + {if isset($blockCategTree.thumbnails) && $blockCategTree.thumbnails|count > 0} +
    + {foreach $blockCategTree.thumbnails as $thumbnail} +
    {$thumbnail}
    + {/foreach} +
    + {/if} + + {if ($smarty.foreach.blockCategTree.iteration mod $numberColumn) == 0 AND !$smarty.foreach.blockCategTree.last} +
+
+
+ + +
+
+ \ No newline at end of file diff --git a/modules/blockcategories/upgrade/install-2.1.php b/modules/blockcategories/upgrade/install-2.1.php index ace16ef68..1fd682727 100644 --- a/modules/blockcategories/upgrade/install-2.1.php +++ b/modules/blockcategories/upgrade/install-2.1.php @@ -5,5 +5,5 @@ if (!defined('_PS_VERSION_')) function upgrade_module_2_1($object) { - return $object->registerHook('displayBackOfficeCategory'); + return ($object->registerHook('displayBackOfficeCategory') && $object->registerHook('displayTop')); } diff --git a/themes/default-bootstrap/modules/blockcategories/blockcategories_top.tpl b/themes/default-bootstrap/modules/blockcategories/blockcategories_top.tpl index 77232ecd8..fa89a6aee 100644 --- a/themes/default-bootstrap/modules/blockcategories/blockcategories_top.tpl +++ b/themes/default-bootstrap/modules/blockcategories/blockcategories_top.tpl @@ -36,6 +36,14 @@ {else} {include file="$branche_tpl_path" node=$child} {/if} + + {if isset($blockCategTree.thumbnails) && $blockCategTree.thumbnails|count > 0} +
+ {foreach $blockCategTree.thumbnails as $thumbnail} +
{$thumbnail}
+ {/foreach} +
+ {/if} {if ($smarty.foreach.blockCategTree.iteration mod $numberColumn) == 0 AND !$smarty.foreach.blockCategTree.last}