Opencart - 愿望清单上的其他图像

时间:2014-02-07 21:56:04

标签: variables opencart

尝试在其他页面上显示其他产品图片,例如愿望清单(但我实际上是在类似的批发模式上使用它)。我真的想知道OpenCart的这部分是如何工作的,但我似乎无法掌握它。

我已将此添加到“Wholesale.php”控制器(来自“Product.php”控制器):

$results = $this->model_catalog_product->getProductImages($this->request->get['product_id']);

foreach ($results as $product_info) {
 $this->data['image'][] = array(
  'popup' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height')),
  'image' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_additional_width'), $this->config->get('config_image_additional_height'))
 );
}

然后我将它('image2')添加到它下面的数组中:

    $this->data['products'][$product_info['product_id']] = array(
      'num' =>  $start + $count,
      'image' => $product_info['image'] ? $this->model_tool_image->resize($product_info['image'], $pricelist['image_width'], $pricelist['image_height']) : $this->model_tool_image->resize('no_image.jpg', $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height')),                        
THIS ONE >>> 'image2' => $product_info['image'] ? $this->model_tool_image->resize($product_info['image'], $pricelist['image_width'], $pricelist['image_height']) : $this->model_tool_image->resize('no_image.jpg', $this->config->get('config_image_additional_width'), $this->config->get('config_image_additional_height')),
      'popup' => $product_info['image'] ? $this->model_tool_image->resize($product_info['image'], $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height')) : false,
      'href' => $this->url->link('product/product', 'product_id=' . $product_info['product_id']),
    );

最后,(为简单起见)模板上的IMG标签:

<img src="<?php echo $product['image2']; ?>" />

我设法减少了错误,直到我离开了 UndefinedIndex:product_id (并且主要产品图片只是在页面上重复)...但现在我完全卡住了

我很想学习这个......但是我甚至不确定问题是什么......“product_id”已经多次在这个控制器中使用了,我不知道为什么我需要注册它再次......所以我不明白为什么它是未定义的。

对于这篇长篇文章感到抱歉,任何见解都会受到赞赏...只是想让其他产品图片显示在“Product.tpl”以外的页面上


编辑:添加完整页面代码以供参考... Stack太长了,使用了pastebin:

Wholesale.php(相关代码很容易识别,广泛分隔/评论): http://pastebin.com/7HRdw3Sp

TemplateFile.tpl(为了方便/冗余而修剪): http://pastebin.com/tdMB0kpe

无论如何,我很欣赏任何见解...... 在过去的3天里,我一直在试用这百万种不同的方式,我甚至无法接近。 :/

2 个答案:

答案 0 :(得分:0)

你应该在“Wholesale.php”控制器中尝试这种方式(来自“Product.php”控制器):

$这 - &GT;负载&GT;模型( '工具/图像');

        if ($product_info['image']) {
            $this->data['popup'] = $this->model_tool_image->resize($product_info['image'], $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height'));
        } else {
            $this->data['popup'] = '';
        }

        if ($product_info['image']) {
            $this->data['thumb'] = $this->model_tool_image->resize($product_info['image'], $this->config->get('config_image_thumb_width'), $this->config->get('config_image_thumb_height'));
        } else {
            $this->data['thumb'] = '';
        }

        $this->data['images'] = array();

        $results = $this->model_catalog_product->getProductImages($this->request->get['product_id']);

        foreach ($results as $result) {
            $this->data['images'][] = array(
                'popup' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height')),
                'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_additional_width'), $this->config->get('config_image_additional_height'))
            );
        }   

转发查看

            $this->data['products'][] = array(
                    'product_id' => $result['product_id'],
                    'thumb'      => $image,

.tpl文件中的img标签“默认主题的参考”

 <?php if ($thumb || $images) { ?>
    <div class="left">
      <?php if ($thumb) { ?>
      <div class="image"><a href="<?php echo $popup; ?>" title="<?php echo $heading_title; ?>" class="colorbox" rel="colorbox"><img src="<?php echo $thumb; ?>" title="<?php echo $heading_title; ?>" alt="<?php echo $heading_title; ?>" id="image" /></a></div>
      <?php } ?>
      <?php if ($images) { ?>
      <div class="image-additional">
        <?php foreach ($images as $image) { ?>
        <a href="<?php echo $image['popup']; ?>" title="<?php echo $heading_title; ?>" class="colorbox" rel="colorbox"><img src="<?php echo $image['thumb']; ?>" title="<?php echo $heading_title; ?>" alt="<?php echo $heading_title; ?>" /></a>
        <?php } ?>
      </div>
      <?php } ?>
    </div>
    <?php } ?>

答案 1 :(得分:0)

我在控制器中看到很少的错误

  1. 在从第124行开始的修改中,您正在使用在第427行定义的数组$product_info[](也将在每次迭代中更改,因此您必须仅在该foreach循环内进行所有编辑)< / p>

  2. 在同一修改中,您使用的是$this->request->get['product_id'],我非常确定没有定义。验证它是否有类似product_id=的内容,它不会出现,所以你不能使用它

  3. 第407行周围的修改没有多大意义

  4. 我希望这些观点足以让你开始