0 / 0 / 1
Регистрация: 14.12.2016
Сообщений: 43
1

Добавление картинки в меню построенном циклом foreach

29.04.2017, 02:20. Показов 3704. Ответов 21
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Друзья, я хочу на своем сайте в около каждого пункта меню вывести иконку. Меню выводится с помощью цикла foreach.

Речь идет об этом меню
Добавление картинки в меню построенном циклом foreach


Сайт new.smallpet.ru
Листинг цикла выкладываю:

PHP
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
<?php
 
        $categories = $this->model_catalog_category->getCategories(0);
 
        $data['menu_items'] = array();
 
        if (isset($setting['menu_item'])) {
            $j = 0;
            foreach ($setting['menu_item'] as $menu_item) {
 
 
                if (($j < sizeof($categories) && $setting['menu_item'][$j]['type'] == 0) || $setting['menu_item'][$j]['type'] == 1) {
 
                    if ($j < sizeof($categories) && $menu_item['type'] == 0) {
                        for ($i = $j; $i < sizeof($categories); $i++) {
                            if ($categories[$j]['top']) {
                                break;
                            }
                        }
                        $category = $categories[$j];
                        $name     = $category['name'];
                        $href     = $this->url->link('product/category', 'path=' . $category['category_id']);
                        $liClass  = $menu_item['submenu_type'] == 1 ? 'sf-with-mega' : '';
                        echo(1);
 
                    } else {
                        if (isset($menu_item[$this->config->get('config_language_id')]['title'])) {
                            $name = $menu_item[$this->config->get('config_language_id')]['title'];
                        } else {
                            $name = '';
                        }
 
                        if (!empty($menu_item['link'])) {
                            $href = $menu_item['link'];
 
                        } else {
                            $href = '';
                        }
 
                       ...... 
}
}
0
Лучшие ответы (1)
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
29.04.2017, 02:20
Ответы с готовыми решениями:

Добавление картинки в меню
Hello. Ребят, подскажите пожалуйста, как в меню вставить картинку(.bmp) или иконку (.ico)?

Ошибка с циклом foreach
функция function allusers() { connect_db(); $query = &quot;SELECT `login` FROM `reg_users`&quot;;...

Работа с циклом foreach
Есть два скрипта. Первый вешается на квадраты в сцене и добавляет в один массив сам квадрат, в...

Проблемы с циклом foreach
implement main open core, console class facts i : unsigned := 0. class predicates ...

21
35 / 35 / 11
Регистрация: 17.03.2017
Сообщений: 250
29.04.2017, 12:18 2
и? иконку нужно вывести? вставьте <img src='ваш путь'> в цикле и все))
а что за начальная заставка на сайте) которая два час грузиться?
0
0 / 0 / 1
Регистрация: 14.12.2016
Сообщений: 43
29.04.2017, 15:32  [ТС] 3
а в какую часть цикла вставить? Можете показать?
0
1931 / 1522 / 703
Регистрация: 17.11.2012
Сообщений: 6,585
29.04.2017, 17:54 4
Цитата Сообщение от prukon Посмотреть сообщение
Меню выводится с помощью цикла foreach.
в вашем листинге, меню не выводится а формируется. вывод в шаблоне(.tpl). если я правильно понял это opencart?
покажите листинг дальше. добавить изображение категории в формирующийся массив меню, недостаточно. нужно его еще вывести в шаблоне
1
0 / 0 / 1
Регистрация: 14.12.2016
Сообщений: 43
29.04.2017, 19:35  [ТС] 5
Да - это opencart.

шаблон tpl, который выводит меню. Я в него добавил ссылку на изображение (строка 13) и сейчас у каждой категории появилась одинаковая картинка.

Теперь категорию выглядят во так:


Надо как-то добавить картинки в массив и выводить их у соответствующих категорий:

PHP
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
<?php if ($menu_items) { ?>
<div class="megamenu">
    <h3><?php echo $heading_title;?></h3>
    <ul class="sf-menu">
        <?php foreach ($menu_items as $menu_item) { ?>
        <li <?php echo (!empty($menu_item['mega'])) ? 'class="' . $menu_item['mega'] . '"' : ''; ?>>
            <?php if (empty($menu_item['href'])) { ?>
            <span><?php echo $menu_item['name']; ?></span>
            <?php } else { ?>
            
            
            
            <img src='http://new.smallpet.ru/image/catalog/logo/logo-8.png'>
                
            
            
            <a href="<?php echo $menu_item['href']; ?>"><?php echo $menu_item['name']; ?>  </a>
            <?php } ?>
            <?php if (!empty($menu_item['multi'])) { ?>
            <?php echo $menu_item['multi']; ?>
            <?php } elseif (!empty($menu_item['mega'])) { ?>
            <ul class="sf-mega" <?php echo (!empty($menu_item['background'])) ? 'style="background-image: url(' . $menu_item['background'] . ');"' : '' ?>>
                <?php for ($i = 0; $i < count($menu_item['column']); $i++) {
                    $column = $menu_item['column'][$i];
                    if ($i % $menu_item['per-row'] == 0 && $i != 0) { ?>
                </li><li class="sf-mega_row">
                <?php } elseif ($i == 0) { ?>
                <li class="sf-mega_row">
                    <?php } ?>
                    <div class="sf-mega_section" style="width: <?php echo $column['width']; ?>">
                        <?php if (!empty($column['custom_category'])) { ?>
                        <div class="submenu_category_title">
                            <a href="<?php echo $column['custom_category_href']; ?>">
                                <?php echo $column['custom_category']['name']; ?>
                            </a>
                        </div>
                        <?php } ?>
                        <?php if (!empty($column['module'])) { ?>
                        <div class="megamenu_module">
                            <?php echo $column['module']; ?>
                        </div>
                        <?php } ?>
                        <?php if (!empty($column['subcategory'])) { ?>
                        <div class="submenu_title">
                            <a href="<?php echo $column['subcategory_href'] ?>">
                                <?php echo $column['subcategory']['name']; ?>
                            </a>
                        </div>
                        <?php } ?>
                        <?php if (!empty($column['list'])) { ?>
                        <ul>
                            <?php echo $column['list']; ?>
                        </ul>
                        <?php } ?>
                    </div>
                    <?php if ($i == count($menu_item['column'])) { ?>
                </li>
                <?php } ?>
                <?php } ?>
            </ul>
            <?php } ?>
        </li>
        <?php } ?>
    </ul>
</div>
 
<?php } ?>
0
1931 / 1522 / 703
Регистрация: 17.11.2012
Сообщений: 6,585
29.04.2017, 20:11 6
Цитата Сообщение от prukon Посмотреть сообщение
Надо как-то добавить картинки в массив и выводить их у соответствующих категорий:
Цитата Сообщение от prukon Посмотреть сообщение
PHP
1
2
3
4
5
$category = $categories[$j];
* * * * * * * * * * * * $name * * = $category['name'];
* * * * * * * * * * * * $href * * = $this->url->link('product/category', 'path=' . $category['category_id']);
* * * * * * * * * * * * $liClass *= $menu_item['submenu_type'] == 1 ? 'sf-with-mega' : '';
* * * * * * * * * * * * echo(1);
добавить
PHP
1
$img_category = $category['image'];
далее в контроллере формируется массив $data['menu_items'], добавить в него $img_category, как-то так
PHP
1
$data['menu_imems'][]['image'] = $img_category;
чтобы подсказать более конкретно, я уже писал
Цитата Сообщение от fanatikus Посмотреть сообщение
покажите листинг дальше.
0
0 / 0 / 1
Регистрация: 14.12.2016
Сообщений: 43
29.04.2017, 20:56  [ТС] 7
Добавил то, что вы сказали.

Сейчас контроллер выглядит вот так:
Все верно?
PHP
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
<?php
 
class ControllerExtensionModuleTMMegaMenu extends Controller
{
 
    public function index($setting)
    {
        $this->load->language('extension/module/category');
        $this->load->language('extension/module/tm_megamenu');
 
        $this->document->addScript('catalog/view/theme/' . $this->config->get($this->config->get('config_theme') . '_directory') . '/js/tmmegamenu/superfish.min.js');
        $this->document->addScript('catalog/view/theme/' . $this->config->get($this->config->get('config_theme') . '_directory') . '/js/tmmegamenu/jquery.rd-navbar.min.js');
 
        $data['heading_title'] = $this->language->get('heading_title');
 
        $this->load->model('catalog/category');
        $this->load->model('catalog/product');
        $this->load->model('tool/image');
 
        $categories = $this->model_catalog_category->getCategories(0);
 
        $data['menu_items'] = array();
        if (isset($setting['menu_item'])) {
            $j = 0;
            foreach ($setting['menu_item'] as $menu_item) {
                    
                
                if (($j < sizeof($categories) && $setting['menu_item'][$j]['type'] == 0) || $setting['menu_item'][$j]['type'] == 1) {
 
                    if ($j < sizeof($categories) && $menu_item['type'] == 0) {
                        for ($i = $j; $i < sizeof($categories); $i++) {
                            if ($categories[$j]['top']) {
                                break;
                            }
                        }
                        $category = $categories[$j];
                        $name     = $category['name'];
                        $href     = $this->url->link('product/category', 'path=' . $category['category_id']);
                        $liClass  = $menu_item['submenu_type'] == 1 ? 'sf-with-mega' : '';
                        $img_category = $category['image'];
                        
 
                    } else {
                        if (isset($menu_item[$this->config->get('config_language_id')]['title'])) {
                            $name = $menu_item[$this->config->get('config_language_id')]['title'];
                        } else {
                            $name = '';
                        }
 
                        if (!empty($menu_item['link'])) {
                            $href = $menu_item['link'];
                            echo(1);
                        } else {
                            $href = '';
                        }
 
                        $liClass = $menu_item['submenu_show'] == 1 ? 'sf-with-mega' : '';
                    }
                    if ($j < sizeof($categories) && $menu_item['type'] == 0 && $menu_item['submenu_type'] == 0) {
                        $multilevel = $this->getCatTree($categories[$j]['category_id']) . "\n";
                    } elseif ($j < sizeof($categories)) {
                        $multilevel        = '';
                        $subcategory_count = 0;
                        $subwithsub_count  = 0;
                        $subwithprod_count = 0;
                        $products_count    = 0;
                        $categories_arr    = [];
 
                        if (isset($menu_item['column'])) {
                            $columns = array();
                            for ($i = 0; $i < $menu_item['columns']; $i++) {
                                $subcategory      = array();
                                $list             = '';
                                $module           = '';
                                $category_show    = '';
                                $category_href    = '';
                                $subcategory_href = '';
 
                                if ($menu_item['column'][$i]['content'] != 0 && $menu_item['type'] == 1) {
                                    if ($menu_item['column'][$i]['category_show'] == 1) {
                                        $category_show = $this->model_catalog_category->getCategory($menu_item['column'][$i]['category_id']);
                                        $category_href = $this->url->link('product/category', 'path=' . $category_show['category_id']);
 
                                        $exist = false;
                                        foreach ($categories_arr as $cat) {
                                            if ($cat['id'] == $menu_item['column'][$i]['category_id']) {
                                                $exist = true;
                                                break;
                                            }
                                        }
 
                                        if (!$exist) {
                                            $categories_arr[] = array(
                                                'id'         => $menu_item['column'][$i]['category_id'],
                                                'count_prod' => 0,
                                                'count_sub'  => 0,
                                                );
                                        }
                                    }
                                }
 
                                switch ($menu_item['column'][$i]['content']) {
                                    case 4:
                                    if (isset($menu_item['column'][$i]['category_id']) && $menu_item['type'] == 1) {
                                        $category_id = (int)$menu_item['column'][$i]['category_id'];
                                        foreach ($categories_arr as $key => $value) {
                                            if ($categories_arr[$key]['id'] == $menu_item['column'][$i]['category_id']) {
                                                $glob_key = $key;
                                            }
                                        }
                                    } else {
                                        $category_id = (int)$categories[$j]['category_id'];
                                    }
 
                                    if ($menu_item['type'] == 1 && isset($glob_key)) {
                                        $start = $categories_arr[$glob_key]['count_prod'];
                                    } else {
                                        $start = $products_count;
                                    }
 
 
                                    $filter_data = array(
                                        'filter_category_id'  => $category_id,
                                        'filter_sub_category' => true,
                                        'sort'                => 'p.date_added',
                                        'order'               => 'DESC',
                                        'start'               => $start,
                                        'limit'               => $menu_item['column'][$i]['prod_limit']
                                        );
 
                                    $results = $this->model_catalog_product->getProducts($filter_data);
                                    if (isset($results)) {
                                        foreach ($results as $product_info) {
                                            $list .= "<li>\n<a href=\"" . $this->url->link('product/product', '&product_id=' . $product_info['product_id']) . "\">" . $product_info['name'] . "</a>\n</li>\n";
                                            if ($menu_item['type'] == 1 && isset($glob_key)) {
                                                $categories_arr[$glob_key]['count_prod']++;
                                            } else {
                                                $products_count++;
                                            }
                                        }
                                    }
 
                                    break;
                                    case 3:
                                    if (isset($menu_item['column'][$i]['category_id']) && $menu_item['type'] == 1) {
                                        $subcategories = $this->model_catalog_category->getCategories((int)$menu_item['column'][$i]['category_id']);
                                    } else {
                                        $subcategories = $this->model_catalog_category->getCategories((int)$categories[$j]['category_id']);
                                    }
 
 
                                    if (isset($subcategories[$subwithsub_count])) {
                                        $subcategory_href = $this->url->link('product/category', 'path=' . $subcategories[$subwithsub_count]['category_id']);
                                        $subcategory = $this->model_catalog_category->getCategory((int)$subcategories[$subwithsub_count]['category_id']);
 
                                        $subcategories2 = $this->model_catalog_category->getCategories((int)$subcategories[$subwithsub_count]['category_id']);
 
                                        if (isset($subcategories2)) {
                                            for ($l = 0; $l < $menu_item['column'][$i]['limit']; $l++) {
                                                if (isset($subcategories2[$l])) {
                                                    $subcategory_name = $subcategories2[$l]['name'];
                                                    $subcategories2_href = $this->url->link('product/category', 'path=' . $subcategories2[$l]['category_id']);
                                                    $list .= "<li>\n<a href=\"" . $subcategories2_href . "\">" . $subcategory_name . "</a>\n</li>\n";
                                                }
                                            }
                                        }
 
                                        $subwithsub_count++;
                                    }
                                    break;
 
                                    case 2:
                                    if (isset($menu_item['column'][$i]['category_id']) && $menu_item['type'] == 1) {
                                        $subcategories = $this->model_catalog_category->getCategories((int)$menu_item['column'][$i]['category_id']);
                                        foreach ($categories_arr as $key => $value) {
                                            if ($categories_arr[$key]['id'] == $menu_item['column'][$i]['category_id']) {
                                                $glob_key = $key;
                                            }
                                        }
                                    } else {
                                        $subcategories = $this->model_catalog_category->getCategories((int)$categories[$j]['category_id']);
                                    }
 
                                    if ($menu_item['type'] == 1 && isset($glob_key)) {
                                        $num = $categories_arr[$glob_key]['count_sub'];
                                        $categories_arr[$glob_key]['count_sub']++;
                                    } else {
                                        $num = $subwithprod_count;
                                        $subwithprod_count++;
                                    }
 
                                    if (isset($subcategories[$num])) {
                                        $subcategory_href = $this->url->link('product/category', 'path=' . $subcategories[$num]['category_id']);
 
                                        $subcategory = $this->model_catalog_category->getCategory((int)$subcategories[$num]['category_id']);
 
                                        if (!empty($subcategory)) {
                                            $filter_data = array(
                                                'filter_category_id'  => (int)$subcategory['category_id'],
                                                'filter_sub_category' => true,
                                                'sort'                => 'p.date_added',
                                                'order'               => 'DESC',
                                                'start'               => 0,
                                                'limit'               => $menu_item['column'][$i]['prod_limit']
                                                );
 
                                            $results = $this->model_catalog_product->getProducts($filter_data);
                                            if (isset($results)) {
                                                foreach ($results as $product_info) {
                                                    $list .= "<li>\n<a href=\"" . $this->url->link('product/product', '&product_id=' . $product_info['product_id']) . "\">" . $product_info['name'] . "</a>\n</li>\n";
                                                }
                                            }
                                        }
                                    }
                                    break;
 
                                    case 1:
                                    if (isset($menu_item['column'][$i]['category_id']) && $menu_item['type'] == 1) {
                                        $subcategories = $this->model_catalog_category->getCategories((int)$menu_item['column'][$i]['category_id']);
                                    } else {
                                        $subcategories = $this->model_catalog_category->getCategories((int)$categories[$j]['category_id']);
                                    }
 
                                    if (isset($subcategories)) {
                                        $tmp = $menu_item['column'][$i]['limit'] + $subcategory_count;
                                        for ($l = $subcategory_count; $l < $tmp; $l++) {
                                            if (isset($subcategories[$l])) {
                                                $subcategory_name = $subcategories[$l]['name'];
                                                $subcategories_href = $this->url->link('product/category', 'path=' . $subcategories[$l]['category_id']);
                                                $list .= "<li>\n<a href=\"" . $subcategories_href . "\">" . $subcategory_name . "</a>\n</li>\n";
                                            }
                                            $subcategory_count++;
                                        }
                                    }
                                    break;
 
                                    case 0:
                                    if (isset($menu_item['column'][$i]['module_id'])) {
                                        $code = $this->model_extension_module->getModuleCode($menu_item['column'][$i]['module_id']);
                                        $setting_info = $this->model_extension_module->getModule($menu_item['column'][$i]['module_id']);
                                        if ($setting_info && $setting_info['status']) {
                                            $module .= $this->load->controller('extension/module/' . $code, $setting_info);
                                        }
                                    }
                                    break;
                                }
 
                                $columns[] = array(
                                    'width'                => $menu_item['column'][$i]['width'],
                                    'custom_category'      => $category_show,
                                    'custom_category_href' => $category_href,
                                    'module'               => $module,
                                    'list'                 => $list,
                                    'subcategory'          => $subcategory,
                                    'subcategory_href'     => $subcategory_href,
                                    );
                            }
                        }
                    }
 
                    if (!isset($columns)) {
                        $columns = array();
                    }
 
                    if (is_file(DIR_IMAGE . $menu_item['image'])) {
                        $image = $this->model_tool_image->resize($menu_item['image'], $menu_item['image_width'], $menu_item['image_height']);
                    } else {
                        $image = '';
                    }
 
                    $data['menu_items'][] = array(
                        'href'       => $href,
                        'name'       => $name,
                        'mega'       => $liClass,
                        'multi'      => $multilevel,
                        'per-row'    => $menu_item['columns-per-row'],
                        'column'     => $columns,
                        'background' => $image
                        );
 
                    if ($menu_item['type'] == 0) {
                        $j++;
                    }
                }
            }
        }
 
        return $this->load->view('extension/module/tm_megamenu', $data);
    }
 
    function getCatTree($category_id = 0)
    {
        if (isset($this->request->get['path'])) {
            $parts = explode('_', (string)$this->request->get['path']);
        } else {
            $parts = array();
        }
 
        $this->load->model('catalog/category');
        $category_data = "";
 
        $categories = $this->model_catalog_category->getCategories((int)$category_id);
 
        foreach ($categories as $category) {
            $name = $category['name'];
            $href = $this->url->link('product/category', 'path=' . $category['category_id']);
            $class = in_array($category['category_id'], $parts) ? " class=\"active\"" : "";
            $parent = $this->getCatTree($category['category_id']);
            if ($parent) {
                $class = $class ? " class=\"active\"" : " class=\"parent\"";
            }
            $category_data .= "<li>\n<a href=\"" . $href . "\"" . $class . ">" . $name . "</a>" . $parent . "\n</li>\n";
 
        }
 
        return strlen($category_data) ? "<ul class=\"simple_menu\">\n" . $category_data . "\n</ul>\n" : "";
    }
}
0
0 / 0 / 1
Регистрация: 14.12.2016
Сообщений: 43
29.04.2017, 20:59  [ТС] 8
Картинки в категории пока не заданы отображаются вот так
Уточните каким образом добавить картинки сейчас в этот массив?
Шаблон выглядит вот так:

PHP
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
<?php if ($menu_items) { ?>
<div class="megamenu">
    <h3><?php echo $heading_title;?></h3>
    <ul class="sf-menu">
        <?php foreach ($menu_items as $menu_item) { ?>
        <li <?php echo (!empty($menu_item['mega'])) ? 'class="' . $menu_item['mega'] . '"' : ''; ?>>
            <?php if (empty($menu_item['href'])) { ?>
            <span><?php echo $menu_item['name']; ?></span>
            <?php } else { ?>
            
            
            
            $data['menu_imems'][]['image'] = $img_category;
                
            
            
            <a href="<?php echo $menu_item['href']; ?>"><?php echo $menu_item['name']; ?>  </a>
            <?php } ?>
            <?php if (!empty($menu_item['multi'])) { ?>
            <?php echo $menu_item['multi']; ?>
            <?php } elseif (!empty($menu_item['mega'])) { ?>
            <ul class="sf-mega" <?php echo (!empty($menu_item['background'])) ? 'style="background-image: url(' . $menu_item['background'] . ');"' : '' ?>>
                <?php for ($i = 0; $i < count($menu_item['column']); $i++) {
                    $column = $menu_item['column'][$i];
                    if ($i % $menu_item['per-row'] == 0 && $i != 0) { ?>
                </li><li class="sf-mega_row">
                <?php } elseif ($i == 0) { ?>
                <li class="sf-mega_row">
                    <?php } ?>
                    <div class="sf-mega_section" style="width: <?php echo $column['width']; ?>">
                        <?php if (!empty($column['custom_category'])) { ?>
                        <div class="submenu_category_title">
                            <a href="<?php echo $column['custom_category_href']; ?>">
                                <?php echo $column['custom_category']['name']; ?>
                            </a>
                        </div>
                        <?php } ?>
                        <?php if (!empty($column['module'])) { ?>
                        <div class="megamenu_module">
                            <?php echo $column['module']; ?>
                        </div>
                        <?php } ?>
                        <?php if (!empty($column['subcategory'])) { ?>
                        <div class="submenu_title">
                            <a href="<?php echo $column['subcategory_href'] ?>">
                                <?php echo $column['subcategory']['name']; ?>
                            </a>
                        </div>
                        <?php } ?>
                        <?php if (!empty($column['list'])) { ?>
                        <ul>
                            <?php echo $column['list']; ?>
                        </ul>
                        <?php } ?>
                    </div>
                    <?php if ($i == count($menu_item['column'])) { ?>
                </li>
                <?php } ?>
                <?php } ?>
            </ul>
            <?php } ?>
        </li>
        <?php } ?>
    </ul>
</div>
<script>
    ;(function ($) {
        $(window).load(function () {
            var o = $('.sf-menu');
            o.superfish();
            o.find('li a').each(function () {
                if ($(location).attr('href').indexOf($(this).attr('href')) >= 0){
                    $(this).addClass('active');
                    return;
                }
            })
            if (o.parents('aside').length){
                var width = $('.container').outerWidth() - $('aside').outerWidth();
                o.find('.sf-mega').each(function () {
                    $(this).width(width);
                })
            }
        });
    })(jQuery);
</script>
<?php } ?>
0
1931 / 1522 / 703
Регистрация: 17.11.2012
Сообщений: 6,585
29.04.2017, 22:41 9
Цитата Сообщение от prukon Посмотреть сообщение
PHP
1
2
3
4
5
6
7
8
$data['menu_items'][] = array(
* * * * * * * * * * * * 'href' * * * => $href,
* * * * * * * * * * * * 'name' * * * => $name,
* * * * * * * * * * * * 'mega' * * * => $liClass,
* * * * * * * * * * * * 'multi' * * *=> $multilevel,
* * * * * * * * * * * * 'per-row' * *=> $menu_item['columns-per-row'],
* * * * * * * * * * * * 'column' * * => $columns,
* * * * * * * * * * * * 'background' => $image
* * * * * * * * * * * * );
добавить
'image'=>$img_category
в шаблоне вместо
PHP
1
$data['menu_imems'][]['image'] = $img_category;
это
PHP
1
<?php echo $menu_item['image']; ?>
0
0 / 0 / 1
Регистрация: 14.12.2016
Сообщений: 43
29.04.2017, 22:49  [ТС] 10
Отлично, изменения я внес. Подскажите пожалуйста, а как теперь сами картинки (куда ссылки вставлять) добавить для пунктов меню?
0
1931 / 1522 / 703
Регистрация: 17.11.2012
Сообщений: 6,585
29.04.2017, 23:13 11
я там поспешил. нужно немного по другому.
в контроллере вместо
PHP
1
$img_category = $category['image'];
это
PHP
1
$img_category =  $this->model_tool_image->resize($category['image'],'ширина изображения','высота изображения');
а в шаблоне
PHP/HTML
1
<img src="<?php echo $menu_item['image']; ?>">
0
0 / 0 / 1
Регистрация: 14.12.2016
Сообщений: 43
29.04.2017, 23:19  [ТС] 12
Отлично.
Правки все внес согласно вашей инструкции.
Уточните, каким образом теперь добавить сами фотографии?

Контроллер:

PHP
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
<?php
 
class ControllerExtensionModuleTMMegaMenu extends Controller
{
 
    public function index($setting)
    {
        $this->load->language('extension/module/category');
        $this->load->language('extension/module/tm_megamenu');
 
        $this->document->addScript('catalog/view/theme/' . $this->config->get($this->config->get('config_theme') . '_directory') . '/js/tmmegamenu/superfish.min.js');
        $this->document->addScript('catalog/view/theme/' . $this->config->get($this->config->get('config_theme') . '_directory') . '/js/tmmegamenu/jquery.rd-navbar.min.js');
 
        $data['heading_title'] = $this->language->get('heading_title');
 
        $this->load->model('catalog/category');
        $this->load->model('catalog/product');
        $this->load->model('tool/image');
 
        $categories = $this->model_catalog_category->getCategories(0);
 
        $data['menu_items'] = array();
        if (isset($setting['menu_item'])) {
            $j = 0;
            foreach ($setting['menu_item'] as $menu_item) {
                    
                
                if (($j < sizeof($categories) && $setting['menu_item'][$j]['type'] == 0) || $setting['menu_item'][$j]['type'] == 1) {
 
                    if ($j < sizeof($categories) && $menu_item['type'] == 0) {
                        for ($i = $j; $i < sizeof($categories); $i++) {
                            if ($categories[$j]['top']) {
                                break;
                            }
                        }
                        $category = $categories[$j];
                        $name     = $category['name'];
                        $href     = $this->url->link('product/category', 'path=' . $category['category_id']);
                        $liClass  = $menu_item['submenu_type'] == 1 ? 'sf-with-mega' : '';
                        
                        $img_category =  $this->model_tool_image->resize($category['image'],'200px',' 200px');
                        
 
                    } else {
                        if (isset($menu_item[$this->config->get('config_language_id')]['title'])) {
                            $name = $menu_item[$this->config->get('config_language_id')]['title'];
                        } else {
                            $name = '';
                        }
 
                        if (!empty($menu_item['link'])) {
                            $href = $menu_item['link'];
                            echo(1);
                        } else {
                            $href = '';
                        }
 
                        $liClass = $menu_item['submenu_show'] == 1 ? 'sf-with-mega' : '';
                    }
                    if ($j < sizeof($categories) && $menu_item['type'] == 0 && $menu_item['submenu_type'] == 0) {
                        $multilevel = $this->getCatTree($categories[$j]['category_id']) . "\n";
                    } elseif ($j < sizeof($categories)) {
                        $multilevel        = '';
                        $subcategory_count = 0;
                        $subwithsub_count  = 0;
                        $subwithprod_count = 0;
                        $products_count    = 0;
                        $categories_arr    = [];
 
                        if (isset($menu_item['column'])) {
                            $columns = array();
                            for ($i = 0; $i < $menu_item['columns']; $i++) {
                                $subcategory      = array();
                                $list             = '';
                                $module           = '';
                                $category_show    = '';
                                $category_href    = '';
                                $subcategory_href = '';
 
                                if ($menu_item['column'][$i]['content'] != 0 && $menu_item['type'] == 1) {
                                    if ($menu_item['column'][$i]['category_show'] == 1) {
                                        $category_show = $this->model_catalog_category->getCategory($menu_item['column'][$i]['category_id']);
                                        $category_href = $this->url->link('product/category', 'path=' . $category_show['category_id']);
 
                                        $exist = false;
                                        foreach ($categories_arr as $cat) {
                                            if ($cat['id'] == $menu_item['column'][$i]['category_id']) {
                                                $exist = true;
                                                break;
                                            }
                                        }
 
                                        if (!$exist) {
                                            $categories_arr[] = array(
                                                'id'         => $menu_item['column'][$i]['category_id'],
                                                'count_prod' => 0,
                                                'count_sub'  => 0,
                                                );
                                        }
                                    }
                                }
 
                                switch ($menu_item['column'][$i]['content']) {
                                    case 4:
                                    if (isset($menu_item['column'][$i]['category_id']) && $menu_item['type'] == 1) {
                                        $category_id = (int)$menu_item['column'][$i]['category_id'];
                                        foreach ($categories_arr as $key => $value) {
                                            if ($categories_arr[$key]['id'] == $menu_item['column'][$i]['category_id']) {
                                                $glob_key = $key;
                                            }
                                        }
                                    } else {
                                        $category_id = (int)$categories[$j]['category_id'];
                                    }
 
                                    if ($menu_item['type'] == 1 && isset($glob_key)) {
                                        $start = $categories_arr[$glob_key]['count_prod'];
                                    } else {
                                        $start = $products_count;
                                    }
 
 
                                    $filter_data = array(
                                        'filter_category_id'  => $category_id,
                                        'filter_sub_category' => true,
                                        'sort'                => 'p.date_added',
                                        'order'               => 'DESC',
                                        'start'               => $start,
                                        'limit'               => $menu_item['column'][$i]['prod_limit']
                                        );
 
                                    $results = $this->model_catalog_product->getProducts($filter_data);
                                    if (isset($results)) {
                                        foreach ($results as $product_info) {
                                            $list .= "<li>\n<a href=\"" . $this->url->link('product/product', '&product_id=' . $product_info['product_id']) . "\">" . $product_info['name'] . "</a>\n</li>\n";
                                            if ($menu_item['type'] == 1 && isset($glob_key)) {
                                                $categories_arr[$glob_key]['count_prod']++;
                                            } else {
                                                $products_count++;
                                            }
                                        }
                                    }
 
                                    break;
                                    case 3:
                                    if (isset($menu_item['column'][$i]['category_id']) && $menu_item['type'] == 1) {
                                        $subcategories = $this->model_catalog_category->getCategories((int)$menu_item['column'][$i]['category_id']);
                                    } else {
                                        $subcategories = $this->model_catalog_category->getCategories((int)$categories[$j]['category_id']);
                                    }
 
 
                                    if (isset($subcategories[$subwithsub_count])) {
                                        $subcategory_href = $this->url->link('product/category', 'path=' . $subcategories[$subwithsub_count]['category_id']);
                                        $subcategory = $this->model_catalog_category->getCategory((int)$subcategories[$subwithsub_count]['category_id']);
 
                                        $subcategories2 = $this->model_catalog_category->getCategories((int)$subcategories[$subwithsub_count]['category_id']);
 
                                        if (isset($subcategories2)) {
                                            for ($l = 0; $l < $menu_item['column'][$i]['limit']; $l++) {
                                                if (isset($subcategories2[$l])) {
                                                    $subcategory_name = $subcategories2[$l]['name'];
                                                    $subcategories2_href = $this->url->link('product/category', 'path=' . $subcategories2[$l]['category_id']);
                                                    $list .= "<li>\n<a href=\"" . $subcategories2_href . "\">" . $subcategory_name . "</a>\n</li>\n";
                                                }
                                            }
                                        }
 
                                        $subwithsub_count++;
                                    }
                                    break;
 
                                    case 2:
                                    if (isset($menu_item['column'][$i]['category_id']) && $menu_item['type'] == 1) {
                                        $subcategories = $this->model_catalog_category->getCategories((int)$menu_item['column'][$i]['category_id']);
                                        foreach ($categories_arr as $key => $value) {
                                            if ($categories_arr[$key]['id'] == $menu_item['column'][$i]['category_id']) {
                                                $glob_key = $key;
                                            }
                                        }
                                    } else {
                                        $subcategories = $this->model_catalog_category->getCategories((int)$categories[$j]['category_id']);
                                    }
 
                                    if ($menu_item['type'] == 1 && isset($glob_key)) {
                                        $num = $categories_arr[$glob_key]['count_sub'];
                                        $categories_arr[$glob_key]['count_sub']++;
                                    } else {
                                        $num = $subwithprod_count;
                                        $subwithprod_count++;
                                    }
 
                                    if (isset($subcategories[$num])) {
                                        $subcategory_href = $this->url->link('product/category', 'path=' . $subcategories[$num]['category_id']);
 
                                        $subcategory = $this->model_catalog_category->getCategory((int)$subcategories[$num]['category_id']);
 
                                        if (!empty($subcategory)) {
                                            $filter_data = array(
                                                'filter_category_id'  => (int)$subcategory['category_id'],
                                                'filter_sub_category' => true,
                                                'sort'                => 'p.date_added',
                                                'order'               => 'DESC',
                                                'start'               => 0,
                                                'limit'               => $menu_item['column'][$i]['prod_limit']
                                                );
 
                                            $results = $this->model_catalog_product->getProducts($filter_data);
                                            if (isset($results)) {
                                                foreach ($results as $product_info) {
                                                    $list .= "<li>\n<a href=\"" . $this->url->link('product/product', '&product_id=' . $product_info['product_id']) . "\">" . $product_info['name'] . "</a>\n</li>\n";
                                                }
                                            }
                                        }
                                    }
                                    break;
 
                                    case 1:
                                    if (isset($menu_item['column'][$i]['category_id']) && $menu_item['type'] == 1) {
                                        $subcategories = $this->model_catalog_category->getCategories((int)$menu_item['column'][$i]['category_id']);
                                    } else {
                                        $subcategories = $this->model_catalog_category->getCategories((int)$categories[$j]['category_id']);
                                    }
 
                                    if (isset($subcategories)) {
                                        $tmp = $menu_item['column'][$i]['limit'] + $subcategory_count;
                                        for ($l = $subcategory_count; $l < $tmp; $l++) {
                                            if (isset($subcategories[$l])) {
                                                $subcategory_name = $subcategories[$l]['name'];
                                                $subcategories_href = $this->url->link('product/category', 'path=' . $subcategories[$l]['category_id']);
                                                $list .= "<li>\n<a href=\"" . $subcategories_href . "\">" . $subcategory_name . "</a>\n</li>\n";
                                            }
                                            $subcategory_count++;
                                        }
                                    }
                                    break;
 
                                    case 0:
                                    if (isset($menu_item['column'][$i]['module_id'])) {
                                        $code = $this->model_extension_module->getModuleCode($menu_item['column'][$i]['module_id']);
                                        $setting_info = $this->model_extension_module->getModule($menu_item['column'][$i]['module_id']);
                                        if ($setting_info && $setting_info['status']) {
                                            $module .= $this->load->controller('extension/module/' . $code, $setting_info);
                                        }
                                    }
                                    break;
                                }
 
                                $columns[] = array(
                                    'width'                => $menu_item['column'][$i]['width'],
                                    'custom_category'      => $category_show,
                                    'custom_category_href' => $category_href,
                                    'module'               => $module,
                                    'list'                 => $list,
                                    'subcategory'          => $subcategory,
                                    'subcategory_href'     => $subcategory_href,
                                    );
                            }
                        }
                    }
 
                    if (!isset($columns)) {
                        $columns = array();
                    }
 
                    if (is_file(DIR_IMAGE . $menu_item['image'])) {
                        $image = $this->model_tool_image->resize($menu_item['image'], $menu_item['image_width'], $menu_item['image_height']);
                    } else {
                        $image = '';
                    }
 
                    $data['menu_items'][] = array(
                        'href'       => $href,
                        'name'       => $name,
                        'mega'       => $liClass,
                        'multi'      => $multilevel,
                        'per-row'    => $menu_item['columns-per-row'],
                        'column'     => $columns,
                        'background' => $image,
                        'image'      => $img_category
                        );
 
                    if ($menu_item['type'] == 0) {
                        $j++;
                    }
                }
            }
        }
 
        return $this->load->view('extension/module/tm_megamenu', $data);
    }
 
    function getCatTree($category_id = 0)
    {
        if (isset($this->request->get['path'])) {
            $parts = explode('_', (string)$this->request->get['path']);
        } else {
            $parts = array();
        }
 
        $this->load->model('catalog/category');
        $category_data = "";
 
        $categories = $this->model_catalog_category->getCategories((int)$category_id);
 
        foreach ($categories as $category) {
            $name = $category['name'];
            $href = $this->url->link('product/category', 'path=' . $category['category_id']);
            $class = in_array($category['category_id'], $parts) ? " class=\"active\"" : "";
            $parent = $this->getCatTree($category['category_id']);
            if ($parent) {
                $class = $class ? " class=\"active\"" : " class=\"parent\"";
            }
            $category_data .= "<li>\n<a href=\"" . $href . "\"" . $class . ">" . $name . "</a>" . $parent . "\n</li>\n";
 
        }
 
        return strlen($category_data) ? "<ul class=\"simple_menu\">\n" . $category_data . "\n</ul>\n" : "";
    }
}
0
1931 / 1522 / 703
Регистрация: 17.11.2012
Сообщений: 6,585
29.04.2017, 23:38 13
Цитата Сообщение от prukon Посмотреть сообщение
Уточните, каким образом теперь добавить сами фотографии?
какие фотографии? а что мы делаем по вашему здесь
PHP
1
 $img_category =  $this->model_tool_image->resize($category['image'],'200px',' 200px');
ресайзим фото категории и кидаем ссылку на него в переменную
далее
Цитата Сообщение от prukon Посмотреть сообщение
'image' * * *=> $img_category
добавляем ссылку на изображение в массив меню
и наконец
Цитата Сообщение от fanatikus Посмотреть сообщение
<img src="<?php echo $menu_item['image']; ?>">
выводим в шаблоне.
куда вы хотите добавить фотографии я не понимаю. если в базу, то изображения категорий добавляются при создании категории.
0
0 / 0 / 1
Регистрация: 14.12.2016
Сообщений: 43
29.04.2017, 23:56  [ТС] 14
На сайте 8 категорий. Значит должно быть 8 ссылок на изображения, я не понимаю куда их вставлять.

Вставил как вы описали выше одно изображение и ничего к сожалению не вышло.

PHP
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
<?php
 
class ControllerExtensionModuleTMMegaMenu extends Controller
{
 
    public function index($setting)
    {
        $this->load->language('extension/module/category');
        $this->load->language('extension/module/tm_megamenu');
 
        $this->document->addScript('catalog/view/theme/' . $this->config->get($this->config->get('config_theme') . '_directory') . '/js/tmmegamenu/superfish.min.js');
        $this->document->addScript('catalog/view/theme/' . $this->config->get($this->config->get('config_theme') . '_directory') . '/js/tmmegamenu/jquery.rd-navbar.min.js');
 
        $data['heading_title'] = $this->language->get('heading_title');
 
        $this->load->model('catalog/category');
        $this->load->model('catalog/product');
        $this->load->model('tool/image');
 
        $categories = $this->model_catalog_category->getCategories(0);
 
        $data['menu_items'] = array();
        if (isset($setting['menu_item'])) {
            $j = 0;
            foreach ($setting['menu_item'] as $menu_item) {
                    
                
                if (($j < sizeof($categories) && $setting['menu_item'][$j]['type'] == 0) || $setting['menu_item'][$j]['type'] == 1) {
 
                    if ($j < sizeof($categories) && $menu_item['type'] == 0) {
                        for ($i = $j; $i < sizeof($categories); $i++) {
                            if ($categories[$j]['top']) {
                                break;
                            }
                        }
                        $category = $categories[$j];
                        $name     = $category['name'];
                        $href     = $this->url->link('product/category', 'path=' . $category['category_id']);
                        $liClass  = $menu_item['submenu_type'] == 1 ? 'sf-with-mega' : '';
                        
                        $img_category =  $this->model_tool_image->resize($category['http://new.smallpet.ru/image/catalog/logo/logo-8.png'],'200px',' 200px');
                        
 
                    } else {
                        if (isset($menu_item[$this->config->get('config_language_id')]['title'])) {
                            $name = $menu_item[$this->config->get('config_language_id')]['title'];
                        } else {
                            $name = '';
                        }
 
                        if (!empty($menu_item['link'])) {
                            $href = $menu_item['link'];
                            echo(1);
                        } else {
                            $href = '';
                        }
 
                        $liClass = $menu_item['submenu_show'] == 1 ? 'sf-with-mega' : '';
                    }
                    if ($j < sizeof($categories) && $menu_item['type'] == 0 && $menu_item['submenu_type'] == 0) {
                        $multilevel = $this->getCatTree($categories[$j]['category_id']) . "\n";
                    } elseif ($j < sizeof($categories)) {
                        $multilevel        = '';
                        $subcategory_count = 0;
                        $subwithsub_count  = 0;
                        $subwithprod_count = 0;
                        $products_count    = 0;
                        $categories_arr    = [];
 
                        if (isset($menu_item['column'])) {
                            $columns = array();
                            for ($i = 0; $i < $menu_item['columns']; $i++) {
                                $subcategory      = array();
                                $list             = '';
                                $module           = '';
                                $category_show    = '';
                                $category_href    = '';
                                $subcategory_href = '';
 
                                if ($menu_item['column'][$i]['content'] != 0 && $menu_item['type'] == 1) {
                                    if ($menu_item['column'][$i]['category_show'] == 1) {
                                        $category_show = $this->model_catalog_category->getCategory($menu_item['column'][$i]['category_id']);
                                        $category_href = $this->url->link('product/category', 'path=' . $category_show['category_id']);
 
                                        $exist = false;
                                        foreach ($categories_arr as $cat) {
                                            if ($cat['id'] == $menu_item['column'][$i]['category_id']) {
                                                $exist = true;
                                                break;
                                            }
                                        }
 
                                        if (!$exist) {
                                            $categories_arr[] = array(
                                                'id'         => $menu_item['column'][$i]['category_id'],
                                                'count_prod' => 0,
                                                'count_sub'  => 0,
                                                );
                                        }
                                    }
                                }
 
                                switch ($menu_item['column'][$i]['content']) {
                                    case 4:
                                    if (isset($menu_item['column'][$i]['category_id']) && $menu_item['type'] == 1) {
                                        $category_id = (int)$menu_item['column'][$i]['category_id'];
                                        foreach ($categories_arr as $key => $value) {
                                            if ($categories_arr[$key]['id'] == $menu_item['column'][$i]['category_id']) {
                                                $glob_key = $key;
                                            }
                                        }
                                    } else {
                                        $category_id = (int)$categories[$j]['category_id'];
                                    }
 
                                    if ($menu_item['type'] == 1 && isset($glob_key)) {
                                        $start = $categories_arr[$glob_key]['count_prod'];
                                    } else {
                                        $start = $products_count;
                                    }
 
 
                                    $filter_data = array(
                                        'filter_category_id'  => $category_id,
                                        'filter_sub_category' => true,
                                        'sort'                => 'p.date_added',
                                        'order'               => 'DESC',
                                        'start'               => $start,
                                        'limit'               => $menu_item['column'][$i]['prod_limit']
                                        );
 
                                    $results = $this->model_catalog_product->getProducts($filter_data);
                                    if (isset($results)) {
                                        foreach ($results as $product_info) {
                                            $list .= "<li>\n<a href=\"" . $this->url->link('product/product', '&product_id=' . $product_info['product_id']) . "\">" . $product_info['name'] . "</a>\n</li>\n";
                                            if ($menu_item['type'] == 1 && isset($glob_key)) {
                                                $categories_arr[$glob_key]['count_prod']++;
                                            } else {
                                                $products_count++;
                                            }
                                        }
                                    }
 
                                    break;
                                    case 3:
                                    if (isset($menu_item['column'][$i]['category_id']) && $menu_item['type'] == 1) {
                                        $subcategories = $this->model_catalog_category->getCategories((int)$menu_item['column'][$i]['category_id']);
                                    } else {
                                        $subcategories = $this->model_catalog_category->getCategories((int)$categories[$j]['category_id']);
                                    }
 
 
                                    if (isset($subcategories[$subwithsub_count])) {
                                        $subcategory_href = $this->url->link('product/category', 'path=' . $subcategories[$subwithsub_count]['category_id']);
                                        $subcategory = $this->model_catalog_category->getCategory((int)$subcategories[$subwithsub_count]['category_id']);
 
                                        $subcategories2 = $this->model_catalog_category->getCategories((int)$subcategories[$subwithsub_count]['category_id']);
 
                                        if (isset($subcategories2)) {
                                            for ($l = 0; $l < $menu_item['column'][$i]['limit']; $l++) {
                                                if (isset($subcategories2[$l])) {
                                                    $subcategory_name = $subcategories2[$l]['name'];
                                                    $subcategories2_href = $this->url->link('product/category', 'path=' . $subcategories2[$l]['category_id']);
                                                    $list .= "<li>\n<a href=\"" . $subcategories2_href . "\">" . $subcategory_name . "</a>\n</li>\n";
                                                }
                                            }
                                        }
 
                                        $subwithsub_count++;
                                    }
                                    break;
 
                                    case 2:
                                    if (isset($menu_item['column'][$i]['category_id']) && $menu_item['type'] == 1) {
                                        $subcategories = $this->model_catalog_category->getCategories((int)$menu_item['column'][$i]['category_id']);
                                        foreach ($categories_arr as $key => $value) {
                                            if ($categories_arr[$key]['id'] == $menu_item['column'][$i]['category_id']) {
                                                $glob_key = $key;
                                            }
                                        }
                                    } else {
                                        $subcategories = $this->model_catalog_category->getCategories((int)$categories[$j]['category_id']);
                                    }
 
                                    if ($menu_item['type'] == 1 && isset($glob_key)) {
                                        $num = $categories_arr[$glob_key]['count_sub'];
                                        $categories_arr[$glob_key]['count_sub']++;
                                    } else {
                                        $num = $subwithprod_count;
                                        $subwithprod_count++;
                                    }
 
                                    if (isset($subcategories[$num])) {
                                        $subcategory_href = $this->url->link('product/category', 'path=' . $subcategories[$num]['category_id']);
 
                                        $subcategory = $this->model_catalog_category->getCategory((int)$subcategories[$num]['category_id']);
 
                                        if (!empty($subcategory)) {
                                            $filter_data = array(
                                                'filter_category_id'  => (int)$subcategory['category_id'],
                                                'filter_sub_category' => true,
                                                'sort'                => 'p.date_added',
                                                'order'               => 'DESC',
                                                'start'               => 0,
                                                'limit'               => $menu_item['column'][$i]['prod_limit']
                                                );
 
                                            $results = $this->model_catalog_product->getProducts($filter_data);
                                            if (isset($results)) {
                                                foreach ($results as $product_info) {
                                                    $list .= "<li>\n<a href=\"" . $this->url->link('product/product', '&product_id=' . $product_info['product_id']) . "\">" . $product_info['name'] . "</a>\n</li>\n";
                                                }
                                            }
                                        }
                                    }
                                    break;
 
                                    case 1:
                                    if (isset($menu_item['column'][$i]['category_id']) && $menu_item['type'] == 1) {
                                        $subcategories = $this->model_catalog_category->getCategories((int)$menu_item['column'][$i]['category_id']);
                                    } else {
                                        $subcategories = $this->model_catalog_category->getCategories((int)$categories[$j]['category_id']);
                                    }
 
                                    if (isset($subcategories)) {
                                        $tmp = $menu_item['column'][$i]['limit'] + $subcategory_count;
                                        for ($l = $subcategory_count; $l < $tmp; $l++) {
                                            if (isset($subcategories[$l])) {
                                                $subcategory_name = $subcategories[$l]['name'];
                                                $subcategories_href = $this->url->link('product/category', 'path=' . $subcategories[$l]['category_id']);
                                                $list .= "<li>\n<a href=\"" . $subcategories_href . "\">" . $subcategory_name . "</a>\n</li>\n";
                                            }
                                            $subcategory_count++;
                                        }
                                    }
                                    break;
 
                                    case 0:
                                    if (isset($menu_item['column'][$i]['module_id'])) {
                                        $code = $this->model_extension_module->getModuleCode($menu_item['column'][$i]['module_id']);
                                        $setting_info = $this->model_extension_module->getModule($menu_item['column'][$i]['module_id']);
                                        if ($setting_info && $setting_info['status']) {
                                            $module .= $this->load->controller('extension/module/' . $code, $setting_info);
                                        }
                                    }
                                    break;
                                }
 
                                $columns[] = array(
                                    'width'                => $menu_item['column'][$i]['width'],
                                    'custom_category'      => $category_show,
                                    'custom_category_href' => $category_href,
                                    'module'               => $module,
                                    'list'                 => $list,
                                    'subcategory'          => $subcategory,
                                    'subcategory_href'     => $subcategory_href,
                                    );
                            }
                        }
                    }
 
                    if (!isset($columns)) {
                        $columns = array();
                    }
 
                    if (is_file(DIR_IMAGE . $menu_item['image'])) {
                        $image = $this->model_tool_image->resize($menu_item['image'], $menu_item['image_width'], $menu_item['image_height']);
                    } else {
                        $image = '';
                    }
 
                    $data['menu_items'][] = array(
                        'href'       => $href,
                        'name'       => $name,
                        'mega'       => $liClass,
                        'multi'      => $multilevel,
                        'per-row'    => $menu_item['columns-per-row'],
                        'column'     => $columns,
                        'background' => $image,
                        'http://new.smallpet.ru/image/catalog/logo/logo-8.png'   => $img_category
                        );
 
                    if ($menu_item['type'] == 0) {
                        $j++;
                    }
                }
            }
        }
 
        return $this->load->view('extension/module/tm_megamenu', $data);
    }
 
    function getCatTree($category_id = 0)
    {
        if (isset($this->request->get['path'])) {
            $parts = explode('_', (string)$this->request->get['path']);
        } else {
            $parts = array();
        }
 
        $this->load->model('catalog/category');
        $category_data = "";
 
        $categories = $this->model_catalog_category->getCategories((int)$category_id);
 
        foreach ($categories as $category) {
            $name = $category['name'];
            $href = $this->url->link('product/category', 'path=' . $category['category_id']);
            $class = in_array($category['category_id'], $parts) ? " class=\"active\"" : "";
            $parent = $this->getCatTree($category['category_id']);
            if ($parent) {
                $class = $class ? " class=\"active\"" : " class=\"parent\"";
            }
            $category_data .= "<li>\n<a href=\"" . $href . "\"" . $class . ">" . $name . "</a>" . $parent . "\n</li>\n";
 
        }
 
        return strlen($category_data) ? "<ul class=\"simple_menu\">\n" . $category_data . "\n</ul>\n" : "";
    }
}

Шаблон:

PHP
1
            <img src="<?php echo $menu_item['http://new.smallpet.ru/image/catalog/logo/logo-8.png]; ?>">
0
1931 / 1522 / 703
Регистрация: 17.11.2012
Сообщений: 6,585
30.04.2017, 00:02 15
Цитата Сообщение от prukon Посмотреть сообщение
$menu_item['http://new.smallpet.ru/image/catalog/logo/logo-8.png];
это что? вы поняли что я вам советовал. или просто тупо вставляли мой код?
0
0 / 0 / 1
Регистрация: 14.12.2016
Сообщений: 43
30.04.2017, 00:59  [ТС] 16
Цитата Сообщение от fanatikus Посмотреть сообщение
ресайзим фото категории и кидаем ссылку на него в переменную
Это я понимаю вот так:

PHP
1
2
3
4
5
6
$img_category  =  $this->model_tool_image->resize($category['https://new.smallpet.ru/image/catalog/logo/logo-1.png'],'200px',' 200px');
                        $img_category2 =  $this->model_tool_image->resize($category['https://new.smallpet.ru/image/catalog/logo/logo-2.png'],'200px',' 200px');
                        $img_category3 =  $this->model_tool_image->resize($category['https://new.smallpet.ru/image/catalog/logo/logo-3.png'],'200px',' 200px');
                        $img_category4 =  $this->model_tool_image->resize($category['https://new.smallpet.ru/image/catalog/logo/logo-4.png'],'200px',' 200px');
                        $img_category5 =  $this->model_tool_image->resize($category['https://new.smallpet.ru/image/catalog/logo/logo-5.png'],'200px',' 200px');
                        $img_category6 =  $this->model_tool_image->resize($category['https://new.smallpet.ru/image/catalog/logo/logo-6.png'],'200px',' 200px');
Цитата Сообщение от fanatikus Посмотреть сообщение
'image' * * *=> $img_category
добавляем ссылку на изображение в массив меню
Это я не понял как делать. Куда мне здесь вставить ссылку?:

PHP
1
'image'      => $img_category
Я это понимаю так:
PHP
1
'http://new.smallpet.ru/image/catalog/logo/logo-8.png'       => $img_category

Цитата Сообщение от fanatikus Посмотреть сообщение
<img src="<?php echo $menu_item['image']; ?>">
выводим в шаблоне.
Поскольку массив должен перебрать все значения 'image' то в шаблоне я оставляю вот так:

PHP
1
<img src= "<?php echo $menu_item['image']; ?>">
Цитата Сообщение от fanatikus Посмотреть сообщение
$menu_item['http://new.smallpet.ru/image/catalog/logo/logo-8.png];
это что? вы поняли что я вам советовал. или просто тупо вставляли мой код?
Я пока не очень хорошо владею синтаксисом, но я учусь. Извините, если показался бездумным.
0
1931 / 1522 / 703
Регистрация: 17.11.2012
Сообщений: 6,585
30.04.2017, 13:30 17
Лучший ответ Сообщение было отмечено prukon как решение

Решение

Цитата Сообщение от prukon Посмотреть сообщение
Это я понимаю вот так:
неправильно понимаете.
тут
PHP
1
$categories = $this->model_catalog_category->getCategories(0);
получаем из базы все категории parent_id у которых равен 0.(родительские)
в массиве $categories уже есть ссылка на изображение категории.
далее создаем массив для пунктов меню( в последствии передается в шаблон)
PHP
1
 $data['menu_items'] = array();
далее, обЪявляем переменные с названием $name и ссылкой $htef категории
PHP
1
2
 $name = $category['name'];
 $href  = $this->url->link('product/category', 'path=' . $category['category_id']);
и переменную, с ссылкой на изображение категории
PHP
1
 $img_category =  $this->model_tool_image->resize($category['image'],'200px',' 200px');
далее добавляем в массив с пунктами меню раннее созданные переменные $name,$href и т.д.
PHP
1
2
3
4
5
6
7
8
9
10
 $data['menu_items'][] = array(
                        'href'       => $href,
                        'name'       => $name,
                        'mega'       => $liClass,
                        'multi'      => $multilevel,
                        'per-row'    => $menu_item['columns-per-row'],
                        'column'     => $columns,
                        'background' => $image,
                        'http://new.smallpet.ru/image/catalog/logo/logo-8.png'   => $img_category
                        );
последняя строка(написанная вами) не правильно.
нужно добавить переменную с ссылкой, которую раннее создали.
PHP
1
'image' => $img_category
в шаблоне, меню будет в массиве $menu_items.
массив $menu_items перебирается в цикле и выводятся пункты меню
PHP/HTML
1
2
3
4
5
6
 <?php foreach ($menu_items as $menu_item) { ?>
        <li <?php echo (!empty($menu_item['mega'])) ? 'class="' . $menu_item['mega'] . '"' : ''; ?>>
            <?php if (empty($menu_item['href'])) { ?>//ссылка, созданная в контроллере $href;
            <span><?php echo $menu_item['name']; ?></span>//название, созданная в контроллере $name
            <?php } else { ?>
                        <img src='<?php echo $menu_item['image'];>//и изображение, созданная в контроллере $img_category
Добавлено через 5 минут
Цитата Сообщение от prukon Посмотреть сообщение
Я пока не очень хорошо владею синтаксисом,
и не только. судя по постам выше, вы не дружите с массивами. может сначала выучить основы, а потом копаться в opencart?
1
0 / 0 / 1
Регистрация: 14.12.2016
Сообщений: 43
30.04.2017, 18:14  [ТС] 18
Вижу, что категории появились. теперь понятно, мы вывели изображения категорий, которые уже были зашиты в opencart. Я думал, что мы сделаем новые ссылки на изображения, потому и спрашивал то в какое место вставлять ссылки на сами изображения.

Сейчас наведу косметику и должно быть все ок.

Спасибо большое!
0
1931 / 1522 / 703
Регистрация: 17.11.2012
Сообщений: 6,585
30.04.2017, 18:53 19
Цитата Сообщение от prukon Посмотреть сообщение
которые уже были зашиты в opencart.
не зашиты. изображения добавляются при создании категории(в админке)
0
0 / 0 / 1
Регистрация: 14.12.2016
Сообщений: 43
30.04.2017, 19:09  [ТС] 20
Столкнулся с проблемой. Выпадающее меню выпадает слишком высоко.
Вы знаете как сделать так, чтобы оно выпадало ниже названия категорий?
0
30.04.2017, 19:09
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
30.04.2017, 19:09
Помогаю со студенческими работами здесь

Запись в файл циклом foreach
&lt;div class=&quot;col-md-2&quot;&gt; &lt;ul class=&quot;dropdown-menu&quot; role=&quot;menu&quot;...

Вывод двумерного массива циклом foreach
Почему двумерный массив через цикл foreach выводится на экран в одну строку? Как сделать через...

Ошибка при работе с циклом foreach
Здравствуйте, мне нужно перебрать массив при помощи цикла foreach, я работаю локально на машине с...

Заполнить массив циклом for и вывести через foreach
Создать целочисленный массив n=6 на m=3 и заполнить при помощи цикла for значениями начиная от 1 до...

Вывести список записей из файла циклом foreach
Здравствуйте, имеется класс: require_once __DIR__.'/shablon.php'; class view { protected...

Можно ли XML парсить циклом foreach не с начала в конец, а с конца в начало?
Друзья всем привет ! возникла такая проблема вот хмл документ &lt;data&gt; &lt;id&gt;1&lt;/id&gt; ...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
20
Ответ Создать тему
Опции темы

КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru