* Add SKU to product variations data store extended info

* Show SKU in product variations table

* Add sku tests for product variation reports
This commit is contained in:
Joshua T Flowers 2019-01-31 09:27:15 +08:00 committed by GitHub
parent 49e78b90cf
commit e65247c54e
3 changed files with 26 additions and 12 deletions

View File

@ -36,6 +36,12 @@ export default class VariationsReportTable extends Component {
required: true, required: true,
isLeftAligned: true, isLeftAligned: true,
}, },
{
label: __( 'SKU', 'wc-admin' ),
key: 'sku',
hiddenByDefault: true,
isSortable: true,
},
{ {
label: __( 'Items Sold', 'wc-admin' ), label: __( 'Items Sold', 'wc-admin' ),
key: 'items_sold', key: 'items_sold',
@ -77,7 +83,7 @@ export default class VariationsReportTable extends Component {
return map( data, row => { return map( data, row => {
const { items_sold, net_revenue, orders_count, extended_info, product_id } = 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 name = get( row, [ 'extended_info', 'name' ], '' ).replace( ' - ', ' / ' );
const ordersLink = getNewPath( persistedQuery, 'orders', { const ordersLink = getNewPath( persistedQuery, 'orders', {
filter: 'advanced', filter: 'advanced',
@ -94,6 +100,10 @@ export default class VariationsReportTable extends Component {
), ),
value: name, value: name,
}, },
{
display: sku,
value: sku,
},
{ {
display: items_sold, display: items_sold,
value: items_sold, value: items_sold,

View File

@ -25,17 +25,18 @@ class WC_Admin_Reports_Variations_Data_Store extends WC_Admin_Reports_Data_Store
* @var array * @var array
*/ */
protected $column_types = array( protected $column_types = array(
'date_start' => 'strval', 'date_start' => 'strval',
'date_end' => 'strval', 'date_end' => 'strval',
'product_id' => 'intval', 'product_id' => 'intval',
'variation_id' => 'intval', 'variation_id' => 'intval',
'items_sold' => 'intval', 'items_sold' => 'intval',
'net_revenue' => 'floatval', 'net_revenue' => 'floatval',
'orders_count' => 'intval', 'orders_count' => 'intval',
'name' => 'strval', 'name' => 'strval',
'price' => 'floatval', 'price' => 'floatval',
'image' => 'strval', 'image' => 'strval',
'permalink' => '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_status',
'stock_quantity', 'stock_quantity',
'low_stock_amount', 'low_stock_amount',
'sku',
); );
/** /**

View File

@ -32,6 +32,7 @@ class WC_Tests_Reports_Variations extends WC_Unit_Test_Case {
$variation->set_parent_id( $product->get_id() ); $variation->set_parent_id( $product->get_id() );
$variation->set_regular_price( 10 ); $variation->set_regular_price( 10 );
$variation->set_attributes( array( 'pa_color' => 'green' ) ); $variation->set_attributes( array( 'pa_color' => 'green' ) );
$variation->set_sku( 'test-sku' );
$variation->save(); $variation->save();
$order = WC_Helper_Order::create_order( 1, $variation ); $order = WC_Helper_Order::create_order( 1, $variation );
@ -142,6 +143,7 @@ class WC_Tests_Reports_Variations extends WC_Unit_Test_Case {
'option' => 'green', 'option' => 'green',
), ),
), ),
'sku' => $variation->get_sku(),
), ),
), ),
), ),