* Add product SKU to products report

* Add tests for SKU data
This commit is contained in:
Joshua T Flowers 2018-12-25 11:02:06 +08:00 committed by GitHub
parent bdcebd7ea3
commit dcaa35c7bf
4 changed files with 17 additions and 2 deletions

View File

@ -95,14 +95,20 @@ class ProductsReportTable extends Component {
return map( data, row => {
const {
product_id,
sku = '', // @TODO
extended_info,
items_sold,
net_revenue,
orders_count,
variations = [], // @TODO
} = row;
const { category_ids, low_stock_amount, name, stock_status, stock_quantity } = extended_info;
const {
category_ids,
low_stock_amount,
name,
sku,
stock_status,
stock_quantity,
} = extended_info;
const ordersLink = getNewPath( persistedQuery, 'orders', {
filter: 'advanced',
product_includes: product_id,

View File

@ -224,6 +224,12 @@ class WC_Admin_REST_Reports_Products_Controller extends WC_REST_Reports_Controll
'context' => array( 'view', 'edit' ),
'description' => __( 'Product inventory threshold for low stock.', 'wc-admin' ),
),
'sku' => array(
'type' => 'string',
'readonly' => true,
'context' => array( 'view', 'edit' ),
'description' => __( 'Product SKU.', 'wc-admin' ),
),
),
),
);

View File

@ -40,6 +40,7 @@ class WC_Admin_Reports_Products_Data_Store extends WC_Admin_Reports_Data_Store i
'stock_quantity' => 'intval',
'low_stock_amount' => 'intval',
'category_ids' => 'array_values',
'sku' => 'strval',
);
/**
@ -68,6 +69,7 @@ class WC_Admin_Reports_Products_Data_Store extends WC_Admin_Reports_Data_Store i
'stock_quantity',
'low_stock_amount',
'category_ids',
'sku',
);
/**

View File

@ -242,6 +242,7 @@ class WC_Tests_Reports_Products extends WC_Unit_Test_Case {
'stock_quantity' => $product->get_stock_quantity(),
'low_stock_amount' => $product->get_low_stock_amount(),
'category_ids' => array_values( $product->get_category_ids() ),
'sku' => $product->get_sku(),
),
),
),