2012-07-12 90 views
4

我已經定義了一些自定義屬性,並通過Opencart管理面板他們分配到的產品。我試圖在結帳時檢索這些屬性以調整一些運輸成本。如何檢索Opencart中的自定義屬性?

我目前在catalog/model/shipping/ups.php文件中getQuote功能工作。我越來越接近這個:

print_r($this->cart->getProducts()); 

這給了我以下產品的數據:

Array 
(
    [59] => Array 
     (
      [key] => 59 
      [product_id] => 59 
      [name] => My Product Name 
      [model] => ABC 
      [shipping] => 1 
      [image] => data/myproduct.jpg 
      [option] => Array 
       (
       ) 

      [download] => Array 
       (
       ) 

      [quantity] => 1 
      [minimum] => 1 
      [subtract] => 1 
      [stock] => 1 
      [price] => 29.99 
      [total] => 29.99 
      [reward] => 0 
      [points] => 0 
      [tax_class_id] => 0 
      [weight] => 3.75 
      [weight_class_id] => 5 
      [length] => 0.00 
      [width] => 0.00 
      [height] => 0.00 
      [length_class_id] => 3 
     ) 

) 

但是,不返回任何自定義屬性。我確信有一個很好的方法可以將產品ID傳遞給一個屬性獲取函數,但我找不到它。 Opencart文檔在開發方面有點欠缺,在Google上也沒有運氣。

平常我grep了地獄,整個目錄結構來找到我要找的,但是shell訪問的這個特定的虛擬主機:(上禁用。

編輯

我相信屬性是Opencart中內置的一個新功能,它像一個自定義字段

無論如何,在管理員端我去了目錄>屬性,並創建了一個名爲「Shipping Box Type」的自定義屬性。我可以設置該屬性的特定產品。請參閱scr eenshot。我的目標是檢索「裝運箱類型」的價值。這是否回答你的問題@Cleverbot?我敢肯定,我可以做一個自定義的數據庫查詢抓住它,但theres必須是一個內置函數搶屬性?

opencart product attributes

+0

你想傳遞哪些屬性名稱? – Cleverbot 2012-07-13 15:07:35

+0

從哪張桌子? – Cleverbot 2012-07-13 15:36:44

回答

6

獲取給定一個屬性的product_id

$this->load->model('catalog/product'); 

$attributes = $this->model_catalog_product->getProductAttributes(59); 

print_r($attributes); 

輸出

Array 
(
    [0] => Array 
     (
      [attribute_group_id] => 9 
      [name] => Shipping Fields 
      [attribute] => Array 
       (
        [0] => Array 
         (
          [attribute_id] => 16 
          [name] => Shipping Box Type 
          [text] => SM2 
         ) 

       ) 

     ) 

) 

進一步考慮吧,這裏是目前通過產品循環的車,看看有什麼屬性的例子他們有:

$this->load->model('catalog/product'); 

$cart_products = $this->cart->getProducts(); 

// get attributes for each product in the cart 
foreach($cart_products as $product) { 
    $attributes = $this->model_catalog_product->getProductAttributes($product['product_id']); 
    print_r($attributes); 
} 
2

這不是Opencart的最直觀的特點。首先,您必須進入目錄>屬性>屬性組,並且必須創建一個組名稱,該名稱將成爲屬性的標題。爲此,它可能是「運輸規格」。

然後,你需要去目錄>屬性>屬性>和創造條件,命名爲「航運指標」,「送貨箱式」的新屬性。

現在,您準備去目錄>產品和屬性添加到產品。

捕獲是它不會顯示你如何希望我的想法。它將顯示在產品頁面上的說明旁邊的規格標籤下。你必須改變「規格」爲您選擇的目錄/查看/ * * your_theme /產品/ products.tpl的標題的容易的選擇,或者您也可以編輯同一文件的第三方物流來改變容器/格式的數據輸出變。

+0

謝謝@Cleverbot。這完全沒有爲我回答,但它幫助我找到了我正在尋找的函數:'getProductAttributes'。我會用我最終使用的一些實際代碼發佈答案。 – Banjer 2012-07-14 12:49:04

+0

啊我看到你想要的功能名稱和位置。好吧,我很高興你得到它 – Cleverbot 2012-07-14 16:14:39