Opencart 3 - отображать категорию (связанную) на странице товара - PullRequest
0 голосов
/ 13 сентября 2018

Мне нужно отобразить ссылки на категории на странице товара.

Я нашел следующий xml на forum.opencart.com :

<?xml version="1.0" encoding="UTF-8"?>
<modification>
<id>Show Linked Categories on Product page</id>
<version>1</version>
<vqmver>2.5.1</vqmver>
<author>http://www.opencart-extensions.co.uk</author>

<file name="catalog/controller/product/product.php">
<operation error="log">
<search position="after" index="1"><![CDATA[$product_info = $this-    >model_catalog_product->getProduct($product_id);]]></search>
<add><![CDATA[
$data['text_linked_categories'] = $this->language->get('text_linked_categories');
$query_linked_categories = $this->model_catalog_product->getCategories($product_id);
$linked_categories = array();
foreach( $query_linked_categories as $linked_category_data ) {
$linked_category = $this->model_catalog_category->getCategory($linked_category_data['category_id']);
$linked_category_info['id'] = $linked_category_data['category_id'];
$linked_category_info['href'] = $this->url->link('product/category', 'path=' . $linked_category_data['category_id']);
$linked_category_info['name'] = $linked_category['name'];
$linked_categories[] = $linked_category_info;
}
]]></add>
</operation>

<operation error="log">
<search position="before"><![CDATA[$data['manufacturer'] =     $product_info['manufacturer'];]]></search>
<add><![CDATA[
$data['linked_categories'] = $linked_categories;
]]></add>
</operation>
</file>

<file name="catalog/language/*/product/product.php">
<operation error="log">
<search position="before"><![CDATA[$_['text_manufacturer']]]></search>
<add><![CDATA[
$_['text_linked_categories']        = 'Categories:';
]]></add>
</operation>
</file>

<file name="catalog/view/theme/*/template/product/product.tpl">
<operation error="log">
<search position="before"><![CDATA[<li><?php echo $text_model; ?> <?php     echo $model; ?></li>]]></search>
<add><![CDATA[
<?php if( $linked_categories ){ ?>
<li><?php echo $text_linked_categories; ?> 
<?php foreach( $linked_categories as $linked_category ){ ?>
<a href="<?php echo $linked_category['href']; ?>"><?php echo         $linked_category['name']; ?></a>&nbsp;
<?php } ?>
</li>
<?php } ?>
]]></add>
</operation>
</file>
</modification>

Проблема в том, что этот xml vqmod работает только в версии 2.

Как применить это решение к Opencart 3?

1 Ответ

0 голосов
/ 13 сентября 2018

так что все очень просто ... вам просто нужно помнить, что в версии 3 OC вместо tpl должны быть файлы веток.Поэтому я переписал код для OC версии 3.0.2 в OCMOD.Не используйте этот код в VQMOD.

<?xml version="1.0" encoding="UTF-8"?>
<modification>
<id>Show Linked Categories on Product page OC 3.0.x</id>
<code>00002</code>
<name>Show Linked Categories on Product page OC 3.0.x</name>
<version>1.0.0</version>
<vqmver>2.6.2</vqmver>
<author>K.B.</author>

<file path="catalog/controller/product/product.php">
<operation error="log">
<search><![CDATA[$product_info = $this->model_catalog_product->getProduct($product_id);]]></search>
<add position="after" index="1"><![CDATA[
$data['text_linked_categories'] = $this->language->get('text_linked_categories');
$query_linked_categories = $this->model_catalog_product->getCategories($product_id);
$linked_categories = array();
foreach( $query_linked_categories as $linked_category_data ) {
$linked_category = $this->model_catalog_category->getCategory($linked_category_data['category_id']);
$linked_category_info['id'] = $linked_category_data['category_id'];
$linked_category_info['href'] = $this->url->link('product/category', 'path=' . $linked_category_data['category_id']);
$linked_category_info['name'] = $linked_category['name'];
$linked_categories[] = $linked_category_info;
}
]]></add>
</operation>

<operation error="log">
<search><![CDATA[$data['manufacturer'] = $product_info['manufacturer'];]]></search>
<add position="before"><![CDATA[
$data['linked_categories'] = $linked_categories;
]]></add>
</operation>
</file>

<file path="catalog/language/*/product/product.php">
<operation error="log">
<search><![CDATA[$_['text_manufacturer']]]></search>
<add position="before"><![CDATA[
$_['text_linked_categories']        = 'Categories:';
]]></add>
</operation>
</file>

<file path="catalog/view/theme/*/template/product/product.twig">
<operation error="log">
<search><![CDATA[<li>{{ text_model }} {{ model }}</li>]]></search>
<add position="before"><![CDATA[
{% if linked_categories %}
  <li>{{ text_linked_categories }} 
  {% for linked_category in linked_categories %}
            <a href="{{ linked_category.href }}">{{ linked_category.name }}</a>&nbsp;
            {% endfor %}
            </li>
            {% endif %}

]]></add>
</operation>
</file>
</modification>

Создайте новый текстовый файл с именем install.xml и скопируйте в него код выше.заархивируйте его под новым именем categories_to_product.ocmod.zip и используйте установщик OC для его установки.после этого не забывайте обновить модификации ...

Удачи

...