From 190cd0bf866a56304de6d11d03169c94ef315a38 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Fri, 19 Aug 2016 15:08:00 +0100 Subject: [PATCH] Remove direct access of item props in admin --- includes/admin/class-wc-admin-post-types.php | 4 +- .../admin/meta-boxes/views/html-order-fee.php | 32 ++++---- .../meta-boxes/views/html-order-item.php | 73 ++++++++----------- .../meta-boxes/views/html-order-items.php | 18 +---- .../meta-boxes/views/html-order-refund.php | 2 +- .../meta-boxes/views/html-order-shipping.php | 39 ++++------ ...class-wc-rest-order-refunds-controller.php | 2 +- .../api/legacy/v1/class-wc-api-orders.php | 2 +- .../api/legacy/v2/class-wc-api-orders.php | 4 +- .../api/legacy/v3/class-wc-api-orders.php | 4 +- includes/class-wc-emails.php | 2 +- includes/cli/class-wc-cli-order.php | 2 +- .../class-wc-gateway-paypal-request.php | 6 +- templates/checkout/form-pay.php | 2 +- templates/emails/email-order-items.php | 2 +- templates/order/order-details-item.php | 2 +- 16 files changed, 80 insertions(+), 116 deletions(-) diff --git a/includes/admin/class-wc-admin-post-types.php b/includes/admin/class-wc-admin-post-types.php index 19819f3a82b..f5ecf7f7358 100644 --- a/includes/admin/class-wc-admin-post-types.php +++ b/includes/admin/class-wc-admin-post-types.php @@ -654,9 +654,9 @@ class WC_Admin_Post_Types { - get_sku() ) ? $product->get_sku() . ' - ' : ''; ?> + get_sku() ) ? $product->get_sku() . ' - ' : ''; ?>get_name(), $item, false ); ?> - + get_name(), $item, false ); ?> diff --git a/includes/admin/meta-boxes/views/html-order-fee.php b/includes/admin/meta-boxes/views/html-order-fee.php index 79dfa5d2f7e..e652cc24ea0 100644 --- a/includes/admin/meta-boxes/views/html-order-fee.php +++ b/includes/admin/meta-boxes/views/html-order-fee.php @@ -15,12 +15,12 @@ if ( ! defined( 'ABSPATH' ) ) {
- + get_name() ? $item->get_name() : __( 'Fee', 'woocommerce' ) ); ?>
@@ -32,15 +32,15 @@ if ( ! defined( 'ABSPATH' ) ) {
get_total(), array( 'currency' => $order->get_currency() ) ); if ( $refunded = $order->get_total_refunded_for_item( $item_id, 'fee' ) ) { - echo '-' . wc_price( $refunded ) . ''; + echo '-' . wc_price( $refunded, array( 'currency' => $order->get_currency() ) ) . ''; } ?>
'; ?> - + ' . esc_html( $item['name'] ) . '' : '
' . esc_html( $item['name'] ) . '
'; + echo $product_link ? '' . esc_html( $item->get_name() ) . '' : '
' . esc_html( $item->get_name() ) . '
'; - if ( $_product && $_product->get_sku() ) { - echo '
' . __( 'SKU:', 'woocommerce' ) . ' ' . esc_html( $_product->get_sku() ) . '
'; + if ( $product && $product->get_sku() ) { + echo '
' . __( 'SKU:', 'woocommerce' ) . ' ' . esc_html( $product->get_sku() ) . '
'; } - if ( ! empty( $item['variation_id'] ) ) { + if ( $item->get_variation_id() ) { echo '
' . __( 'Variation ID:', 'woocommerce' ) . ' '; - if ( ! empty( $item['variation_id'] ) && 'product_variation' === get_post_type( $item['variation_id'] ) ) { - echo esc_html( $item['variation_id'] ); - } elseif ( ! empty( $item['variation_id'] ) ) { - echo esc_html( $item['variation_id'] ) . ' (' . __( 'No longer exists', 'woocommerce' ) . ')'; + if ( 'product_variation' === get_post_type( $item->get_variation_id() ) ) { + echo esc_html( $item->get_variation_id() ); + } else { + echo esc_html( $item->get_variation_id() ) . ' (' . __( 'No longer exists', 'woocommerce' ) . ')'; } echo '
'; } ?> - + - + - + - +
get_item_total( $item, false, true ), array( 'currency' => $order->get_currency() ) ); + echo wc_price( $order->get_item_total( $item, false, true ), array( 'currency' => $order->get_currency() ) ); - if ( isset( $item['line_subtotal'] ) && $item['line_subtotal'] != $item['line_total'] ) { - echo '-' . wc_price( wc_format_decimal( $order->get_item_subtotal( $item, false, false ) - $order->get_item_total( $item, false, false ), '' ), array( 'currency' => $order->get_currency() ) ) . ''; - } + if ( $item->get_subtotal() !== $item->get_total() ) { + echo '-' . wc_price( wc_format_decimal( $order->get_item_subtotal( $item, false, false ) - $order->get_item_total( $item, false, false ), '' ), array( 'currency' => $order->get_currency() ) ) . ''; } ?>
@@ -74,21 +66,19 @@ $item_subtotal = ( isset( $item['line_subtotal'] ) ) ? esc_attr( wc_format_local ?> - +
$order->get_currency() ) ); - } + echo wc_price( $item->get_total(), array( 'currency' => $order->get_currency() ) ); - if ( isset( $item['line_subtotal'] ) && $item['line_subtotal'] !== $item['line_total'] ) { - echo '-' . wc_price( wc_format_decimal( $item['line_subtotal'] - $item['line_total'], '' ), array( 'currency' => $order->get_currency() ) ) . ''; + if ( $item->get_subtotal() !== $item->get_total() ) { + echo '-' . wc_price( wc_format_decimal( $item->get_subtotal() - $item->get_total(), '' ), array( 'currency' => $order->get_currency() ) ) . ''; } if ( $refunded = $order->get_total_refunded_for_item( $item_id ) ) { @@ -100,11 +90,11 @@ $item_subtotal = ( isset( $item['line_subtotal'] ) ) ? esc_attr( wc_format_local
- +
- +
@@ -114,9 +104,9 @@ $item_subtotal = ( isset( $item['line_subtotal'] ) ) ? esc_attr( wc_format_local get_taxes() ) && wc_tax_enabled() ) { foreach ( $order_taxes as $tax_item ) { - $tax_item_id = $tax_item['rate_id']; + $tax_item_id = $tax_item->get_rate_id(); $tax_item_total = isset( $tax_data['total'][ $tax_item_id ] ) ? $tax_data['total'][ $tax_item_id ] : ''; $tax_item_subtotal = isset( $tax_data['subtotal'][ $tax_item_id ] ) ? $tax_data['subtotal'][ $tax_item_id ] : ''; ?> @@ -129,7 +119,7 @@ $item_subtotal = ( isset( $item['line_subtotal'] ) ) ? esc_attr( wc_format_local echo '–'; } - if ( isset( $item['line_subtotal'] ) && $item['line_subtotal'] !== $item['line_total'] ) { + if ( $item->get_subtotal() !== $item->get_total() ) { echo '-' . wc_price( wc_round_tax_total( $tax_item_subtotal - $tax_item_total ), array( 'currency' => $order->get_currency() ) ) . ''; } @@ -158,7 +148,6 @@ $item_subtotal = ( isset( $item['line_subtotal'] ) ) ? esc_attr( wc_format_local } } ?> -
is_editable() ) : ?> diff --git a/includes/admin/meta-boxes/views/html-order-items.php b/includes/admin/meta-boxes/views/html-order-items.php index 97436f84fcd..1dadbb0db56 100644 --- a/includes/admin/meta-boxes/views/html-order-items.php +++ b/includes/admin/meta-boxes/views/html-order-items.php @@ -26,21 +26,7 @@ if ( wc_tax_enabled() ) { } } - // Older orders won't have line taxes so we need to handle them differently :( - $tax_data = ''; - if ( $line_items ) { - $check_item = current( $line_items ); - $tax_data = maybe_unserialize( isset( $check_item['line_tax_data'] ) ? $check_item['line_tax_data'] : '' ); - } elseif ( $line_items_shipping ) { - $check_item = current( $line_items_shipping ); - $tax_data = maybe_unserialize( isset( $check_item['taxes'] ) ? $check_item['taxes'] : '' ); - } elseif ( $line_items_fee ) { - $check_item = current( $line_items_fee ); - $tax_data = maybe_unserialize( isset( $check_item['line_tax_data'] ) ? $check_item['line_tax_data'] : '' ); - } - - $legacy_order = ! empty( $order_taxes ) && empty( $tax_data ) && ! is_array( $tax_data ); - $show_tax_columns = ! $legacy_order || sizeof( $order_taxes ) === 1; + $show_tax_columns = sizeof( $order_taxes ) === 1; } ?>
@@ -53,7 +39,7 @@ if ( wc_tax_enabled() ) { $tax_item ) : $tax_class = wc_get_tax_class_by_tax_id( $tax_item['rate_id'] ); $tax_class_name = isset( $classes_options[ $tax_class ] ) ? $classes_options[ $tax_class ] : __( 'Tax', 'woocommerce' ); diff --git a/includes/admin/meta-boxes/views/html-order-refund.php b/includes/admin/meta-boxes/views/html-order-refund.php index 4123cee47fc..a50977a6730 100644 --- a/includes/admin/meta-boxes/views/html-order-refund.php +++ b/includes/admin/meta-boxes/views/html-order-refund.php @@ -36,7 +36,7 @@ $who_refunded = new WP_User( $refund->post->post_author );
- + diff --git a/includes/admin/meta-boxes/views/html-order-shipping.php b/includes/admin/meta-boxes/views/html-order-shipping.php index b55fdc9c0c4..04f03e609ef 100644 --- a/includes/admin/meta-boxes/views/html-order-shipping.php +++ b/includes/admin/meta-boxes/views/html-order-shipping.php @@ -5,9 +5,8 @@ * @var object $item The item being displayed * @var int $item_id The id of the item being displayed */ - if ( ! defined( 'ABSPATH' ) ) { - exit; // Exit if accessed directly + exit; } ?> @@ -15,11 +14,11 @@ if ( ! defined( 'ABSPATH' ) ) {
- + get_name() ? $item->get_name() : __( 'Shipping', 'woocommerce' ) ); ?>