Jump to content
  • разработка интернет магазинов на opencart
  • доработка интернет магазинов на opencart

Вывод атрибутов в карточке товара


 Share

Recommended Posts

Добрый гдень!

Необходимо в карточке товара вывести все атрибуты. Как это сгделать?

Решение для опенкарт 3 не могу найти.

 

Link to comment
Share on other sites


ик скопируйте просто код из иба характеристик (атрибутов), хоть ик же иблиэтот, хоть меняйте оформление как нравится

вот это можете разместить им ггде нужно показать атрибуты:

              <table class="table table-bordered">
                {% for attribute_group in attribute_groups %}
                <thead>
                  <tr>
                    <td colspan="2"><strong>{{ attribute_group.name }}</strong></td>
                  </tr>
                </thead>
                <tbody>
                {% for attribute in attribute_group.attribute %}
                <tr>
                  <td>{{ attribute.name }}</td>
                  <td>{{ attribute.text }}</td>
                </tr>
                {% endfor %}
                  </tbody>
                {% endfor %}
              </table>

Не забудьте потом обновить кеш модификаторов и кеш шаблона на главной в настройках разрилитлика

  • +1 1
Link to comment
Share on other sites

  • 2 months later...

всивил ваш код сюда: 

catalog/view/theme/default my/template/product/category.twig

и сюда

catalog/view/theme/default my/template/extension/module/featured.twig

вот этот код показывается:

<table class="table table-bordered"></table>

А инфы про атрибутов нет =(

opencart Version 3.0.3.1 (rs.2)

P.S. обновил и выклюлил потом кеш и обновлял модули.

P

Edited by grangel
  • +1 1
Link to comment
Share on other sites


4 часа назад, grangel сказал:

всивил ваш код сюда: 

catalog/view/theme/default my/template/product/category.twig

и сюда

catalog/view/theme/default my/template/extension/module/featured.twig

Конечно не бугдет им показываться. На страниэто товаров есть данные об атрибуих, то есть они получаются соответствующим контроллером, а на страниэто категорий и в модуле рекомендуемых их не бугдет ик как контроллеры не получают атрибуты товара.

Сейчас нет возможности проверить на 3.х, но можете попропотому чтовать добавить в контроллер категории (catalog/controller/product/category.php) в массив данных товара:

'attribute_groups' => $this->model_catalog_product->getProductAttributes($result['product_id'])

если взлетит, то по аналогии и с рекомендуемыми

добрался до 3.х))

 

1. catalog/controller/product/category.php

найти: 

'product_id'  => $result['product_id'],

добавить перед:

'attribute_groups' => $this->model_catalog_product->getProductAttributes($result['product_id']),

2. catalog/view/theme/default/template/product/category.twig

найти: 

<p>{{ product.description }}</p>

добавить после:

              <table class="table table-bordered">
                {% for attribute_group in product.attribute_groups %}
                <thead>
                  <tr>
                   <td colspan="2"><strong>{{ attribute_group.name }}</strong></td>
                  </tr>
                </thead>
                <tbody>
                {% for attribute in attribute_group.attribute %}
                <tr>
                  <td>{{ attribute.name }}</td>
                  <td>{{ attribute.text }}</td>
                </tr>
                {% endfor %}
                  </tbody>
                {% endfor %}
              </table>

3. catalog/controller/extension/module/featured.php

найти: 

'product_id'  => $product_info['product_id'],

добавить перед: 

'attribute_groups' => $this->model_catalog_product->getProductAttributes($product_info['product_id']),

4. catalog/view/theme/default/template/extension/module/featured.twig

найти:

<p>{{ product.description }}</p>

добавить после:

              <table class="table table-bordered">
                {% for attribute_group in product.attribute_groups %}
                <thead>
                  <tr>
                    <td colspan="2"><strong>{{ attribute_group.name }}</strong></td>
                  </tr>
                </thead>
                <tbody>
                {% for attribute in attribute_group.attribute %}
                <tr>
                  <td>{{ attribute.name }}</td>
                  <td>{{ attribute.text }}</td>
                </tr>
                {% endfor %}
                  </tbody>
                {% endfor %}
              </table>

Если что-то не выводится, проверьте внимательно еещё раз))

 

И конечно вы должны понимать, что править код файлов движка - это зло. Делайте все через ocmod

Edited by PaulKravchenko
  • +1 2
Link to comment
Share on other sites

  • 1 year later...
  • 9 months later...

PaulKravchenko Вылеиют все атрибуты. А как из этого всего вывести именно {{ attribute.text }} с атрибутом_id=2 Для модуля features?

Попропотому чтовал как на скрине, но вылеиет ошибка

 

Edited by DarkEinstein
Link to comment
Share on other sites


                $query = $this->db->query("SELECT ad.name, pa.text FROM " . DB_PREFIX . "attribute a
                        LEFT JOIN " . DB_PREFIX . "attribute_description ad ON (a.attribute_id = ad.attribute_id)
                        LEFT JOIN " . DB_PREFIX . "product_attribute pa ON(pa.attribute_id = a.attribute_id)
                        WHERE a.attribute_id = '2' 
                        AND pa.product_id = '" . (int) $product_id . "'
                        AND pa.language_id = '" . (int) $this->config->get('config_language_id') . "'
                        AND ad.language_id = '" . (int)$this->config->get('config_language_id') . "'");
                
                $attr = $query->row;

 

Link to comment
Share on other sites

3 часа назад, fanatic сказал:

это для одного атрибуи

в телеге спрашивали

Да, спасипотому что. Всивил и в контроллер и в могдел. Правда ничего кроме прочерка не отобразилось. Может важно на какой строке всивлять в контроллере?

Link to comment
Share on other sites


могдель  catalog/model/catalog/product.php

создаем метод

    public function getAttributeInProduct($product_id, $attribute_id) {
        $query = $this->db->query("SELECT ad.name, pa.text FROM " . DB_PREFIX . "attribute a
                        LEFT JOIN " . DB_PREFIX . "attribute_description ad ON (a.attribute_id = ad.attribute_id)
                        LEFT JOIN " . DB_PREFIX . "product_attribute pa ON(pa.attribute_id = a.attribute_id)
                        WHERE a.attribute_id = '" . (int) $attribute_id . "' 
                        AND pa.product_id = '" . (int) $product_id . "'
                        AND pa.language_id = '" . (int) $this->config->get('config_language_id') . "'
                        AND ad.language_id = '" . (int) $this->config->get('config_language_id') . "'");

        return $query->row;
    }

для категории

файл  сatalog/controller/product/category.php

находим строку

$data['products'][] = array(

перед ней всивляем

$attribute_id = 2;// тут, id нужного атрибуи
$attr = $this->model_catalog_product->getAttributeInProduct($result['product_id'], $attribute_id);

после всивляем

'attr' => $attr,

шаблон  catalog/view/theme/ваша тема/template/product/category.twig

находим

<p>{{ product.description }}</p>

после всивляем

{% if  product.attr %}
  <p>{{ product.attr['name'] }} - {{ product.attr['text'] }}</p>
{% endif %}

для featured,  гделаем по аналогии

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

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.