在opencart中显示子类别中的图像

时间:2014-07-09 11:53:19

标签: php image opencart

最近我第一次安装了Opencart 1.5.6。除了我试图在子类别中显示图像和文本(其中是精炼搜索文本)之外,所有内容都可以。 到目前为止,我已将其放在catalog\controller\module\category.php

$children_data[] = array(
    'category_id' => $child['category_id'],
    'name'        => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $product_total . ')' : ''),
    'image'       => $category['image'],
    'href'        => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id']) 
);      
}

$this->data['categories'][] = array(
    'category_id' => $category['category_id'],
    'name'        => $category['name'] . ($this->config->get('config_product_count') ? ' (' . $total . ')' : ''),
    'image'       => $category['image'],
    'children'    => $children_data,
    'href'        => $this->url->link('product/category', 'path=' . $category['category_id'])
);

新事物是'image' => $category['image'],。我也改变了一点点catalog\view\theme\MYTHEME\template\product\category.tpl

<ul>
  <?php foreach ($categories as $category) { ?>

  <li>
      <img src="../../../../../../image/data/models/<?php echo $category['image']; ?>" width="100"/>
      <a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
  </li>

  <?php } ?>
</ul>
<ul>
  <?php $j = $i + ceil(count($categories) / 4); ?>
  <?php for (; $i < $j; $i++) { ?>
  <?php if (isset($categories[$i])) { ?>
  <li>
      <img src="../../../../../../image/data/models/<?php echo $categories['image']; ?>" width="100"/>
      <a href="<?php echo $categories[$i]['href']; ?>"><?php echo $categories[$i]['name']; ?></a></li>

    <?php } ?>
  <?php } ?>
</ul>

结果是图像下方的图像和文本损坏的框。 This

我可以从错误中看到它是什么但无法弄清楚如何修复它 <img src="../../../../../../image/data/models/<b>Notice</b>: Undefined index: image in <b>..\catalog\view\theme\mytheme\template\product\category.tpl</b> on line <b>29</b>" width="100"/>

1 个答案:

答案 0 :(得分:3)

尝试使用默认的OpenCart代码。

第1步

打开文件catalog/view/theme/<your theme>/template/template/category.tpl

查找:优化类别代码。

<div class="category-list">启动div后添加

<?php $counter = 0; foreach ($categories as $category) {?>  
            <div>
                <?php if ($category['thumb']) { ?>
                <a href="<?php echo $category['href']; ?>"><img src="<?php echo $category['thumb']; ?>" alt="<?php echo $category['name']; ?>" /></a>
                <?php } else { ?>
                <a href="<?php echo $category['href']; ?>"><img src="image/no_image.jpg" alt="<?php echo $category['name']; ?>" /></a>
                <?php } ?>
                <a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
            </div>
    <?php $counter++; } ?>


第2步

打开文件catalog/controller/product/category.php

查找

$product_total = $this->model_catalog_product->getTotalProducts($data);

之后添加
$image = $this->model_tool_image->resize($result['image'], $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height'));


第3步

在同一档案catalog/controller/product/category.php

查找

'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url)

替换(而非上线)

'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url), 'thumb' => $image

然后检查它。

相关问题