我正在尝试在Opencart
版本2.0.1.1
的"打印发票"页面上显示产品属性。
到目前为止,我已经通过添加$this->load->model("catalog/product");
编辑了admin/controller/sale/order.php
然后我在$product_data[] = array()
中添加了"attribute"=>$this->model_catalog_product->getProductAttributes($product['product_id'])
现在在order_invoice.tpl
页面上,我已经使用<?php print_r ($attribute);?>
来查看它正在提取的数据,它显示:
Array
(
[attribute_id] => 1
[product_attribute_description] => Array
(
[1] => Array
(
[text] => 240
)
)
)
[text] => 240
是属性的值,但我一辈子都无法显示属性名称,我尝试了很多次,正如最常见的建议,我尝试过$attribute['name'];
,但这没有带来任何结果。
有人能解释一下我如何正确地检索属性名称和属性值吗。
我试过$attribute['name'];但这并没有带来
那么,你为什么认为它应该带来一些东西呢?显然,在$attribute
中没有这样一个名为name
的条目(您可以注意到,在通过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
)
)
)
下面是我们要做的(很抱歉介绍太长):
- 打开文件
<OC_ROOT>/admin/model/catalog/product.php
- 转到函数
getProductAttributes($product_id)
@classModelCatalogProduct
- 在这行
$product_attribute_data[] = array(
之前,我们应该添加一个查询来获取属性名称:
// 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'];
- 最后,将
$attr_name
添加到结果属性数组中,在行'attribute_id' => $product_attribute['attribute_id'],
之后添加'name' => $attr_name