0

我正在尝试从销售订单项目中获取自定义选项值。我写了一个代码如下

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

但我不知道如何通过这个数组访问单个选项。ex- $opt-> 标题

没有为我得到任何东西

这是一项的 var 转储

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) "hello@camfolio.co.uk" } ["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) "hello@camfolio.co.uk" ["print_value"]=> string(20) "hello@camfolio.co.uk" ["option_id"]=> string(4) "1573" ["option_type"]=> string(5) "field" ["option_value"]=> string(20) "hello@camfolio.co.uk" ["custom_view"]=> bool(false) } } 

谁能帮我从这个前电子邮件地址出生日期等获取数据......

谢谢你

4

1 回答 1

0

$opt 是一个多维数组。

因此,如果您想访问名字,您可以使用:

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

但这可能是一项艰苦的工作。我真的建议你创建一个类(如果没有的话)并从 $opt 中反序列化一个对象。

于 2012-11-15T19:46:16.407 回答