4

Smart for-each ループに少し問題があります - これが私のコードです:

{* this example will print out all the values of the $custid array *}
{foreach from=$order_info item=amount}
amount: {$amount}<br>
{/foreach}

したがって、基本的には、ループして $order_info から「金額」を出力しようとしています。問題は、「金額」だけでなく、配列全体を出力することです。

以下は、デバッグ コンソールから取得した配列の項目数を減らしたものです。

{$order_info}   Array (86)
order_id => "13"
is_parent_order => "N"
parent_order_id => "0"
company_id => "0"
user_id => "1"
total => "1077.87"
subtotal => "1049.87"
discount => "0.00"
subtotal_discount => "0.00"
payment_surcharge => "0.00"
shipping_ids => "1"
shipping_cost => "28.00"
timestamp => "1352380055"
status => "O"
notes => ""
details => ""
promotions => Array (0)
promotion_ids => ""
title => ""
firstname => "John"
lastname => "Doe"
company => ""
b_title => ""
b_firstname => "John"
b_lastname => "Doe"
b_address => "44 Main street"
b_address_2 => "test"
b_city => "Boston"
b_county => ""
b_state => "MA"
b_country => "US"
b_zipcode => "02134"
b_phone => ""
s_title => ""
s_firstname => "John"
s_lastname => "Doe"
s_address => "44 Main street"
s_address_2 => "test"
s_city => "Boston"
s_county => ""
s_state => "MA"
s_country => "US"
s_zipcode => "02134"
s_phone => ""
phone => ""
fax => ""
url => ""
email => "joe@burford.co.uk"
payment_id => "3"
tax_exempt => "N"
lang_code => "EN"
ip_address => "62.49.144.33"
repaid => "0"
validation_code => ""
localization_id => "0"
payment_method => Array (15)
  payment_id => "3"
  usergroup_ids => "0"
  position => "30"
  status => "A"
  template => "check.tpl"
  processor_id => "0"
  params => ""
  a_surcharge => "0.000"
  p_surcharge => "0.000"
  localization => ""
  payment => "Check"
  description => "Check payment"
  instructions => "Type instructions to pay by visiting ..."
  lang_code => "EN"
  processor => ""
fields => Array (0)
items => Array (2)
  2902390881 => Array (19)
    item_id => "2902390881"
    order_id => "13"
    product_id => "1110"
    product_code => "B0002I9OJS"
    price => "549.99"
    amount => "1"
    extra => Array (9)
      step => "1"
      product_options => Array (0)
      unlimited_download => "N"
      product => "eMachines T2958 Desktop PC (2.66 GHz ..."
      company_id => "0"
      is_edp => "N"
      edp_shipping => "N"
      base_price => "549.99"
      stored_price => "N"
    product => "eMachines T2958 Desktop PC (2.66 GHz ..."
    deleted_product => ""
    discount => "0"
    company_id => "0"
    base_price => "549.99"
    original_price => "549.99"
    cart_id => "2902390881"
    tax_value => "0"
    subtotal => "549.99"
    display_subtotal => "549.99"
    shipped_amount => "0"
    shipment_amount => "1"
  2278796194 => Array (19)
    item_id => "2278796194"
    order_id => "13"
    product_id => "1120"
    product_code => "B00086HZJA"
    price => "499.88"
    amount => "1"
    extra => Array (9)
      step => "1"
      product_options => Array (0)
      unlimited_download => "N"
      product => "HP Pavilion a1000n Desktop PC (Intel ..."
      company_id => "0"
      is_edp => "N"
      edp_shipping => "N"
      base_price => "499.88"
      stored_price => "N"
    product => "HP Pavilion a1000n Desktop PC (Intel ..."
    deleted_product => ""
    discount => "0"
    company_id => "0"
    base_price => "499.88"
    original_price => "499.88"
    cart_id => "2278796194"
    tax_value => "0"
    subtotal => "499.88"
    display_subtotal => "499.88"
    shipped_amount => "0"
    shipment_amount => "1"

だから私が実際にやろうとしているのは、内部から取得することです. $ amountorder_info.itemsを試しましたが、これによりサイトがクラッシュしました.items$order_info

どんなアイデアでも大歓迎です。

4

2 に答える 2

3

これで解決しました:

{foreach from=$order_info.items item=foo} 
     {$foo.product_id} 
{/foreach}
于 2012-11-17T13:28:56.010 に答える
1

のようなものではないでしょうか

{foreach from=$order_info.items item=items}
    {foreach from=$items item=item}
        amount: {$item.amount}<br>
    {/foreach}
{/foreach}

あなたの構造を $order_info -> items array -> (item item item item) として理解し、各アイテムが .mount プロパティを持っていると仮定します。

于 2012-11-08T15:03:08.380 に答える