2012-07-12 184 views
0

我有一個對象,我試圖從數據訪問,但似乎無法得到它。Magento訪問嵌套數據

使用Mage::log($request->debug());

我得到以下輸出

Array 
(
[all_items] => Array 
    (
     [0 (Mage_Sales_Model_Quote_Item)] => Array 
      (
       [item_id] => 593 
       [quote_id] => 536 
       [created_at] => 2012-07-12 11:40:17 
       [updated_at] => 2012-07-12 12:10:31 
       [product_id] => 37191 
       [store_id] => 8 
       [is_virtual] => 0 
       [sku] => 30018025 
       [name] => Fish Snowboard 2012 
       [free_shipping] => 
       [is_qty_decimal] => 0 
       [no_discount] => 0 
       [weight] => 5000.0000 
       [qty] => 1 
       [price] => 429.12 
       [base_price] => 429.12 
       [discount_percent] => 0.0000 
       [discount_amount] => 0.0000 
       [base_discount_amount] => 0.0000 
       [tax_percent] => 20 
       [tax_amount] => 85.8200 
       [base_tax_amount] => 85.8200 
       [row_total] => 429.12 
       [base_row_total] => 429.12 
       [row_total_with_discount] => 0.0000 
       [row_weight] => 5000 
       [product_type] => simple 
       [price_incl_tax] => 514.94 
       [base_price_incl_tax] => 514.9400 
       [row_total_incl_tax] => 514.94 
       [base_row_total_incl_tax] => 514.94 
       [weee_tax_disposition] => 0 
       [weee_tax_row_disposition] => 0 
       [base_weee_tax_disposition] => 0 
       [base_weee_tax_row_disposition] => 0 
       [weee_tax_applied] => a:0:{} 
       [weee_tax_applied_amount] => 0 
       [weee_tax_applied_row_amount] => 0 
       [base_weee_tax_applied_amount] => 0 
       [qty_options] => Array 
        (
        ) 

       [product (OrganicInternet_SimpleConfigurableProducts_Catalog_Model_Product)] => Array 
        (
         [entity_id] => 37191 
         [entity_type_id] => 4 
         [attribute_set_id] => 10 
         [type_id] => simple 
         [sku] => 30018025 
         [has_options] => 0 
         [required_options] => 0 
         [created_at] => 2011-06-19 17:34:46 
         [updated_at] => 2012-01-19 14:28:08 
         [name] => Fish Snowboard 2012 
         [small_image] => /f/i/fish-snowboard-2012-164.jpg 
         [thumbnail] => /f/i/fish-snowboard-2012-164.jpg 
         [url_key] => burton-fish-snowboard-2012-164cm 
         [url_path] => burton-fish-snowboard-2012-164cm 
         [msrp_enabled] => Use config 
         [msrp_display_actual_price_type] => Use config 
         [gift_message_available] => 
         [status] => 1 
         [visibility] => 4 
         [enable_googlecheckout] => 1 
         [tax_class_id] => 2 
         [price] => 524.9400 
         [weight] => 5000.0000 
         [is_salable] => 1 
         [stock_item (Mage_CatalogInventory_Model_Stock_Item)] => Array 
          (
           [item_id] => 35510 
           [product_id] => 37191 
           [stock_id] => 1 
           [qty] => 2.0000 
           [min_qty] => 0.0000 
           [use_config_min_qty] => 1 
           [is_qty_decimal] => 0 
           [backorders] => 0 
           [use_config_backorders] => 1 
           [min_sale_qty] => 1.0000 
           [use_config_min_sale_qty] => 1 
           [max_sale_qty] => 0.0000 
           [use_config_max_sale_qty] => 1 
           [is_in_stock] => 1 
           [notify_stock_qty] => 0.0000 
           [use_config_notify_stock_qty] => 1 
           [manage_stock] => 1 
           [use_config_manage_stock] => 1 
           [stock_status_changed_auto] => 0 
           [stock_status_changed_automatically] => 0 
           [use_config_qty_increments] => 1 
           [qty_increments] => 0.0000 
           [use_config_enable_qty_inc] => 1 
           [use_config_enable_qty_increments] => 1 
           [enable_qty_increments] => 0 
           [type_id] => simple 
           [stock_status] => 1 
           [product_name] => Fish Snowboard 2012 
           [store_id] => 8 
           [product_type_id] => simple 
           [product_status_changed] => 1 
           [ordered_items] => 1 
          ) 

         [request_path] => burton-fish-snowboard-2012-164cm 
         [tier_price] => Array 
          (
          ) 

         [is_in_stock] => 1 
         [store_id] => 8 
         [customer_group_id] => 0 
        ) 

       [tax_class_id] => 2 
       [has_error] => 
       [is_nominal] => 
       [base_original_price] => 514.9400 
       [taxable_amount] => 514.94 
       [base_taxable_amount] => 514.94 
       [is_price_incl_tax] => 1 
       [discount_calculation_price] => 429.12 
       [base_discount_calculation_price] => 429.12 
       [base_weee_tax_applied_row_amount] => 0 
      ) 

    ) 

[dest_country_id] => GB 
[dest_region_code] => 
[dest_street] => ndjn 
[dest_city] => ihho 
[dest_postcode] => iohih 
[package_value] => 514.94 
[package_value_with_discount] => 429.12 
[package_weight] => 5000 
[package_qty] => 1 
[package_physical_value] => 429.12 
[free_method_weight] => 5000 
[store_id] => 8 
[website_id] => 4 
[free_shipping] => 0 
[base_currency (Mage_Directory_Model_Currency)] => Array 
    (
     [currency_code] => GBP 
    ) 

[package_currency (Mage_Directory_Model_Currency)] => Array 
    (
     [currency_code] => GBP 
    ) 

[country_id] => GB 
[region_id] => 0 
[city] => 
[postcode] => 
[p_rcondition_name] => package_standard 
[ignore_free_items] => 
) 

我想訪問$request[all_items][0][price]$request[all_items][0][product][price]

我已經嘗試了不同的視圖方式,但無論我做什麼我只是似乎無法獲得我想要的東西。

我敢肯定它的簡單,一旦你知道如何:P

+0

嘗試向下鑽取的記錄語句,直到獲得有趣的結果。例如:'Mage :: log($ request [all_items])',然後'Mage :: log($ request [all_items] [0])'等等 – kojiro 2012-07-12 12:57:18

回答

1

你可以試試這個:

$items = $request->getAllItems(); 
$itemPrice = $items[0]->getPrice(); 
$productPrice = $items[0]->getProduct()->getPrice(); 

您會在這裏找到有關Varien_Object一些信息:http://alanstorm.com/magento_varien_object_debugging

+0

謝謝!那真是太簡單了。 – 2012-07-12 13:18:45