Php 将产品属性添加到opencart发票

Php 将产品属性添加到opencart发票,php,attributes,opencart,opencart2.x,Php,Attributes,Opencart,Opencart2.x,我试图在打印发票页面上的Opencartversion2.0.1.1中显示产品属性 到目前为止,我已经通过添加$this->load->model(“目录/产品”)编辑了admin/controller/sale/order.php 然后我将'attribute'=>$this->model\u catalog\u product->getProductAttributes($product['product\u id'])添加到$product\u data[]=array()中 现在在ord

我试图在打印发票页面上的
Opencart
version
2.0.1.1
中显示产品属性

到目前为止,我已经通过添加
$this->load->model(“目录/产品”)编辑了
admin/controller/sale/order.php

然后我将'attribute'=>
$this->model\u catalog\u product->getProductAttributes($product['product\u id'])
添加到
$product\u data[]=array()中

现在在
order\u invoice.tpl
页面上,我使用
查看它正在提取哪些数据,并显示:

Array
(
[attribute_id] => 1
[product_attribute_description] => Array
    (
        [1] => Array
            (
                [text] => 240
            )

    )

)
[text]=>240
是属性的值,但我一生都无法显示属性名称,我尝试了无数次尝试,正如最常见的建议,我尝试了
$attribute['name']但这不会带来任何结果

有人能解释一下我如何正确地检索属性名和属性值吗

我试过$attribute['name'];但这并没有带来什么

那你为什么认为它会带来什么呢?显然,在
$attribute
中没有名为
name
的条目(您可以注意到在转储中通过
print\r

因此,您需要更改
$this->model\u catalog\u product->getProductAttributes
,以使其返回属性的名称,因此为了正确使用
$attribute['name']
,您的
$attribute
转储应该如下:

下面是我们要做的(很抱歉,介绍太长了):

  • 打开文件
    /admin/model/catalog/product.php
  • 转到函数
    getProductAttributes($product\u id)
    @class
    ModelCatalogProduct
  • 在这行
    $product\u attribute\u data[]=array(
    )之前,我们应该添加一个查询以获取属性名称:
  • 最后,将
    $attr\u name
    添加到结果属性数组中,在
    'attribute\u id'=>$product\u attribute['attribute\u id']行之后,
    添加
    'name'=>$attr\u name

  • 谢谢你做了一些努力并发布了你的试用,我现在就回答你的问题。这是一个完美的答案,谢谢你在这方面的帮助。我在我的原始帖子后又看了一眼,注意到模型页面只生成了属性id和产品属性描述,但我一直在想如何将名称添加到其中@JamesCollins不客气,请使用术语
    模型类
    而不是
    模型页
    Array
    (
    [attribute_id] => 1
    [name] => 'bla bla bla'
    [product_attribute_description] => Array
        (
            [1] => Array
                (
                    [text] => 240
                )
    
        )
    
    )
    
    // attribute name is stored in the table `attribute_description`
    $attr_name_query = $this->db->query("SELECT `name` FROM `" . DB_PREFIX . "attribute_description` WHERE `attribute_id` = " . (int)$product_attribute['attribute_id'] . " and `language_id` = " . (int)$this->config->get('config_language_id'));         
    $attr_name = $attr_name_query->row['name'];