2016-04-14 110 views
2

我試圖在Opencart版本2.0.1.1的打印發票頁面上顯示產品屬性。將產品屬性添加到opencart發票

所以由order_invoice.tpl頁我用<?php print_r ($attribute);?>看到它是拉什麼數據上添加$this->load->model("catalog/product");

然後我加入「屬性」 =>$this->model_catalog_product->getProductAttributes($product['product_id'])$product_data[] = array()

現在爲止,我已經編輯admin/controller/sale/order.php它表明:

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

    ) 

) 

[text] => 240是屬性的價值,但我不能爲我的克生活等屬性名稱顯示出來,我已經嘗試過無數次嘗試,並且最常見的建議是我試過$attribute['name'];,但這沒有任何結果。

有人可以請解釋我如何可以正確檢索屬性名稱和屬性值。

+0

感謝做一些努力和發佈您的試驗,我會回答你的問題現在 –

回答

1

我試過$屬性['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 
      ) 

    ) 

) 

所以這是我們要做的(抱歉長介紹):

  1. 打開文件<OC_ROOT>/admin/model/catalog/product.php
  2. 去功能getProductAttributes($product_id) @類ModelCatalogProduct
  3. 此行$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']; 
  1. 最後,將$attr_name添加到resulul坦屬性陣列,後線'attribute_id' => $product_attribute['attribute_id'],添加'name' => $attr_name
+0

阿卜杜這是一個完美的答案,謝謝你的這個幫助。我看了一下我原來的帖子,注意到模型頁面只是生成了attribute_id和product_attribute_description,但我一直被困在如何獲得名稱添加到它。 –

+0

@JamesCollins歡迎您使用術語'model class'而不是'model page' –

相關問題