Magento访问嵌套数据

时间:2012-07-12 12:44:32

标签: php 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

1 个答案:

答案 0 :(得分:1)

你可以试试这个:

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

您可以在此处找到有关Varien_Object的一些信息:http://alanstorm.com/magento_varien_object_debugging