2012-11-15 42 views
0

我想從銷售訂單項目中獲取自定義選項值。我寫了如下代碼Magento從Serializd陣列獲取數據

foreach ($order->getAllItems() as $item){ 
    $productOptions = $item->getProductOptions(); 
    foreach($productOptions as $opt){ 
    var_dump($opt); 
    } 
    } 

但我不知道何通過這個數組訪問單個選項。 EX- $ OPT->標題

這裏沒有得到任何東西是無功轉儲一個項目

array(7) { ["uenc"]=> string(80) "aHR0cDovL3ZhbmhhZ2UuY2FtZm9saW8uY28udWsvc2hvcC1vbmxpbmUvbG95YWx0eS1jYXJkLmh0bWw," ["product"]=> string(4) "1841" ["related_product"]=> string(0) "" ["super_attribute"]=> array(1) { [1000]=> string(5) "11160" } ["options"]=> array(13) { [1574]=> string(2) "Mr" [1575]=> string(7) "Cameron" [1576]=> string(4) "Owen" [1577]=> string(1) "6" [1578]=> string(14) "Address Line 1" [1579]=> string(14) "Address Line 2" [1580]=> string(4) "Town" [1581]=> string(6) "County" [1582]=> string(7) "B17 6AG" [1583]=> string(12) "0121 424 578" [1584]=> string(11) "07811877865" [1585]=> string(10) "19/04/1987" [1573]=> string(20) "[email protected]" } ["cpid"]=> string(4) "1840" ["qty"]=> int(1) } array(13) { [0]=> array(7) { ["label"]=> string(5) "Title" ["value"]=> string(2) "Mr" ["print_value"]=> string(2) "Mr" ["option_id"]=> string(4) "1574" ["option_type"]=> string(5) "field" ["option_value"]=> string(2) "Mr" ["custom_view"]=> bool(false) } [1]=> array(7) { ["label"]=> string(10) "First Name" ["value"]=> string(7) "Cameron" ["print_value"]=> string(7) "Cameron" ["option_id"]=> string(4) "1575" ["option_type"]=> string(5) "field" ["option_value"]=> string(7) "Cameron" ["custom_view"]=> bool(false) } [2]=> array(7) { ["label"]=> string(9) "Last Name" ["value"]=> string(4) "Owen" ["print_value"]=> string(4) "Owen" ["option_id"]=> string(4) "1576" ["option_type"]=> string(5) "field" ["option_value"]=> string(4) "Owen" ["custom_view"]=> bool(false) } [3]=> array(7) { ["label"]=> string(12) "House Number" ["value"]=> string(1) "6" ["print_value"]=> string(1) "6" ["option_id"]=> string(4) "1577" ["option_type"]=> string(5) "field" ["option_value"]=> string(1) "6" ["custom_view"]=> bool(false) } [4]=> array(7) { ["label"]=> string(14) "Address Line 1" ["value"]=> string(14) "Address Line 1" ["print_value"]=> string(14) "Address Line 1" ["option_id"]=> string(4) "1578" ["option_type"]=> string(5) "field" ["option_value"]=> string(14) "Address Line 1" ["custom_view"]=> bool(false) } [5]=> array(7) { ["label"]=> string(14) "Address Line 2" ["value"]=> string(14) "Address Line 2" ["print_value"]=> string(14) "Address Line 2" ["option_id"]=> string(4) "1579" ["option_type"]=> string(5) "field" ["option_value"]=> string(14) "Address Line 2" ["custom_view"]=> bool(false) } [6]=> array(7) { ["label"]=> string(4) "Town" ["value"]=> string(4) "Town" ["print_value"]=> string(4) "Town" ["option_id"]=> string(4) "1580" ["option_type"]=> string(5) "field" ["option_value"]=> string(4) "Town" ["custom_view"]=> bool(false) } [7]=> array(7) { ["label"]=> string(6) "County" ["value"]=> string(6) "County" ["print_value"]=> string(6) "County" ["option_id"]=> string(4) "1581" ["option_type"]=> string(5) "field" ["option_value"]=> string(6) "County" ["custom_view"]=> bool(false) } [8]=> array(7) { ["label"]=> string(8) "Postcode" ["value"]=> string(7) "B17 6AG" ["print_value"]=> string(7) "B17 6AG" ["option_id"]=> string(4) "1582" ["option_type"]=> string(5) "field" ["option_value"]=> string(7) "B17 6AG" ["custom_view"]=> bool(false) } [9]=> array(7) { ["label"]=> string(16) "Telephone Number" ["value"]=> string(12) "0121 424 578" ["print_value"]=> string(12) "0121 424 578" ["option_id"]=> string(4) "1583" ["option_type"]=> string(5) "field" ["option_value"]=> string(12) "0121 424 578" ["custom_view"]=> bool(false) } [10]=> array(7) { ["label"]=> string(13) "Mobile Number" ["value"]=> string(11) "07811877865" ["print_value"]=> string(11) "07811877865" ["option_id"]=> string(4) "1584" ["option_type"]=> string(5) "field" ["option_value"]=> string(11) "07811877865" ["custom_view"]=> bool(false) } [11]=> array(7) { ["label"]=> string(13) "Date of Birth" ["value"]=> string(10) "19/04/1987" ["print_value"]=> string(10) "19/04/1987" ["option_id"]=> string(4) "1585" ["option_type"]=> string(5) "field" ["option_value"]=> string(10) "19/04/1987" ["custom_view"]=> bool(false) } [12]=> array(7) { ["label"]=> string(13) "Email Address" ["value"]=> string(20) "[email protected]" ["print_value"]=> string(20) "[email protected]" ["option_id"]=> string(4) "1573" ["option_type"]=> string(5) "field" ["option_value"]=> string(20) "[email protected]" ["custom_view"]=> bool(false) } } 

誰能幫助我從這個 前 郵箱地址獲得DATAS 出生日期 等....

謝謝

+0

嘗試$ opt ['...'] ...例如$ opt ['label'] –

+0

沒有好運的伴侶, http://vanhage.camfolio.co.uk/reporting2.php是我的測試網址 –

+0

你使用什麼版本的magento? –

回答

0

$ opt是一個多維數組。

因此,如果您要訪問的第一個名字,你可以使用:

$options=$opt['options']; 
$name=$options[1575]; 

但這可能是艱苦的工作。我真的建議你創建一個類(如果沒有的話)並且反序列化一個超出$ opt的對象。

+0

嘗試在其中放置一個劇集:$ options =(array)$ opt ['options']。我不能重現這個問題,我懶得寫一個有效的php數組ut,​​結果是這個var_dump結果 –

+0

這個工作很好,謝謝:) –