[英]opencart how to display all categories with images on home page opencart 1.5.1.3
[英]How to display images of categories on the product page to which it belongs Opencart 3
請告訴我如何在產品頁面上顯示產品所屬類別的圖像。 我拿出了類別的名稱和鏈接,但使用圖像它不起作用。 我不明白要插入什么以及在哪里顯示類別圖像。 我這樣做了(在 OCMOD 文件中):
<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[
$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_name'];]]></search>
<add position="before"><![CDATA[
$data['linked_categories'] = $linked_categories;
]]></add>
</operation>
<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 %}
<div class="uni-module product-linked_categories">
<div class="category-list row row-flex">
{% for linked_category in linked_categories %}
<div>
<a href="{{ linked_category.href }}" class="category-list__item image-after">
{% if linked_category.thumb %}
<img src="{{ linked_category.thumb }}" alt="{{ linked_category.name }}" title="{{ linked_category.name }}" class="category-list__img img-responsive" />
{% endif %}
{{ linked_category.name }}
</a>
</div>
{% endfor %}
</div>
</div>
<script>
$('.product-linked_categories').uniModules({
type:'{{type_view is defined ? type_view : 'carousel'}}',
loop: {{linked_categories|length > 4 ? 'true' : 'false'}}
});
</script>
{% endif %}
]]></add>
</operation>
</file>
您錯過了在 controller 中獲取圖像的代碼。 現在您的 OCMOD 文件如下所示:
<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[
$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'];
// added this part for thumbs
if ($linked_category['image']) {
$linked_category_info['thumb'] = $this->model_tool_image->resize($linked_category['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_category_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_category_height'));
} else {
$linked_category_info['thumb'] = '';
}
//
$linked_categories[] = $linked_category_info;
}
]]></add>
</operation>
<operation error="log">
<search><![CDATA[$data['manufacturer'] = $product_info['manufacturer_name'];]]></search>
<add position="before"><![CDATA[
$data['linked_categories'] = $linked_categories;
]]></add>
</operation>
<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 %}
<div class="uni-module product-linked_categories">
<div class="category-list row row-flex">
{% for linked_category in linked_categories %}
<div>
<a href="{{ linked_category.href }}" class="category-list__item image-after">
{% if linked_category.thumb %}
<img src="{{ linked_category.thumb }}" alt="{{ linked_category.name }}" title="{{ linked_category.name }}" class="category-list__img img-responsive" />
{% endif %}
{{ linked_category.name }}
</a>
</div>
{% endfor %}
</div>
</div>
<script>
$('.product-linked_categories').uniModules({
type:'{{type_view is defined ? type_view : 'carousel'}}',
loop: {{linked_categories|length > 4 ? 'true' : 'false'}}
});
</script>
{% endif %}
]]></add>
</operation>
</file>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.