简体   繁体   中英

Opencart 2.0.0 Top menu with only one subcategory should go to thumbnails of that page

I need help with opencart 2.0. top menu.

If a main category only has one subcategory, then it should skip the collage page and go straight to the thumbs of that single subcategory.

I am new to PHP and opencart. I have tried changing header controller and model catalog, but neither change works.

For anyone who wants answer for this I had to edit catalog/controller/common/header.php and catalog/model/catalog/category.php

In category.php I added this function

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'];
}

and in header.php I made the code change as follows

/* 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  */

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM