Skip to content
This repository was archived by the owner on Dec 1, 2020. It is now read-only.
Open
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
94 changes: 71 additions & 23 deletions blocktopmenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ 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_SHOW_SUBMENU', '1'))
return false;

return true;
Expand Down Expand Up @@ -123,7 +123,7 @@ 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_SHOW_SUBMENU'))
return false;

return true;
Expand Down Expand Up @@ -182,6 +182,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_SHOW_SUBMENU', (bool)Tools::getValue('showsubmenu'), false, (int)$shop_group_id, (int)$shop_id);

if (!$updated)
{
Expand Down Expand Up @@ -612,32 +613,37 @@ private 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']))
{
$html .= '<ul>';
$html .= $this->generateCategoriesMenu($category['children'], 1);

if ((int)$category['level_depth'] > 1 && !$is_children)

$shop_id = (int)$this->context->shop->id;
$shop_group_id = Shop::getGroupFromShop($shop_id);
if(Configuration::get('MOD_BLOCKTOPMENU_SHOW_SUBMENU', null, $shop_group_id, $shop_id)) {
if (isset($category['children']) && !empty($category['children']))
{
$files = scandir(_PS_CAT_IMG_DIR_);
$html .= '<ul>';
$html .= $this->generateCategoriesMenu($category['children'], 1);

if (count($files) > 0)
if ((int)$category['level_depth'] > 1 && !$is_children)
{
$html .= '<li class="category-thumbnail">';
$files = scandir(_PS_CAT_IMG_DIR_);

if (count($files) > 0)
{
$html .= '<li class="category-thumbnail">';

foreach ($files as $file)
if (preg_match('/^'.$category['id_category'].'-([0-9])?_thumb.jpg/i', $file) === 1)
$html .= '<div><img src="'.$this->context->link->getMediaLink(_THEME_CAT_DIR_.$file)
.'" alt="'.Tools::SafeOutput($category['name']).'" title="'
.Tools::SafeOutput($category['name']).'" class="imgm" /></div>';
foreach ($files as $file)
if (preg_match('/^'.$category['id_category'].'-([0-9])?_thumb.jpg/i', $file) === 1)
$html .= '<div><img src="'.$this->context->link->getMediaLink(_THEME_CAT_DIR_.$file)
.'" alt="'.Tools::SafeOutput($category['name']).'" title="'
.Tools::SafeOutput($category['name']).'" class="imgm" /></div>';

$html .= '</li>';
$html .= '</li>';
}
}
}

$html .= '</ul>';
$html .= '</ul>';
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useless whitespaces.

$html .= '</li>';
}

Expand Down Expand Up @@ -725,6 +731,7 @@ public function hookDisplayTop($param)
$shop_group_id = Shop::getGroupFromShop($shop_id);

$this->smarty->assign('MENU_SEARCH', Configuration::get('MOD_BLOCKTOPMENU_SEARCH', null, $shop_group_id, $shop_id));
$this->smarty->assign('MENU_SHOWSUBMENU', Configuration::get('MOD_BLOCKTOPMENU_SHOW_SUBMENU', null, $shop_group_id, $shop_id));
$this->smarty->assign('MENU', $this->_menu);
$this->smarty->assign('this_path', $this->_path);
}
Expand Down Expand Up @@ -953,6 +960,24 @@ public function renderForm()
'label' => $this->l('Disabled')
)
),
),
array(
'type' => 'switch',
'label' => $this->l('Show Menu Children'),
'name' => 'showsubmenu',
'is_bool' => true,
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
)
),
'submit' => array(
Expand Down Expand Up @@ -989,6 +1014,26 @@ public function renderForm()
),
)
),
'input' => array(
array(
'type' => 'switch',
'label' => $this->l('Show Children Menu'),
'name' => 'showsubmenu',
'is_bool' => true,
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
)
),
'submit' => array(
'name' => 'submitBlocktopmenu',
'title' => $this->l('Save')
Expand Down Expand Up @@ -1232,16 +1277,19 @@ public function getConfigFieldsValues()
{
$shops = Shop::getContextListShopID();
$is_search_on = true;
$is_showsubmenu_on = true;

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);
$shop_group_id = Shop::getGroupFromShop($shop_id);
$is_search_on &= (bool)Configuration::get('MOD_BLOCKTOPMENU_SEARCH', null, $shop_group_id, $shop_id);
$is_showsubmenu_on &= (bool)Configuration::get('MOD_BLOCKTOPMENU_SHOW_SUBMENU', null, $shop_group_id, $shop_id);

}

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

Expand Down