Jump to content

OpenCart 2.3: Вывод названия главной категорий с ссылкой в карточке товара

Recommended Posts

Возможно, кому то пригодится. Сделал вывод главной категории на странице товара OpenCart 2.3.

- В файле catalog/controller/product/product.php


После строки



//вывод главной категории на странице товара//
        $data['catproduct'] = array();

        if (isset($this->request->get['path'])) {
            $path = '';

            $parts = explode('_', (string)$this->request->get['path']);

            $category_id = (int)array_pop($parts);

            foreach ($parts as $path_id) {
                if (!$path) {
                    $path = $path_id;
                } else {
                    $path .= '_' . $path_id;
                $category_info = $this->model_catalog_category->getCategory($path_id);

                if ($category_info) {
                    $data['catproduct'][] = array(
                        'text' => $category_info['name'],
                        'href' => $this->url->link('product/category', 'path=' . $path)
            $category_info = $this->model_catalog_category->getCategory($category_id);

            if ($category_info) {
                $url = '';

                if (isset($this->request->get['sort'])) {
                    $url .= '&sort=' . $this->request->get['sort'];
                if (isset($this->request->get['order'])) {
                    $url .= '&order=' . $this->request->get['order'];
                if (isset($this->request->get['page'])) {
                    $url .= '&page=' . $this->request->get['page'];
                if (isset($this->request->get['limit'])) {
                    $url .= '&limit=' . $this->request->get['limit'];
                $data['catproduct'][] = array(
                    'text' => $category_info['name'],
                    'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url)

 - в файле catalog/view/theme/*/template/product/product.tpl в нужном месте

<span class="desc_title">Категория: </span><?php foreach ($catproduct as $catp) { ?> <a href="<?php echo $catp['href']; ?>"><?php echo $catp['text']; ?></a><?php } ?>

Решение для главной категории взял по аналогии с вывода

Может не совсем верно, но заработало правильно.


Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.


Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.