Всем доброго времени суток. Вторую неделю пытаюсь сделать вывод всех категорий из магазина. По умолчанию выводиться только 1 и второй уровень. За основу я взял модуль из опенкарта 1.5 (достался бекап от клиента) где был модуль на 4 уровня . Я его подключил по аналогии стандартного модуля category.php Опенкарат 2. С большими усилиями я вывел 3 уровня (4 так и не вывелся) НО дело не в этом. Я не могу получить текущий ИД категории. Ниже я приложил кусок кода. Аналогичный код на стандартном модуле работает, я постарался максимально подобно сделать и свой, но напомню что он с модуля Опенкарта 1.5. Большое спасибо.
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;
}
if (isset($parts[2])) {
$data['child_id2'] = $parts[2];
} else {
$data['child_id2'] = 0;
}
if (isset($parts[3])) {
$data['child_id3'] = $parts[3];
} else {
$data['child_id3'] = 0;
}
$this->load->model('catalog/category');
$this->load->model('catalog/product');
$data['categories'] = array();
$categories = $this->model_catalog_category->getCategories(0);
// 1
foreach ($categories as $category) {
$total = $this->model_catalog_product->getTotalProducts(array('filter_category_id' => $category['category_id']));
$children_data = array();
$children = $this->model_catalog_category->getCategories($category['category_id']);
// 2
foreach ($children as $child) {
$children2_data = array();
$children2 = $this->model_catalog_category->getCategories($child['category_id']);
// 3
foreach ($children2 as $child2) {
$children3_data = array();
$children3 = $this->model_catalog_category->getCategories($child2['category_id']);
// 4
foreach ($children3 as $child3) {
$data3 = array(
'filter_category_id' => $child3['category_id'],
'filter_sub_category' => true
);
$product_total3 = $this->model_catalog_product->getTotalProducts($data3);
$children3_data[] = array(
'category_id' => $child3['category_id'],
'name' => $child3['name'] . ($this->config->get('config_product_count') ? ' (' . $product_total3 . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id']. '_' . $child2['category_id']. '_' . $child3['category_id'])
);
}
$data2 = array(
'filter_category_id' => $child2['category_id'],
'filter_sub_category' => true
);
$product_total2 = $this->model_catalog_product->getTotalProducts($data2);
$children2_data[] = array(
'category_id' => $child2['category_id'],
'name' => $child2['name'] . ($this->config->get('config_product_count') ? ' (' . $product_total2 . ')' : ''),
'children3' => $children3_data,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id']. '_' . $child2['category_id'])
);
}
$data = array(
'filter_category_id' => $child['category_id'],
'filter_sub_category' => true
);
$product_total = $this->model_catalog_product->getTotalProducts($data);
$total += $product_total;
$children_data[] = array(
'category_id' => $child['category_id'],
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $product_total . ')' : ''),
'children2' => $children2_data,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}
$data['categories'][] = array(
'category_id' => $category['category_id'],
'name' => $category['name'] . ($this->config->get('config_product_count') ? ' (' . $total . ')' : ''),
'children' => $children_data,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
гории