【发布时间】:2021-07-06 16:26:15
【问题描述】:
我找到了这段代码,并为 Journal3 主题修改了它,它可以工作。 但现在它显示了所有父子类别。我只想查看产品所在的最新子类别。 有人可以帮我调整代码吗?在这种情况下,我只需要最后一个类别(筹码)
版本:3.0.3.7 日记:3.1.8
<?xml version="1.0" encoding="UTF-8"?>
<modification>
<code>Show_Linked_Categories_on_Product_page</code>
<name>Show Linked Categories on Product page</name>
<version>1.0.0</version>
<author></author>
<link></link>
<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/nl-nl/product/product.php">
<operation error="log">
<search><![CDATA[$_['text_manufacturer']]]></search>
<add position="before"><![CDATA[
$_['text_linked_categories'] = 'Categorie:';
]]></add>
</operation>
</file>
<file path="catalog/view/theme/journal3/template/product/product.twig">
<operation error="log">
<search><![CDATA[<li class="product-sku"><b>{{ j3.settings.get(stylePrefix ~ 'ProductSKUText') }}:</b> <span> {{ product_sku }}</span></li>]]></search>
<add position="before"><![CDATA[
{% if linked_categories %}
<li class="product-sku"><b>{{ text_linked_categories }}</b>
{% for linked_category in linked_categories %}
<span><a href="{{ linked_category.href }}">{{ linked_category.name }}</a></span>;
{% endfor %}
</li>
{% endif %}
]]></add>
</operation>
</file>
</modification>
我最终得到了这个工作代码:
<?xml version="1.0" encoding="UTF-8"?>
<modification>
<code></code>
<name></name>
<version></version>
<ocver></ocver>
<author></author>
<date></date>
<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="0">
<![CDATA[
$data['text_linked_category'] = $this->language->get( 'text_linked_category' );
$data['linked_category_info'] = [];
$linked_categories = $this->model_catalog_product->getCategories($product_id);
$last_category = array_pop( $linked_categories );
if( $target_category = $this->model_catalog_category->getCategory( $last_category['category_id'] ) ) {
$data['linked_category_info'] = [
'id' => $target_category['category_id'],
'href' => $this->url->link( 'product/category', 'path=' . $target_category['category_id'], true ),
'name' => $target_category['name']
];
}
]]>
</add>
</operation>
</file>
<file path="catalog/language/nl-nl/product/product.php">
<operation error="log">
<search><![CDATA[$_['text_manufacturer']]]></search>
<add position="before"><![CDATA[$_['text_linked_category'] = 'Categorie:';]]></add>
</operation>
</file>
<file path="catalog/view/theme/journal3/template/product/product.twig">
<operation error="log">
<search><![CDATA[<li class="product-sku"><b>{{ j3.settings.get(stylePrefix ~ 'ProductSKUText') }}:</b> <span> {{ product_sku }}</span></li>]]></search>
<add position="before">
<![CDATA[
{% if linked_category_info %}
<li class="product-sku"><b>{{ text_linked_category }}</b>
<span><a href="{{ linked_category_info.href }}" style="text-decoration: none">{{ linked_category_info.name }}</a></span>
</li>
{% endif %}
]]>
</add>
</operation>
</file>
</modification>
【问题讨论】:
-
您实际需要什么?请上传截图以便我们更好地理解。
-
嗨 Mujahid,我添加了一个屏幕截图。
-
但现在它正在处理屏幕截图。
-
它正在工作!但它也显示了父类别。我只想显示最新的子类别。在这种情况下,芯片。
-
是的明白,我会看到代码并尽快更新