0

我需要有关 opencart 2.0 的帮助。顶部菜单。

如果一个主要类别只有一个子类别,那么它应该跳过拼贴页面并直接进入该单个子类别的拇指。

我是 PHP 和 opencart 的新手。我尝试过更改标头控制器和模型目录,但都没有更改。

4

1 回答 1

0

对于任何想要回答这个问题的人,我必须编辑 catalog/controller/common/header.php 和 catalog/model/catalog/category.php

在 category.php 我添加了这个函数

public function getCategoryFirstChildId($category_id) {
    $query = $this->db->query('SELECT category_id FROM '. DB_PREFIX .'category WHERE parent_id = '. (int)$category_id .' ORDER BY category_id ASC LIMIT 1');

    return $query->row['category_id'];
}

在 header.php 中,我将代码更改如下

/* New Code starts  here  */

/*NEW =>*/  $category_total = $this->model_catalog_category->getTotalCategoriesByCategoryId($category['category_id']);

/*NEW =>*/  $first_child_id = $this->model_catalog_category->getCategoryFirstChildId($category['category_id']);

      if($category_total>1)
{

                // Level 1
                $data['categories'][] = array(
                    'name'     => $category['name'],
                    'children' => $children_data,
                    'column'   => $category['column'] ? $category['column'] : 1,
                    'href'     => $this->url->link('product/category', 'path=' . $category['category_id'])
                );
}

else

{
                           // Level 1
                $data['categories'][] = array(
                    'name'     => $category['name'],
                    'children' => $children_data,
                    'column'   => $category['column'] ? $category['column'] : 1,
                    'href'     => $this->url->link('product/category', 'path=' . $category['category_id']. '_' . $first_child_id)
                );

}

/* New Code ends here  */
于 2015-03-24T15:16:43.970 回答