oct_menu.php
10.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<?php
/**
* @copyright OCTemplates
* @support https://octemplates.net/
* @license LICENSE.txt
*/
class ModelOCTemplatesMenuOCTMenu extends Controller {
public function getOCTMenuItems($data = []) {
$this->load->model('tool/image');
$customer_group_id = ($this->customer->isLogged()) ? $this->customer->getGroupId() : $this->config->get('config_customer_group_id');
$inType = $oct_items = [];
foreach ($data['types'] as $key => $value) {
if ($value) {
$inType[] = "'". $this->db->escape($key) ."'";
}
}
$display_type = isset($data['display_type']) ? $data['display_type'] : 'vertical';
if ($inType) {
$query = $this->db->query("
SELECT * FROM `" . DB_PREFIX . "oct_menu` om
LEFT JOIN `" . DB_PREFIX . "oct_menu_description` omd
ON (om.oct_menu_id = omd.oct_menu_id)
LEFT JOIN `" . DB_PREFIX . "oct_menu_to_customer_group` omc
ON (om.oct_menu_id = omc.oct_menu_id)
LEFT JOIN `" . DB_PREFIX . "oct_menu_to_store` oms
ON (om.oct_menu_id = oms.oct_menu_id)
WHERE
om.status = '1'
AND om.display_option = '" . $this->db->escape($display_type) . "'
AND om.type IN (" . implode(',', $inType) . ")
AND omc.customer_group_id = '" . (int)$customer_group_id . "'
AND oms.store_id = '" . (int)$this->config->get('config_store_id') . "'
AND omd.language_id = '" . (int)$this->config->get('config_language_id') . "'
ORDER BY
om.sort_order ASC
");
foreach ($query->rows as $oct_item) {
$fn_name = "getMenuType". $oct_item['type'];
$settings = json_decode($oct_item['settings'], true);
$children = $this->{$fn_name}($settings);
$oct_pages = isset($children['pages']) ? $children['pages'] : [];
unset($children['pages']);
$href = ($oct_item['link'] == "#" || empty($oct_item['link'])) ? "javascript:void(0);" : $oct_item['link'];
if (isset($settings['main_category_id'][0]) && !empty($settings['main_category_id'][0])) {
$href = $this->url->link('product/category', 'path=' . (int) $settings['main_category_id'][0]);
}
$oct_items[] = [
'name' => $oct_item['title'],
'sort' => $oct_item['sort_order'],
'type' => $oct_item['type'],
'view' => (isset($settings['view']) && $settings['view']) ? $settings['view'] : 0,
'column' => 1,
'target' => (isset($settings['target']) && $settings['target']) ? 'target="_blank"' : '',
'children' => $children ? $children : false,
'oct_pages' => $oct_pages,
'oct_image' => $settings['image'] ? $this->model_tool_image->resize($settings['image'], 20, 20) : false,
'show_image' => (isset($settings['show_image']) && $settings['show_image']) ? $settings['show_image'] : false,
'width' => 20,
'height' => 20,
'subcat_image_width' => isset($settings['width']) ? $settings['width'] : 20,
'subcat_image_height' => isset($settings['height']) ? $settings['height'] : 20,
'href' => $href
];
}
}
return $oct_items;
}
private function getMenuTypeCategory($settings) {
$this->load->model('catalog/category');
$oct_deals_data = $this->config->get('theme_oct_deals_data');
$categories = $oct_pages = [];
if (isset($settings['id']) && !empty($settings['id'])) {
foreach ($settings['id'] as $category_id) {
$result = $this->model_catalog_category->getCategory($category_id);
$children_data = [];
if (isset($oct_deals_data['megamenu']['page']) && !empty($result['page_group_links'])) {
$oct_pages[] = unserialize($result['page_group_links']);
}
if (isset($settings['sub']) && $settings['sub']) {
$results = $this->model_catalog_category->getOCTCategories($category_id, $settings['limit']);
foreach ($results as $child) {
if (isset($oct_deals_data['megamenu']['page']) && !empty($child['page_group_links'])) {
$oct_pages[] = unserialize($child['page_group_links']);
}
$children_data2 = [];
$children = $this->model_catalog_category->getCategories($child['category_id']);
foreach ($children as $ch) {
if ((isset($ch['name']) && !empty($ch['name'])) && (isset($ch['category_id']) && !empty($ch['category_id']))) {
$children_data2[] = [
'name' => $ch['name'],
'oct_pages' => (isset($oct_deals_data['megamenu']['page']) && !empty($ch['page_group_links'])) ? unserialize($ch['page_group_links']) : [],
'href' => $this->url->link('product/category', 'path=' . $ch['category_id'])
];
}
}
if ((isset($child['name']) && !empty($child['name'])) && (isset($child['category_id']) && !empty($child['category_id']))) {
$children_data[] = [
'name' => $child['name'],
'children' => $children_data2,
'oct_pages' => (isset($oct_deals_data['megamenu']['page']) && !empty($child['page_group_links'])) ? unserialize($child['page_group_links']) : [],
'href' => $this->url->link('product/category', 'path=' . $child['category_id'])
];
}
}
}
if ((isset($result['name']) && !empty($result['name'])) && (isset($result['category_id']) && !empty($result['category_id']))) {
$categories[] = [
'name' => $result['name'],
'sort' => $result['sort_order'],
'children' => $children_data,
'oct_pages' => (isset($oct_deals_data['megamenu']['page']) && !empty($result['page_group_links'])) ? unserialize($result['page_group_links']) : [],
'oct_image'=> (isset($settings['show_image']) && $settings['show_image']) ? $this->model_tool_image->resize($result['image'] ? $result['image'] : 'no-thumb.png', $settings['width'], $settings['height']) : false,
'width' => $settings['width'],
'height' => $settings['height'],
'href' => $this->url->link('product/category', 'path=' . $result['category_id'])
];
}
}
}
$sort = array();
foreach ($categories as $key => $row) {
$sort[$key] = $row['sort'];
}
array_multisort($sort, SORT_ASC, $categories);
$categories['pages'] = $oct_pages;
return $categories;
}
private function getMenuTypeManufacturer($settings) {
$this->load->model('catalog/manufacturer');
$manufacturers = [];
if (isset($settings['id']) && !empty($settings['id'])) {
foreach ($settings['id'] as $manufacturer_id) {
$result = $this->model_catalog_manufacturer->getManufacturer($manufacturer_id);
if ((isset($result['name']) && !empty($result['name'])) && (isset($result['manufacturer_id']) && !empty($result['manufacturer_id']))) {
$manufacturers[] = [
'name' => $result['name'],
'oct_image'=> (isset($settings['show_image']) && $settings['show_image']) ? $this->model_tool_image->resize($result['image'] ? $result['image'] : 'no-thumb.png', $settings['width'], $settings['height']) : false,
'width' => $settings['width'],
'height' => $settings['height'],
'oct_pages' => [],
'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $result['manufacturer_id'])
];
}
}
}
return $manufacturers;
}
private function getMenuTypeOCT_BlogCategory($settings) {
$this->load->model('octemplates/blog/oct_blogcategory');
$blogs = [];
if (isset($settings['id']) && !empty($settings['id'])) {
foreach ($settings['id'] as $path_id) {
$result = $this->model_octemplates_blog_oct_blogcategory->getBlogCategory($path_id);
$children_data = [];
if (isset($settings['sub']) && $settings['sub']) {
$results = $this->model_octemplates_blog_oct_blogcategory->getBlogCategories($path_id);
foreach ($results as $child) {
if ((isset($child['name']) && !empty($child['name'])) && (isset($child['blogcategory_id']) && !empty($child['blogcategory_id']))) {
$children_data[] = [
'name' => $child['name'],
'href' => $this->url->link('octemplates/blog/oct_blogcategory', 'blog_path=' . $result['blogcategory_id'] . '_' . $child['blogcategory_id'] )
];
}
}
}
if ((isset($result['name']) && !empty($result['name'])) && (isset($result['blogcategory_id']) && !empty($result['blogcategory_id'])) && $result['parent_id'] == 0) {
$blogs[] = [
'name' => $result['name'],
'children' => $children_data,
'oct_image'=> (isset($settings['show_image']) && $settings['show_image']) ? $this->model_tool_image->resize($result['image'] ? $result['image'] : 'no-thumb.png', $settings['width'], $settings['height']) : false,
'width' => $settings['width'],
'height' => $settings['height'],
'oct_pages' => [],
'href' => $this->url->link('octemplates/blog/oct_blogcategory', 'blog_path=' . $result['blogcategory_id'])
];
}
}
}
return $blogs;
}
private function getMenuTypeLink($settings) {
return [];
}
}