From e65247c54e6f3c179ea2021606d81cbcf2142bb3 Mon Sep 17 00:00:00 2001 From: Joshua T Flowers Date: Thu, 31 Jan 2019 09:27:15 +0800 Subject: [PATCH] Add SKU to product variations table (https://github.com/woocommerce/woocommerce-admin/pull/1422) * Add SKU to product variations data store extended info * Show SKU in product variations table * Add sku tests for product variation reports --- .../report/products/table-variations.js | 12 +++++++++- ...wc-admin-reports-variations-data-store.php | 24 ++++++++++--------- .../class-wc-tests-reports-variations.php | 2 ++ 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/plugins/woocommerce-admin/client/analytics/report/products/table-variations.js b/plugins/woocommerce-admin/client/analytics/report/products/table-variations.js index 5bfda17057b..e60767c2b0e 100644 --- a/plugins/woocommerce-admin/client/analytics/report/products/table-variations.js +++ b/plugins/woocommerce-admin/client/analytics/report/products/table-variations.js @@ -36,6 +36,12 @@ export default class VariationsReportTable extends Component { required: true, isLeftAligned: true, }, + { + label: __( 'SKU', 'wc-admin' ), + key: 'sku', + hiddenByDefault: true, + isSortable: true, + }, { label: __( 'Items Sold', 'wc-admin' ), key: 'items_sold', @@ -77,7 +83,7 @@ export default class VariationsReportTable extends Component { return map( data, row => { const { items_sold, net_revenue, orders_count, extended_info, product_id } = row; - const { stock_status, stock_quantity, low_stock_amount } = extended_info; + const { stock_status, stock_quantity, low_stock_amount, sku } = extended_info; const name = get( row, [ 'extended_info', 'name' ], '' ).replace( ' - ', ' / ' ); const ordersLink = getNewPath( persistedQuery, 'orders', { filter: 'advanced', @@ -94,6 +100,10 @@ export default class VariationsReportTable extends Component { ), value: name, }, + { + display: sku, + value: sku, + }, { display: items_sold, value: items_sold, diff --git a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-variations-data-store.php b/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-variations-data-store.php index e6107fff7c6..c24110d35ce 100644 --- a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-variations-data-store.php +++ b/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-variations-data-store.php @@ -25,17 +25,18 @@ class WC_Admin_Reports_Variations_Data_Store extends WC_Admin_Reports_Data_Store * @var array */ protected $column_types = array( - 'date_start' => 'strval', - 'date_end' => 'strval', - 'product_id' => 'intval', - 'variation_id' => 'intval', - 'items_sold' => 'intval', - 'net_revenue' => 'floatval', - 'orders_count' => 'intval', - 'name' => 'strval', - 'price' => 'floatval', - 'image' => 'strval', - 'permalink' => 'strval', + 'date_start' => 'strval', + 'date_end' => 'strval', + 'product_id' => 'intval', + 'variation_id' => 'intval', + 'items_sold' => 'intval', + 'net_revenue' => 'floatval', + 'orders_count' => 'intval', + 'name' => 'strval', + 'price' => 'floatval', + 'image' => 'strval', + 'permalink' => 'strval', + 'sku' => 'strval', ); /** @@ -64,6 +65,7 @@ class WC_Admin_Reports_Variations_Data_Store extends WC_Admin_Reports_Data_Store 'stock_status', 'stock_quantity', 'low_stock_amount', + 'sku', ); /** diff --git a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-variations.php b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-variations.php index 8bac9675a35..082e8d6e307 100644 --- a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-variations.php +++ b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-variations.php @@ -32,6 +32,7 @@ class WC_Tests_Reports_Variations extends WC_Unit_Test_Case { $variation->set_parent_id( $product->get_id() ); $variation->set_regular_price( 10 ); $variation->set_attributes( array( 'pa_color' => 'green' ) ); + $variation->set_sku( 'test-sku' ); $variation->save(); $order = WC_Helper_Order::create_order( 1, $variation ); @@ -142,6 +143,7 @@ class WC_Tests_Reports_Variations extends WC_Unit_Test_Case { 'option' => 'green', ), ), + 'sku' => $variation->get_sku(), ), ), ),