在Opencart中将类别名称添加到愿望清单产品

时间:2013-03-24 04:22:03

标签: php opencart

有没有办法在Opencart v1.5.5.1的愿望清单中列出的每个产品名称旁边添加类别名称?

我尝试将此添加到wishlist.tpl,但它不起作用:

<?php foreach ($categories as $category) { ?>
<li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
<?php } ?>

以及我在另一篇文章中找到的代码,该代码适用于product.tpl模板:

<?php
$this->load->model('catalog/category');
$query = $this->db->query("SELECT category_id
FROM oc_product_to_category
WHERE product_id = '".$product_id."'");
$prodcategories = $query->rows;
foreach($prodcategories as $prodcategory){
$category_id = $prodcategory['category_id'];
$category_info = $this->model_catalog_category->getCategory($category_id);
$caturl = (HTTP_SERVER . 'index.php?route=product/category&path=' . $category_id); ?>
Category : <a href="<?php echo $caturl; ?>"><?php echo $category_info['name']; ?></a><br />
<?php  }  ?>

1 个答案:

答案 0 :(得分:0)

在文件中

catalog/controller/account/wishlist.php

在第108行附近的某处,在代码块之前添加product.tpl代码

$this->data['products'][] = array(
                    'product_id' => $product_info['product_id'],
                    'thumb'      => $image,
                    'name'       => $product_info['name'],
                    'model'      => $product_info['model'],
                    'stock'      => $stock,
                    'price'      => $price,     
                    'special'    => $special,
                    'href'       => $this->url->link('product/product', 'product_id=' . $product_info['product_id']),
                    'remove'     => $this->url->link('account/wishlist', 'remove=' . $product_info['product_id'])
                );

将类别名称添加为产品的属性之一,如

                'categoryname' => $categoryinfoARRAY and then in the wishlist.tpl each product will have its associated categoryname .