0

对于特色模块中显示的每个产品,我都有一个弹出窗口,在该弹出窗口中,我想显示与产品页面外观相似的产品的所有图像,即 1 张大图像,下方有其他图像的缩略图,单击时会更新大图像。

为此,我将一些代码从控制器 product.php 复制到控制器模块 features.php 但这似乎不起作用。这是我的代码:

控制器/扩展/模块/特色.php

if ($product_info) {
                if ($product_info['image']) {
                    $image = $this->model_tool_image->resize($product_info['image'], $setting['width'], $setting['height']);
                } else {
                    $image = $this->model_tool_image->resize('placeholder.png', $setting['width'], $setting['height']);
                }

                if ($product_info['image']) {
                    $data['popup'] = $this->model_tool_image->resize($product_info['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_popup_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_popup_height'));
                } else {
                    $data['popup'] = '';
                }

                $data['images'] = array();

                $results = $this->model_catalog_product->getProductImages($this->model_catalog_product->getProduct($product_id));

                foreach ($results as $result) {
                    $data['images'][] = array(
                        'popup' => $this->model_tool_image->resize($result['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_popup_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_popup_height')),
                        'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_additional_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_additional_height'))
                    );
                }
                // some other code in between

                $data['products'][] = array(
                    'product_id'  => $product_info['product_id'],
                    'thumb'       => $image,
                    'popup'       => $image,
                    'name'        => $product_info['name'],
                    'description' => utf8_substr(strip_tags(html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('theme_' . $this->config->get('config_theme') . '_product_description_length')) . '..',
                    'price'       => $price,
                    'special'     => $special,
                    'tax'         => $tax,
                    'rating'      => $rating,
                    'href'        => $this->url->link('product/product', 'product_id=' . $product_info['product_id'])
                );

对于视图/主题/扩展/模块/特色.twig

{% if thumb or images %}
      <ul class="thumbnails">
        {% if thumb %}
        <li><a class="thumbnail" href="{{ popup }}" title="{{ heading_title }}"><img src="{{ thumb }}" title="{{ heading_title }}" alt="{{ heading_title }}" /></a></li>
        {% endif %}
        {% if images %}
        {% for image in images %}
        <li class="image-additional"><a class="thumbnail" href="{{ image.popup }}" title="{{ heading_title }}"> <img src="{{ image.thumb }}" title="{{ heading_title }}" alt="{{ heading_title }}" /></a></li>
        {% endfor %}
        {% endif %}
      </ul>
      {% endif %}
4

1 回答 1

0

您使用的代码适用于单个产品,您需要对其进行编辑才能与多个产品一起使用。

文件:

catalog\controller\extension\module\featured.php

寻找:

$data['products'][] = array(

用。。。来代替:

$images = array();
$results = $this->model_catalog_product->getProductImages($product_info['product_id']);
foreach ($results as $result) {
    $images[] = array(
        'popup' => $this->model_tool_image->resize($result['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_popup_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_popup_height')),
        'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_additional_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_additional_height'))
    );
}
$data['products'][] = array(
    'images'      => $images,

文件:

catalog\view\theme\default\template\extension\module\featured.twig

在 for 循环中,添加:

{% if product.images %}
<ul class="list-inline list-unstyled thumbnails">
{% for image in product.images %}
<li class="image-additional"><a class="thumbnail" href="{{ image.popup }}" title="{{ product.name }}"> <img src="{{ image.thumb }}" title="{{ product.name }}" alt="{{ product.name }}" /></a></li>
{% endfor %}
</ul>
{% endif %}

如果你想启用画廊(magnific-popup),在上面的控制器文件中,在 foreach 循环之外的某个地方,添加:

$this->document->addScript('catalog/view/javascript/jquery/magnific/jquery.magnific-popup.min.js');
$this->document->addStyle('catalog/view/javascript/jquery/magnific/magnific-popup.css');

在视图文件中,在 for 循环之外的某处,添加:

<script>
$(document).ready(function() {
    $('.thumbnails').magnificPopup({
        type:'image',
        delegate: 'a',
        gallery: {
            enabled: true
        }
    });
});
</script>
于 2018-01-10T07:42:37.450 回答