diff --git a/modules/cttopmenu/classes/CTTopMenuItem.php b/modules/cttopmenu/classes/CTTopMenuItem.php
index 7a152236..8fc25409 100644
--- a/modules/cttopmenu/classes/CTTopMenuItem.php
+++ b/modules/cttopmenu/classes/CTTopMenuItem.php
@@ -8,17 +8,18 @@ class CTTopMenuItem extends ObjectModel
/**
* Menu item types
*/
- const TYPE_CUSTOM_LINK = 0;
- const TYPE_PRODUCT = 1;
- const TYPE_CATEGORY = 2;
- const TYPE_CATEGORY_TREE = 3;
- const TYPE_CMS = 4;
- const TYPE_CMS_CATEGORY = 5;
- const TYPE_CMS_CATEGORY_TREE = 6;
- const TYPE_MANUFACTURER = 7;
- const TYPE_MANUFACTURER_LIST = 8;
- const TYPE_SUPPLIER = 9;
- const TYPE_SUPPLIER_LIST = 10;
+ const TYPE_CUSTOM_LINK = 0;
+ const TYPE_PRODUCT = 1;
+ const TYPE_CATEGORY = 2;
+ const TYPE_CATEGORY_TREE = 3;
+ const TYPE_CATEGORY_FLAT_TREE = 11;
+ const TYPE_CMS = 4;
+ const TYPE_CMS_CATEGORY = 5;
+ const TYPE_CMS_CATEGORY_TREE = 6;
+ const TYPE_MANUFACTURER = 7;
+ const TYPE_MANUFACTURER_LIST = 8;
+ const TYPE_SUPPLIER = 9;
+ const TYPE_SUPPLIER_LIST = 10;
/** @var int */
public $type = 0;
@@ -72,6 +73,7 @@ class CTTopMenuItem extends ObjectModel
self::TYPE_PRODUCT,
self::TYPE_CATEGORY,
self::TYPE_CATEGORY_TREE,
+ self::TYPE_CATEGORY_FLAT_TREE,
self::TYPE_CMS,
self::TYPE_CMS_CATEGORY,
self::TYPE_CMS_CATEGORY_TREE,
diff --git a/modules/cttopmenu/config.xml b/modules/cttopmenu/config.xml
index afee2939..cc1e6dcb 100644
--- a/modules/cttopmenu/config.xml
+++ b/modules/cttopmenu/config.xml
@@ -2,11 +2,11 @@
cttopmenu
-
+
1
1
-
+
\ No newline at end of file
diff --git a/modules/cttopmenu/controllers/admin/AdminCTTopMenuItemController.php b/modules/cttopmenu/controllers/admin/AdminCTTopMenuItemController.php
index abdae7f0..0d80048f 100644
--- a/modules/cttopmenu/controllers/admin/AdminCTTopMenuItemController.php
+++ b/modules/cttopmenu/controllers/admin/AdminCTTopMenuItemController.php
@@ -55,6 +55,14 @@ public function __construct()
'tree_max_depth' => true,
),
),
+ CTTopMenuItem::TYPE_CATEGORY_FLAT_TREE => array(
+ 'name' => $this->l('Category Flat Tree'),
+ 'entity_name' => $this->l('Category'),
+ 'fields' => array(
+ 'entity_id' => true,
+ 'tree_max_depth' => true,
+ ),
+ ),
CTTopMenuItem::TYPE_CMS => array(
'name' => $this->l('CMS Link'),
'entity_name' => $this->l('CMS'),
@@ -100,14 +108,9 @@ public function __construct()
);
// Write ID column so we can use this array as option list in fields form
- $this->menuItemTypes = array_map(
- function ($value, $key) {
- $value['id'] = $key;
- return $value;
- },
- $this->menuItemTypes,
- array_keys($this->menuItemTypes)
- );
+ foreach ($this->menuItemTypes as $menuItemTypeKey => &$menuItemType) {
+ $menuItemType['id'] = $menuItemTypeKey;
+ }
}
/**
diff --git a/modules/cttopmenu/cttopmenu.php b/modules/cttopmenu/cttopmenu.php
index b92e8e75..9589452c 100644
--- a/modules/cttopmenu/cttopmenu.php
+++ b/modules/cttopmenu/cttopmenu.php
@@ -364,6 +364,8 @@ public function buildMenuItem(array $menuItem, $id_shop, $id_lang)
return $this->buildCategoryLink($menuItem, $id_shop, $id_lang);
case CTTopMenuItem::TYPE_CATEGORY_TREE:
return $this->buildCategoryTree($menuItem, $id_shop, $id_lang);
+ case CTTopMenuItem::TYPE_CATEGORY_FLAT_TREE:
+ return $this->buildCategoryFlatTree($menuItem, $id_shop, $id_lang);
case CTTopMenuItem::TYPE_CMS:
return $this->buildCmsLink($menuItem, $id_shop, $id_lang);
case CTTopMenuItem::TYPE_CMS_CATEGORY:
@@ -590,6 +592,35 @@ protected function buildCategoryTreeItem(array $category, $id_shop, $id_lang, $d
);
}
+ /**
+ * Builds a menu tree where subcategories of a given category
+ * are a flattened
+ *
+ * @param array $menuItem
+ * @param int $id_shop
+ * @param int $id_lang
+ *
+ * @return array
+ */
+ protected function buildCategoryFlatTree(array $menuItem, $id_shop, $id_lang)
+ {
+ $tree = $this->buildCategoryTree($menuItem, $id_shop, $id_lang);
+ $tree['type'] = 'category-flat-tree';
+
+ $treeSubItems = array();
+ foreach ($tree['sub_items'] as $subItemKey => $subItemTree) {
+ $treeSubItems = array_merge($treeSubItems, $this->flattenMenuItemTree($subItemTree));
+ }
+
+ usort($treeSubItems, function ($a, $b) {
+ return ($a['name'] < $b['name']) ? -1 : 1;
+ });
+
+ $tree['sub_items'] = $treeSubItems;
+
+ return $tree;
+ }
+
/**
* Builds menu item
*
@@ -1015,4 +1046,25 @@ protected function buildSupplierList(array $menuItem, $id_lang)
'sub_items' => $subItems,
);
}
+
+ /**
+ * Flattens the menu tree to a flat list (array)
+ *
+ * @param array $menuItem
+ *
+ * @return array
+ */
+ protected function flattenMenuItemTree(array $menuItem)
+ {
+ $menuItemList = array();
+
+ foreach ($menuItem['sub_items'] as $menuSubItem) {
+ $menuItemList = array_merge($menuItemList, $this->flattenMenuItemTree($menuSubItem));
+ }
+
+ $menuItem['sub_items'] = array();
+ $menuItemList[] = $menuItem;
+
+ return $menuItemList;
+ }
}
diff --git a/modules/cttopmenu/views/templates/hook/tree_item.tpl b/modules/cttopmenu/views/templates/hook/tree_item.tpl
index 618ac69f..3f6f5aa9 100644
--- a/modules/cttopmenu/views/templates/hook/tree_item.tpl
+++ b/modules/cttopmenu/views/templates/hook/tree_item.tpl
@@ -1,5 +1,5 @@
-
+
{if !empty($item.icon)}{/if}
{$item.name|escape:'html':'UTF-8'}