如何向目录页面添加属性

时间:2016-03-25 16:38:01

标签: php opencart opencart2.x

我尝试将属性添加到产品的目录页面。 在文件catalog/view/theme/default/template/product/category.tpl中 我添加了这一行

<p><?php echo $data['attribute_groups']; ?></p>

但我有一个错误Notice: Undefined index: attribute_groups in

然后我将此行添加到&#39; catalog / controller / product / category.php&#39;

 $data['attribute_groups'] = $this->model_catalog_product->getProductAttributes($this->request->get['product_id']);

现在我又出现了另一个错误Undefined index: product_id in

第一个截图

first image

第二

second

1 个答案:

答案 0 :(得分:2)

你的代码甚至没有意义 首先$this->request->get['product_id']

中没有category.php

第二个$data['attribute_groups']是一个数组,你正试图回应它。

之后传递产品数组中的属性组
$data['products'][] = array(

添加

'attribute_groups' => $this->model_catalog_product->getProductAttributes($result['product_id']),

现在您可以在

中打印值了
<?php foreach ($attribute_group['attribute'] as $attribute) { ?>
        <?php echo $attribute['name']; ?>
        <?php echo $attribute['text']; ?>
<?php } ?>