Всем привет!
Opencart 2.3.0.2.2
Использую модуль Стена категорий, все работает прекрасно. Но, потребовалось вывести этот модуль в модальное окно. То есть чтобы по нажатию кнопки "Все меню" на весь экран на любой странице открывались бы все категории во всплывающем окне.
Я взял стандартную модальку Bootstrap, и в футер вставил код шаблона модуля. В контроллер футера вставил код контроллера модуля. Но не работает, выдает ошибку:
Notice: Undefined variable: categories
Invalid argument supplied for foreach()
Что я делаю не так? Подскажите пожалуйста)
Код шаблона:
<div class="row" style="opacity: 1; display: block;margin-bottom: 0px;">
<?php foreach ($categories as $category) { ?>
<div class="col-lg-2 col-md-3 col-sm-6 col-xs-12">
<div class="product-thumb transition">
<div class="image"><a href="<?php echo $category['href']; ?>"><img src="<?php echo $category['image']; ?>" alt="<?php echo $category['name']; ?>" title="<?php echo $category['name']; ?>" class="img-responsive" /></a></div>
<div class="caption" style="min-height: 50px">
<h5><a style="text-decoration: none" href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a></h5>
<?php if ($category['children']) { ?>
<?php foreach ($category['children'] as $child) { ?>
<?php if ($child['category_id'] == $child_id) { ?>
<a href="<?php echo $child['href']; ?>"> - <?php echo $child['name']; ?></a><br>
<?php } else { ?>
<a href="<?php echo $child['href']; ?>"> - <?php echo $child['name']; ?></a><br>
<?php } ?>
<?php } ?>
<?php } ?>
</div>
</div>
</div>
<?php } ?>
</div>
Код контроллера:
class ControllerExtensionModuleCategoryWall extends Controller {
public function index() {
$this->load->language('extension/module/category_wall');
$data['heading_title'] = $this->language->get('heading_title');
if (isset($this->request->get['path'])) {
$parts = explode('_', (string) $this->request->get['path']);
} else {
$parts = array();
}
if (isset($parts[0])) {
$data['category_id'] = $parts[0];
} else {
$data['category_id'] = 0;
}
if (isset($parts[1])) {
$data['child_id'] = $parts[1];
} else {
$data['child_id'] = 0;
}
$this->load->model('catalog/category');
$this->load->model('catalog/product');
$data['categories'] = array();
$data['categories'] = array();
$categories = $this->model_catalog_category->getCategories(0);
$this->load->model('tool/image');
foreach ($categories as $category) {
$children_data = array();
if ($category['top']) {
$children = $this->model_catalog_category->getCategories($category['category_id']);
foreach($children as $child) {
$filter_data = array('filter_category_id' => $child['category_id'], 'filter_sub_category' => true);
$children_data[] = array(
'category_id' => $child['category_id'],
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}
if ($category['image']) {
$image = $this->model_tool_image->resize($category['image'], $this->config->get($this->config->get('config_theme') . '_image_category_width'), $this->config->get($this->config->get('config_theme') . '_image_category_height'));
} else {
$image = $this->model_tool_image->resize('placeholder.png', $this->config->get($this->config->get('config_theme') . '_image_category_width'), $this->config->get($this->config->get('config_theme') . '_image_category_height'));
}
$data['categories'][] = array(
'description' => $category['description'],
'name' => $category['name'],
'children' => $children_data,
'image' => $image,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
}
return $this->load->view('extension/module/category_wall', $data);
}
}