Skip to content
This repository was archived by the owner on Dec 1, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions blocktopmenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ public function install($delete_params = true)
$this->clearMenuCache();

if ($delete_params) {
if (!$this->installDb() || !Configuration::updateGlobalValue('MOD_BLOCKTOPMENU_ITEMS', 'CAT3,CAT26') || !Configuration::updateGlobalValue('MOD_BLOCKTOPMENU_SEARCH', '1')) {
if (!$this->installDb()
|| !Configuration::updateGlobalValue('MOD_BLOCKTOPMENU_ITEMS', 'CAT3,CAT26')
|| !Configuration::updateGlobalValue('MOD_BLOCKTOPMENU_SEARCH', '1')
|| !Configuration::updateGlobalValue('MOD_BLOCKTOPMENU_DEPTH_LEVEL', '3')
) {
return false;
}
}
Expand Down Expand Up @@ -128,7 +132,11 @@ public function uninstall($delete_params = true)
$this->clearMenuCache();

if ($delete_params) {
if (!$this->uninstallDB() || !Configuration::deleteByName('MOD_BLOCKTOPMENU_ITEMS') || !Configuration::deleteByName('MOD_BLOCKTOPMENU_SEARCH')) {
if (!$this->uninstallDB()
|| !Configuration::deleteByName('MOD_BLOCKTOPMENU_ITEMS')
|| !Configuration::deleteByName('MOD_BLOCKTOPMENU_SEARCH')
|| !Configuration::deleteByName('MOD_BLOCKTOPMENU_DEPTH_LEVEL')
) {
return false;
}
}
Expand Down Expand Up @@ -189,6 +197,7 @@ public function getContent()
}

$updated &= Configuration::updateValue('MOD_BLOCKTOPMENU_SEARCH', (bool)Tools::getValue('search'), false, (int)$shop_group_id, (int)$shop_id);
$updated &= Configuration::updateValue('MOD_BLOCKTOPMENU_DEPTH_LEVEL', (int)Tools::getValue('depth_level'), false, (int)$shop_group_id, (int)$shop_id);

if (!$updated) {
$shop = new Shop($shop_id);
Expand Down Expand Up @@ -592,6 +601,10 @@ protected function generateCategoriesOption($categories, $items_to_skip = null)

protected function generateCategoriesMenu($categories, $is_children = 0)
{
$shop_id = (int)$this->context->shop->id;
$shop_group_id = Shop::getGroupFromShop($shop_id);
$depthLevel = (int)Configuration::get('MOD_BLOCKTOPMENU_DEPTH_LEVEL', null, $shop_group_id, $shop_id);

$html = '';

foreach ($categories as $key => $category) {
Expand All @@ -611,7 +624,7 @@ protected function generateCategoriesMenu($categories, $is_children = 0)
&& (int)Tools::getValue('id_category') == (int)$category['id_category']) ? ' class="sfHoverForce"' : '').'>';
$html .= '<a href="'.$link.'" title="'.$category['name'].'">'.$category['name'].'</a>';

if (isset($category['children']) && !empty($category['children'])) {
if (isset($category['children']) && !empty($category['children']) && $category['level_depth'] <= $depthLevel) {
$html .= '<ul>';
$html .= $this->generateCategoriesMenu($category['children'], 1);

Expand Down Expand Up @@ -970,7 +983,12 @@ public function renderForm()
'label' => $this->l('Disabled')
)
),
)
),
array(
'type' => 'text',
'label' => $this->l('Depth level'),
'name' => 'depth_level',
),
),
'submit' => array(
'name' => 'submitBlocktopmenu',
Expand Down Expand Up @@ -1005,7 +1023,12 @@ public function renderForm()
'label' => $this->l('Disabled')
)
),
)
),
array(
'type' => 'text',
'label' => $this->l('Depth level'),
'name' => 'depth_level',
),
),
'submit' => array(
'name' => 'submitBlocktopmenu',
Expand Down Expand Up @@ -1259,14 +1282,17 @@ public function getConfigFieldsValues()
{
$shops = Shop::getContextListShopID();
$is_search_on = true;
$depth_level = 3;

foreach ($shops as $shop_id) {
$shop_group_id = Shop::getGroupFromShop($shop_id);
$is_search_on &= (bool)Configuration::get('MOD_BLOCKTOPMENU_SEARCH', null, $shop_group_id, $shop_id);
$depth_level = (int)Configuration::get('MOD_BLOCKTOPMENU_DEPTH_LEVEL', null, $shop_group_id, $shop_id);
}

return array(
'search' => (int)$is_search_on
'search' => (int)$is_search_on,
'depth_level' => (int)$depth_level,
);
}

Expand Down
33 changes: 33 additions & 0 deletions upgrade/install-2.3.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/*
* 2007-2016 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 <contact@prestashop.com>
* @copyright 2007-2016 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;
}

function upgrade_module_2_3($object)
{
return Configuration::updateGlobalValue('MOD_BLOCKTOPMENU_DEPTH_LEVEL', '3');
}