Opencart 3-在产品页面上显示类别(链接到)

时间:2018-09-13 07:25:22

标签: php twig opencart

我需要在产品页面上显示类别链接。

我在forum.opencart.com找到了以下xml:

<?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 :(得分:0)

所以这非常简单..您只需要记住,在OC版本3中,tpl必须是树枝文件。 因此,我在OCMOD中重写了OC 3.0.2版的代码。不要在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安装程序进行安装。之后,别忘了刷新修改...

祝你好运