如何在Opencart 3所属的产品页面上显示类别的图像 [英] How to display images of categories on the product page to which it belongs Opencart 3

查看:95
本文介绍了如何在Opencart 3所属的产品页面上显示类别的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请告诉我如何在产品页面上显示产品所属类别的图像.我带出了名称和指向类别的链接,但是使用图像却无法使用.我不明白要在什么地方插入类别图像.我做到了(在OCMOD文件中):

Please tell me how to display images of the categories to which the product belongs on the product page. I brought out the name and link to the categories, but with the image it does not work. I can't understand what and where to insert to display category images. I did this (in OCMOD file):

<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>

推荐答案

您错过了在控制器中获取图像的代码.现在,您的OCMOD文件如下所示:

You miss the code to get images in your controller. Now you OCMOD file looks like this:

<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>

这篇关于如何在Opencart 3所属的产品页面上显示类别的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆