Oprava breadcrumb v Opencart 2

Pokiaľ odkazujete produkt z hlavnej stránky, neukáže sa Vám celá cesta k nemu, ale iba Domov > Produkt. Problém sa dá riešiť veľmi jednoducho. Nasledujúce riešenie platí pre verzie Opencart 2.0.0.0 až 2.1.0.1

Oprava je nasledovná:


1. Otvor súbor


catalog/controller/product/product.php


2. nájdi kód (priblížne v riadku 17, prvý z troch nájdených)


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


celý vyzerá takto


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['breadcrumbs'][] = array(
                        'text' => $category_info['name'],
                        'href' => $this->url->link('product/category', 'path=' . $path)
                    );
                }
            }

            // Set the last category breadcrumb
            $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['breadcrumbs'][] = array(
                    'text' => $category_info['name'],
                    'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url)
                );
            }
        }


a zaňho pripoj kód


    else {
            if(isset($this->request->get['product_id'])){
                $getCategories = $this->model_catalog_product->getCategories($this->request->get['product_id']);
                $category = array_shift($getCategories);
                $category_info = $this->model_catalog_category->getCategory($category['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['breadcrumbs'][] = array(
                        'text' => $category_info['name'],
                        'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . $url)
                    );
                }
            }
        }


3. V rovnakom súbore nájdi kód (niekde v riadku medzi 160-190)


$this->load->model('catalog/product');


a pred neho pridaj kód


$this->load->model('catalog/category');


4. V administrácii choď do Rozšírenia/Úpravy a daj ich Obnoviť.


Teraz sa ti bude zobrazovať v produktoch celá cesta aj po príchode k ním z úvodnej stránky.


opencart, breadcrumb
Web
8.8.2016

Najnovšie z notesu