How to var_dump objects in Magento 2
Every once a while, we face a problem with an obvious solution but we need to check a property on an object, and we are not sure its name. XDebug is slowing down Magento 2, and sometimes it’s just not worth firing it up for such a simple task.
A common solution for such problems in PHP is var_dump. However, in Magento 2, objects are so complex with infinite recursions that it’s not a viable option. Here is a quick solution that won’t start writing to your swap and only printing the required properties in a nice readable output:
echo "<pre>"; print_r($order->debug()); die("dead");
It generates something more readable than var_dump, like this:
Array
(
[entity_id] => 128
[state] => processing
[status] => processing
[protect_code] => 0cf7e6d4dc7adae995d3263523b849eb
[shipping_description] => Ships within 2 business days. - Standard Shipping
[is_virtual] => 0
[store_id] => 1
[base_discount_amount] => 0.0000
[base_grand_total] => 23.9900
[base_shipping_amount] => 8.9900
[base_shipping_tax_amount] => 0.0000
[base_subtotal] => 15.0000
[base_tax_amount] => 0.0000
[base_to_global_rate] => 1.0000
[base_to_order_rate] => 1.0000
[discount_amount] => 0.0000
[grand_total] => 23.9900
[shipping_amount] => 8.9900
[shipping_tax_amount] => 0.0000
[store_to_base_rate] => 0.0000
[store_to_order_rate] => 0.0000
[subtotal] => 15.0000
[tax_amount] => 0.0000
[total_qty_ordered] => 1.0000
[customer_is_guest] => 1
[customer_note_notify] => 1
[billing_address_id] => 241
[customer_group_id] => 0
[quote_id] => 533
[shipping_address_id] => 240
[base_shipping_discount_amount] => 0.0000
[base_subtotal_incl_tax] => 15.0000
[base_total_due] => 23.9900
[shipping_discount_amount] => 0.0000
[subtotal_incl_tax] => 15.0000
[total_due] => 23.9900
[weight] => 0.1000
[increment_id] => MD-0020018-A
[base_currency_code] => USD
[customer_email] => sandor@---.co
[global_currency_code] => USD
[order_currency_code] => USD
[remote_ip] => 172.21.0.1
[shipping_method] => acmecorp_standard_acmecorp_standard
[store_currency_code] => USD
[store_name] => Main Website
Main Website Store
[created_at] => 2018-06-30 11:54:55
[updated_at] => 2018-06-30 11:58:49
[total_item_count] => 1
[discount_tax_compensation_amount] => 0.0000
[base_discount_tax_compensation_amount] => 0.0000
[shipping_discount_tax_compensation_amount] => 0.0000
[base_shipping_discount_tax_compensation_amnt] => 0.0000
[shipping_incl_tax] => 8.9900
[base_shipping_incl_tax] => 8.9900
[gift_cards] => []
[base_gift_cards_amount] => 0.0000
[gift_cards_amount] => 0.0000
[gw_base_price] => 0.0000
[gw_price] => 0.0000
[gw_items_base_price] => 0.0000
[gw_items_price] => 0.0000
[gw_card_base_price] => 0.0000
[gw_card_price] => 0.0000
[paypal_ipn_customer_notified] => 0
[payment (Magento\Sales\Model\Order\Payment\Interceptor)] => Array
(
[entity_id] => 131
[parent_id] => 128
[base_shipping_amount] => 8.9900
[shipping_amount] => 8.9900
[base_amount_ordered] => 23.9900
[amount_ordered] => 23.9900
[cc_ss_start_year] => 0
[method] => checkmo
[cc_ss_start_month] => 0
[cc_exp_year] => 0
[additional_information] => Array
(
[method_title] => Check / Money order
)
[method_instance (Magento\OfflinePayments\Model\Checkmo\Interceptor)] => Array
(
[info_instance (Magento\Sales\Model\Order\Payment\Interceptor)] => *** RECURSION ***
[store] => 1
)
)
[items] => Array
(
[162 (Magento\Sales\Model\Order\Item\Interceptor)] => Array
(
[item_id] => 162
[order_id] => 128
[quote_item_id] => 795
[store_id] => 1
[created_at] => 2018-06-30 11:54:55
[updated_at] => 2018-06-30 11:58:49
[product_id] => 90
[product_type] => configurable
[product_options] => Array
(
[info_buyRequest] => Array
(
[uenc] => aHR0cDovL3d3dy5kZXYtc2l0ZS5jb20vZmFjZS1ib2R5LWNsZWFuc2VyLmh0bWw,
[product] => 90
[selected_configurable_option] =>
[related_product] =>
[super_attribute] => Array
(
[735] => 69
)
[options] => Array
(
[24] => 102
)
[qty] => 1
)
[options] => Array
(
[0] => Array
(
[label] => Subscription
[value] => No, thanks!
[print_value] => No, thanks!
[option_id] => 24
[option_type] => radio
[option_value] => 102
[custom_view] =>
)
)
[attributes_info] => Array
(
[0] => Array
(
[label] => Size
[value] => 100ML
[option_id] => 735
[option_value] => 69
)
)
[simple_name] => Face & Body Cleanser-100ML
[simple_sku] => Face & Body Cleanser-100ML
[product_calculations] => 1
[shipment_type] => 0
[giftcard_is_redeemable] => 0
)
[weight] => 0.1000
[is_virtual] => 0
[sku] => Face & Body Cleanser-100ML
[name] => Face & Body Cleanser
[is_qty_decimal] => 0
[no_discount] => 0
[qty_canceled] => 0.0000
[qty_invoiced] => 0.0000
[qty_ordered] => 1.0000
[qty_refunded] => 0.0000
[qty_shipped] => 1
[price] => 15.0000
[base_price] => 15.0000
[original_price] => 15.0000
[base_original_price] => 15.0000
[tax_percent] => 0.0000
[tax_amount] => 0.0000
[base_tax_amount] => 0.0000
[tax_invoiced] => 0.0000
[base_tax_invoiced] => 0.0000
[discount_percent] => 0.0000
[discount_amount] => 0.0000
[base_discount_amount] => 0.0000
[discount_invoiced] => 0.0000
[base_discount_invoiced] => 0.0000
[amount_refunded] => 0.0000
[base_amount_refunded] => 0.0000
[row_total] => 15.0000
[base_row_total] => 15.0000
[row_invoiced] => 0.0000
[base_row_invoiced] => 0.0000
[row_weight] => 0.1000
[price_incl_tax] => 15.0000
[base_price_incl_tax] => 15.0000
[row_total_incl_tax] => 15.0000
[base_row_total_incl_tax] => 15.0000
[discount_tax_compensation_amount] => 0.0000
[base_discount_tax_compensation_amount] => 0.0000
[free_shipping] => 0
[qty_returned] => 0.0000
[has_children] => 1
[product (Magento\Catalog\Model\Product\Interceptor)] => Array
(
[row_id] => 90
[entity_id] => 90
[created_in] => 1
[updated_in] => 2147483647
[attribute_set_id] => 4
[type_id] => configurable
[sku] => Face & Body Cleanser
[has_options] => 1
[required_options] => 1
[created_at] => 2018-06-06 18:38:13
[updated_at] => 2018-06-22 21:10:51
[description] => Gentle foaming formula cleans without removing good bacteria.
[meta_keyword] => Face & Body Cleanser
[directions] =>
Use like you would any other face cleanser or body wash. Pump into your hands, lather onto wet skin, and rinse.
[ingredients] =>
Aqua (water), Rosa Damascena Flower Water, Lauramidopropyl Betaine (plant-based cleanser), Coco Glucoside (plant-based cleanser), Pyrus Malus (Apple) Fruit Extract, Glycerin (moisture-binding), Hydroxypropylcellulose (thickener), Hydrolyzed Quinoa (moisture-binding).
This preservative-free product is best when used within 8 weeks after opening. Refrigeration not necessary.
[results] => Enhances results of the AO+ Mist.
[video] =>
[advantages] => advantages.png
[related_products_title] => Boost the results of your face & body cleanser routine
[subscription_intervals] => 1,2,3
[name] => Face & Body Cleanser
[meta_title] => Face & Body Cleanser
[meta_description] => Face & Body Cleanser
[image] => /c/l/cleanser_2.png
[small_image] => /8/2/8218_0009_amazon_5.jpg
[thumbnail] => /8/2/8218_0009_amazon_5.jpg
[options_container] => container2
[url_key] => face-body-cleanser
[gift_message_available] => 2
[gift_wrapping_available] => 2
[is_returnable] => 2
[swatch_image] => no_selection
[video_title] => Is this cleanser right for you?
[video_description] => Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin ac est mauris. Cras et leo eget est eleifend iaculis quis et justo. Ut sodales nisl in purus scelerisque, vel imperdiet ligula scelerisque.
[advantages_title] => Efficacy advantage: It's actually alive in there
[advantages_description] => This cult favorite gives you great skin by restoring an essential bacteria we've lost with modern living.
[advantages_link] => #
[questions_link] => https://acmecorp1521473985.zendesk.com/hc/en-us
[results_3] => 60% of users cut out 2 or more products
[results_4] => 55% of users are able to take shorter showers with fewer products
[results_link] => https://acmecorp.zendesk.com/hc/en-us/articles/360001572048-Our-Research
[results_2] => Users across all skin types notice improvements in their skin’s appearance, as well as improved texture of the skin.
[ingredients_link] => https://acmecorp.zendesk.com/hc/en-us/sections/360000082328-Ingredients
[status] => 1
[visibility] => 4
[quantity_and_stock_status] => Array
(
[is_in_stock] => 1
[qty] => 0
)
[tax_class_id] => 2
[subscription_active] => 1
[subscription_allow_onetime] => 1
[options] => Array
(
[0 (Magento\Catalog\Model\Product\Option)] => Array
(
[option_id] => 24
[product_id] => 90
[type] => radio
[is_require] => 1
[max_characters] => 0
[image_size_x] => 0
[image_size_y] => 0
[sort_order] => 1000
[default_title] => Subscription
[title] => Subscription
)
)
[media_gallery] => Array
(
[images] => Array
(
[108] => Array
(
[value_id] => 108
[file] => /c/l/cleanser_7.jpg
[media_type] => image
[row_id] => 90
[position] => 1
[disabled] => 1
[position_default] => 1
[disabled_default] => 1
)
[111] => Array
(
[value_id] => 111
[file] => /8/2/8218_0009_amazon_5.jpg
[media_type] => image
[row_id] => 90
[position] => 2
[disabled] => 1
[position_default] => 2
[disabled_default] => 1
)
[144] => Array
(
[value_id] => 144
[file] => /c/l/cleanser_2.png
[media_type] => image
[row_id] => 90
[position] => 3
[disabled] => 0
[position_default] => 3
[disabled_default] => 0
)
)
[values] => Array
(
)
)
[category_ids] => Array
(
[0] => 2
[1] => 9
[2] => 29
)
[is_salable] => 1
)
)
[163 (Magento\Sales\Model\Order\Item\Interceptor)] => Array
(
[item_id] => 163
[order_id] => 128
[parent_item_id] => 162
[quote_item_id] => 796
[store_id] => 1
[created_at] => 2018-06-30 11:54:55
[updated_at] => 2018-06-30 11:54:55
[product_id] => 93
[product_type] => simple
[product_options] => Array
(
[info_buyRequest] => Array
(
[uenc] => aHR0cDovL3d3dy5kZXYtc2l0ZS5jb20vZmFjZS1ib2R5LWNsZWFuc2VyLmh0bWw,
[product] => 90
[selected_configurable_option] =>
[related_product] =>
[super_attribute] => Array
(
[735] => 69
)
[options] => Array
(
[24] => 102
)
[qty] => 1
)
[giftcard_is_redeemable] => 0
)
[weight] => 0.1000
[is_virtual] => 0
[sku] => Face & Body Cleanser-100ML
[name] => Face & Body Cleanser-100ML
[is_qty_decimal] => 0
[no_discount] => 0
[qty_canceled] => 0.0000
[qty_invoiced] => 0.0000
[qty_ordered] => 1.0000
[qty_refunded] => 0.0000
[qty_shipped] => 0.0000
[price] => 0.0000
[base_price] => 0.0000
[original_price] => 0.0000
[tax_percent] => 0.0000
[tax_amount] => 0.0000
[base_tax_amount] => 0.0000
[tax_invoiced] => 0.0000
[base_tax_invoiced] => 0.0000
[discount_percent] => 0.0000
[discount_amount] => 0.0000
[base_discount_amount] => 0.0000
[discount_invoiced] => 0.0000
[base_discount_invoiced] => 0.0000
[amount_refunded] => 0.0000
[base_amount_refunded] => 0.0000
[row_total] => 0.0000
[base_row_total] => 0.0000
[row_invoiced] => 0.0000
[base_row_invoiced] => 0.0000
[row_weight] => 0.0000
[free_shipping] => 0
[qty_returned] => 0.0000
[gift_message_available] => 0
[parent_item (Magento\Sales\Model\Order\Item\Interceptor)] => *** RECURSION ***
)
)
[is_in_process] => 1
[status_histories] => Array
(
)
[addresses] => Array
(
[240 (Magento\Sales\Model\Order\Address\Interceptor)] => Array
(
[entity_id] => 240
[parent_id] => 128
[region_id] => 6
[region] => Alabama
[postcode] => 12345
[lastname] => Czettner
[street] => ***
[city] => ***
[email] => sandor@---.co
[telephone] => 123456
[country_id] => US
[firstname] => Sandor
[address_type] => shipping
)
[241 (Magento\Sales\Model\Order\Address\Interceptor)] => Array
(
[entity_id] => 241
[parent_id] => 128
[region_id] => 6
[region] => Alabama
[postcode] => 12345
[lastname] => Czettner
[street] => ***
[city] => ***
[email] => sandor@---.co
[telephone] => 123456
[country_id] => US
[firstname] => Sandor
[address_type] => billing
)
)
)
dead
Comments