将产品属性添加到opencart invoice

时间:2016-04-14 15:14:46

标签: php attributes opencart opencart2.x

我正在Opencart版本2.0.1.1的“打印发票”页面上显示产品属性。<​​/ p>

到目前为止,我已通过添加admin/controller/sale/order.php

$this->load->model("catalog/product");进行了修改

然后我添加了'attribute'=&gt; $this->model_catalog_product->getProductAttributes($product['product_id'])

$product_data[] = array()

现在在order_invoice.tpl页面上,我使用了<?php print_r ($attribute);?>来查看它所提取的数据,并显示:

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

    )

)

[text] => 240是属性的值,但我不能在我的生活中获得要显示的属性名称,我尝试过多次尝试,并且最常见的建议我尝试过$attribute['name'];但这没有任何结果。

有人可以解释我如何正确检索属性名称和属性值。

1 个答案:

答案 0 :(得分:1)

  

我已尝试过$ attribute [&#39; name&#39;];但这并没有带来什么

那你为什么认为应该提出一些建议呢?显然,在name中没有这样一个名为$attribute的条目(你可以注意到你在转储中通过了print_r

因此,您需要以返回属性名称的方式更改$this->model_catalog_product->getProductAttributes,因此为了正确使用$attribute['name'],您的$attribute转储应如下所示:

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

    )

)

所以这就是我们要做的事情(抱歉长篇介绍):

  1. 打开文件<OC_ROOT>/admin/model/catalog/product.php
  2. 转到功能getProductAttributes($product_id) @ class ModelCatalogProduct
  3. 在此行$product_attribute_data[] = array(之前,我们应该添加一个查询来获取属性名称:
  4. // 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'];
    
    1. 最后,在$attr_name添加'attribute_id' => $product_attribute['attribute_id'],
    2. 行之后,将'name' => $attr_name添加到结果属性数组中
相关问题