2018-10-11 08:30:51 +00:00
|
|
|
|
/** @format */
|
|
|
|
|
/**
|
|
|
|
|
* External dependencies
|
|
|
|
|
*/
|
2019-01-18 02:52:58 +00:00
|
|
|
|
import { __, _n, _x, sprintf } from '@wordpress/i18n';
|
2018-10-11 08:30:51 +00:00
|
|
|
|
import { Component, Fragment } from '@wordpress/element';
|
2018-12-03 03:40:57 +00:00
|
|
|
|
import { map } from 'lodash';
|
2018-10-11 08:30:51 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2018-10-30 18:57:48 +00:00
|
|
|
|
* WooCommerce dependencies
|
2018-10-11 08:30:51 +00:00
|
|
|
|
*/
|
2019-01-14 09:54:44 +00:00
|
|
|
|
import { Date, Link, OrderStatus, ViewMoreList } from '@woocommerce/components';
|
2019-01-18 02:52:58 +00:00
|
|
|
|
import { defaultTableDateFormat } from '@woocommerce/date';
|
2018-12-03 03:40:57 +00:00
|
|
|
|
import { formatCurrency } from '@woocommerce/currency';
|
2019-01-29 16:48:46 +00:00
|
|
|
|
import { numberFormat } from '@woocommerce/number';
|
2018-10-30 18:57:48 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Internal dependencies
|
|
|
|
|
*/
|
2018-12-03 03:40:57 +00:00
|
|
|
|
import ReportTable from 'analytics/components/report-table';
|
2019-01-20 22:31:03 +00:00
|
|
|
|
import { getNewPath, getPersistedQuery } from '@woocommerce/navigation';
|
2018-10-18 10:43:45 +00:00
|
|
|
|
import './style.scss';
|
2018-10-11 08:30:51 +00:00
|
|
|
|
|
2019-01-18 02:52:58 +00:00
|
|
|
|
export default class OrdersReportTable extends Component {
|
2018-12-03 03:40:57 +00:00
|
|
|
|
constructor() {
|
|
|
|
|
super();
|
|
|
|
|
|
|
|
|
|
this.getHeadersContent = this.getHeadersContent.bind( this );
|
|
|
|
|
this.getRowsContent = this.getRowsContent.bind( this );
|
|
|
|
|
this.getSummary = this.getSummary.bind( this );
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-11 08:30:51 +00:00
|
|
|
|
getHeadersContent() {
|
|
|
|
|
return [
|
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
|
label: __( 'Date', 'woocommerce-admin' ),
|
2018-10-16 08:50:07 +00:00
|
|
|
|
key: 'date',
|
2018-10-11 08:30:51 +00:00
|
|
|
|
required: true,
|
|
|
|
|
defaultSort: true,
|
|
|
|
|
isLeftAligned: true,
|
|
|
|
|
isSortable: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
|
label: __( 'Order #', 'woocommerce-admin' ),
|
|
|
|
|
screenReaderLabel: __( 'Order Number', 'woocommerce-admin' ),
|
2019-02-28 14:14:21 +00:00
|
|
|
|
key: 'order_number',
|
2018-10-11 08:30:51 +00:00
|
|
|
|
required: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
|
label: __( 'Status', 'woocommerce-admin' ),
|
2018-10-11 08:30:51 +00:00
|
|
|
|
key: 'status',
|
|
|
|
|
required: false,
|
2018-10-16 08:50:07 +00:00
|
|
|
|
isSortable: false,
|
2018-10-11 08:30:51 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
|
label: __( 'Customer', 'woocommerce-admin' ),
|
2018-10-11 08:30:51 +00:00
|
|
|
|
key: 'customer_id',
|
|
|
|
|
required: false,
|
2018-10-16 08:50:07 +00:00
|
|
|
|
isSortable: false,
|
2018-10-11 08:30:51 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
|
label: __( 'Product(s)', 'woocommerce-admin' ),
|
|
|
|
|
screenReaderLabel: __( 'Products', 'woocommerce-admin' ),
|
2018-10-11 08:30:51 +00:00
|
|
|
|
key: 'products',
|
|
|
|
|
required: false,
|
|
|
|
|
isSortable: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
|
label: __( 'Items Sold', 'woocommerce-admin' ),
|
2019-02-15 10:54:41 +00:00
|
|
|
|
key: 'num_items_sold',
|
2018-10-11 08:30:51 +00:00
|
|
|
|
required: false,
|
2019-02-15 10:54:41 +00:00
|
|
|
|
isSortable: true,
|
2018-10-11 08:30:51 +00:00
|
|
|
|
isNumeric: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
|
label: __( 'Coupon(s)', 'woocommerce-admin' ),
|
|
|
|
|
screenReaderLabel: __( 'Coupons', 'woocommerce-admin' ),
|
2018-10-11 08:30:51 +00:00
|
|
|
|
key: 'coupons',
|
|
|
|
|
required: false,
|
|
|
|
|
isSortable: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
|
label: __( 'N. Revenue', 'woocommerce-admin' ),
|
|
|
|
|
screenReaderLabel: __( 'Net Revenue', 'woocommerce-admin' ),
|
2019-02-15 10:54:41 +00:00
|
|
|
|
key: 'net_total',
|
2018-10-11 08:30:51 +00:00
|
|
|
|
required: true,
|
2019-02-15 10:54:41 +00:00
|
|
|
|
isSortable: true,
|
2018-10-11 08:30:51 +00:00
|
|
|
|
isNumeric: true,
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getRowsContent( tableData ) {
|
2019-01-20 22:31:03 +00:00
|
|
|
|
const { query } = this.props;
|
|
|
|
|
const persistedQuery = getPersistedQuery( query );
|
2018-10-11 08:30:51 +00:00
|
|
|
|
return map( tableData, row => {
|
|
|
|
|
const {
|
2019-01-18 02:52:58 +00:00
|
|
|
|
currency,
|
|
|
|
|
customer_type,
|
|
|
|
|
date_created,
|
|
|
|
|
net_total,
|
|
|
|
|
num_items_sold,
|
|
|
|
|
order_id,
|
2019-02-28 14:14:21 +00:00
|
|
|
|
order_number,
|
2018-10-11 08:30:51 +00:00
|
|
|
|
status,
|
|
|
|
|
} = row;
|
2019-03-05 02:56:47 +00:00
|
|
|
|
const extended_info = row.extended_info || {};
|
2019-01-18 02:52:58 +00:00
|
|
|
|
const { coupons, products } = extended_info;
|
2018-10-11 08:30:51 +00:00
|
|
|
|
|
2019-01-18 02:52:58 +00:00
|
|
|
|
const formattedProducts = products
|
2018-10-12 21:29:25 +00:00
|
|
|
|
.sort( ( itemA, itemB ) => itemB.quantity - itemA.quantity )
|
|
|
|
|
.map( item => ( {
|
|
|
|
|
label: item.name,
|
|
|
|
|
quantity: item.quantity,
|
2019-01-20 22:31:03 +00:00
|
|
|
|
href: getNewPath( persistedQuery, 'products', {
|
|
|
|
|
filter: 'single_product',
|
|
|
|
|
products: item.id,
|
|
|
|
|
} ),
|
2018-10-12 21:29:25 +00:00
|
|
|
|
} ) );
|
|
|
|
|
|
2019-01-18 02:52:58 +00:00
|
|
|
|
const formattedCoupons = coupons.map( coupon => ( {
|
2018-10-12 21:29:25 +00:00
|
|
|
|
label: coupon.code,
|
2019-01-20 22:31:03 +00:00
|
|
|
|
href: getNewPath( persistedQuery, 'coupons', {
|
|
|
|
|
filter: 'single_coupon',
|
|
|
|
|
coupons: coupon.id,
|
|
|
|
|
} ),
|
2018-10-12 21:29:25 +00:00
|
|
|
|
} ) );
|
|
|
|
|
|
2018-10-11 08:30:51 +00:00
|
|
|
|
return [
|
|
|
|
|
{
|
2019-01-18 02:52:58 +00:00
|
|
|
|
display: <Date date={ date_created } visibleFormat={ defaultTableDateFormat } />,
|
|
|
|
|
value: date_created,
|
2018-10-11 08:30:51 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
2018-12-18 09:44:43 +00:00
|
|
|
|
display: (
|
2019-01-18 02:52:58 +00:00
|
|
|
|
<Link href={ 'post.php?post=' + order_id + '&action=edit' } type="wp-admin">
|
2019-02-28 14:14:21 +00:00
|
|
|
|
{ order_number }
|
2018-12-18 09:44:43 +00:00
|
|
|
|
</Link>
|
|
|
|
|
),
|
2019-02-28 14:14:21 +00:00
|
|
|
|
value: order_number,
|
2018-10-11 08:30:51 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
2018-10-18 10:43:45 +00:00
|
|
|
|
display: (
|
|
|
|
|
<OrderStatus className="woocommerce-orders-table__status" order={ { status } } />
|
|
|
|
|
),
|
2018-10-11 08:30:51 +00:00
|
|
|
|
value: status,
|
|
|
|
|
},
|
|
|
|
|
{
|
2019-01-18 02:52:58 +00:00
|
|
|
|
display:
|
|
|
|
|
customer_type === 'new'
|
2019-03-13 17:14:02 +00:00
|
|
|
|
? _x( 'New', 'customer type', 'woocommerce-admin' )
|
|
|
|
|
: _x( 'Returning', 'customer type', 'woocommerce-admin' ),
|
2019-01-18 02:52:58 +00:00
|
|
|
|
value: customer_type,
|
2018-10-11 08:30:51 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
display: this.renderList(
|
2019-01-18 02:52:58 +00:00
|
|
|
|
formattedProducts.length ? [ formattedProducts[ 0 ] ] : [],
|
|
|
|
|
formattedProducts.map( product => ( {
|
2019-03-13 17:14:02 +00:00
|
|
|
|
label: sprintf(
|
|
|
|
|
__( '%s× %s', 'woocommerce-admin' ),
|
|
|
|
|
product.quantity,
|
|
|
|
|
product.label
|
|
|
|
|
),
|
2018-10-12 21:29:25 +00:00
|
|
|
|
href: product.href,
|
2018-10-11 08:30:51 +00:00
|
|
|
|
} ) )
|
|
|
|
|
),
|
2019-01-18 02:52:58 +00:00
|
|
|
|
value: formattedProducts.map( product => product.label ).join( ' ' ),
|
2018-10-11 08:30:51 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
2019-01-18 02:52:58 +00:00
|
|
|
|
display: numberFormat( num_items_sold ),
|
|
|
|
|
value: num_items_sold,
|
2018-10-11 08:30:51 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
2019-01-18 02:52:58 +00:00
|
|
|
|
display: this.renderList(
|
|
|
|
|
formattedCoupons.length ? [ formattedCoupons[ 0 ] ] : [],
|
|
|
|
|
formattedCoupons
|
|
|
|
|
),
|
|
|
|
|
value: formattedCoupons.map( item => item.code ).join( ' ' ),
|
2018-10-11 08:30:51 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
2019-01-18 02:52:58 +00:00
|
|
|
|
display: formatCurrency( net_total, currency ),
|
|
|
|
|
value: net_total,
|
2018-10-11 08:30:51 +00:00
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
} );
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-31 19:09:38 +00:00
|
|
|
|
getSummary( totals ) {
|
2019-02-05 12:00:37 +00:00
|
|
|
|
const {
|
|
|
|
|
orders_count = 0,
|
|
|
|
|
num_new_customers = 0,
|
|
|
|
|
num_returning_customers = 0,
|
|
|
|
|
products = 0,
|
|
|
|
|
num_items_sold = 0,
|
|
|
|
|
coupons = 0,
|
|
|
|
|
net_revenue = 0,
|
|
|
|
|
} = totals;
|
2018-10-31 19:09:38 +00:00
|
|
|
|
return [
|
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
|
label: _n( 'order', 'orders', orders_count, 'woocommerce-admin' ),
|
2019-02-05 12:00:37 +00:00
|
|
|
|
value: numberFormat( orders_count ),
|
2018-10-31 19:09:38 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
|
label: _n( 'new customer', 'new customers', num_new_customers, 'woocommerce-admin' ),
|
2019-02-05 12:00:37 +00:00
|
|
|
|
value: numberFormat( num_new_customers ),
|
2018-10-31 19:09:38 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: _n(
|
|
|
|
|
'returning customer',
|
|
|
|
|
'returning customers',
|
2019-02-05 12:00:37 +00:00
|
|
|
|
num_returning_customers,
|
2019-03-13 17:14:02 +00:00
|
|
|
|
'woocommerce-admin'
|
2018-10-31 19:09:38 +00:00
|
|
|
|
),
|
2019-02-05 12:00:37 +00:00
|
|
|
|
value: numberFormat( num_returning_customers ),
|
2018-10-31 19:09:38 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
|
label: _n( 'product', 'products', products, 'woocommerce-admin' ),
|
2019-02-05 12:00:37 +00:00
|
|
|
|
value: numberFormat( products ),
|
2018-10-31 19:09:38 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
|
label: _n( 'item sold', 'items sold', num_items_sold, 'woocommerce-admin' ),
|
2019-02-05 12:00:37 +00:00
|
|
|
|
value: numberFormat( num_items_sold ),
|
2018-10-31 19:09:38 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
|
label: _n( 'coupon', 'coupons', coupons, 'woocommerce-admin' ),
|
2019-02-05 12:00:37 +00:00
|
|
|
|
value: numberFormat( coupons ),
|
2018-10-31 19:09:38 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
|
label: __( 'net revenue', 'woocommerce-admin' ),
|
2019-02-05 12:00:37 +00:00
|
|
|
|
value: formatCurrency( net_revenue ),
|
2018-10-31 19:09:38 +00:00
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-12 21:29:25 +00:00
|
|
|
|
renderLinks( items = [] ) {
|
2018-10-18 20:45:59 +00:00
|
|
|
|
return items.map( ( item, i ) => (
|
2019-01-20 22:31:03 +00:00
|
|
|
|
<Link href={ item.href } key={ i } type="wc-admin">
|
2018-10-12 21:29:25 +00:00
|
|
|
|
{ item.label }
|
|
|
|
|
</Link>
|
2018-10-11 08:30:51 +00:00
|
|
|
|
) );
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-12 21:29:25 +00:00
|
|
|
|
renderList( visibleItems, popoverItems ) {
|
|
|
|
|
return (
|
|
|
|
|
<Fragment>
|
|
|
|
|
{ this.renderLinks( visibleItems ) }
|
|
|
|
|
{ popoverItems.length > 1 && <ViewMoreList items={ this.renderLinks( popoverItems ) } /> }
|
|
|
|
|
</Fragment>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-29 07:57:05 +00:00
|
|
|
|
render() {
|
2019-01-18 02:52:58 +00:00
|
|
|
|
const { query } = this.props;
|
2018-10-11 08:30:51 +00:00
|
|
|
|
|
|
|
|
|
return (
|
2018-12-03 03:40:57 +00:00
|
|
|
|
<ReportTable
|
|
|
|
|
endpoint="orders"
|
|
|
|
|
getHeadersContent={ this.getHeadersContent }
|
|
|
|
|
getRowsContent={ this.getRowsContent }
|
|
|
|
|
getSummary={ this.getSummary }
|
|
|
|
|
query={ query }
|
2019-01-18 02:52:58 +00:00
|
|
|
|
tableQuery={ {
|
|
|
|
|
extended_info: true,
|
|
|
|
|
} }
|
2019-03-13 17:14:02 +00:00
|
|
|
|
title={ __( 'Orders', 'woocommerce-admin' ) }
|
2018-12-13 20:34:23 +00:00
|
|
|
|
columnPrefsKey="orders_report_columns"
|
2018-10-11 08:30:51 +00:00
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
2018-10-29 07:57:05 +00:00
|
|
|
|
}
|