* issue fix woocommerce/woocommerce-admin#1801 SKU filter issue fixed.

* make is sortable true.

* phpcs error fix.

* Fix PHPCS errors and warnings.

* Fix PHPCS errors and warnings.

* Update client/analytics/report/products/table-variations.js

Co-Authored-By: ronakganatra9 <ronakganatra9@gmail.com>

* Update includes/data-stores/class-wc-admin-reports-variations-data-store.php

Co-Authored-By: ronakganatra9 <ronakganatra9@gmail.com>

* changed postmeta.meta_value to meta_value
This commit is contained in:
ronakganatra9 2019-04-01 00:23:48 +05:30 committed by Albert Juhé Lluveras
parent 6ff9d0673a
commit 3cddc714c6
3 changed files with 40 additions and 2 deletions

View File

@ -40,6 +40,7 @@ export default class VariationsReportTable extends Component {
label: __( 'SKU', 'woocommerce-admin' ),
key: 'sku',
hiddenByDefault: true,
isSortable: true,
},
{
label: __( 'Items Sold', 'woocommerce-admin' ),

View File

@ -293,6 +293,7 @@ class WC_Admin_REST_Reports_Variations_Controller extends WC_REST_Reports_Contro
'net_revenue',
'orders_count',
'items_sold',
'sku',
),
'validate_callback' => 'rest_validate_request_arg',
);

View File

@ -78,11 +78,41 @@ class WC_Admin_Reports_Variations_Data_Store extends WC_Admin_Reports_Data_Store
$this->report_columns['orders_count'] = str_replace( 'order_id', $table_name . '.order_id', $this->report_columns['orders_count'] );
}
/**
* Fills ORDER BY clause of SQL request based on user supplied parameters.
*
* @param array $query_args Parameters supplied by the user.
*
* @return array
*/
protected function get_order_by_sql_params( $query_args ) {
global $wpdb;
$order_product_lookup_table = $wpdb->prefix . self::TABLE_NAME;
$sql_query['order_by_clause'] = '';
if ( isset( $query_args['orderby'] ) ) {
$sql_query['order_by_clause'] = $this->normalize_order_by( $query_args['orderby'] );
}
if ( 'meta_value' === $sql_query['order_by_clause'] ) {
$sql_query['from_clause'] .= " JOIN {$wpdb->prefix}postmeta AS postmeta ON {$order_product_lookup_table}.variation_id = postmeta.post_id AND postmeta.meta_key = '_sku'";
}
if ( isset( $query_args['order'] ) ) {
$sql_query['order_by_clause'] .= ' ' . $query_args['order'];
} else {
$sql_query['order_by_clause'] .= ' DESC';
}
return $sql_query;
}
/**
* Updates the database query with parameters used for Products report: categories and order status.
*
* @param array $query_args Query arguments supplied by the user.
* @param string $from_arg Name of the FROM sql param.
*
* @return array Array of parameters used for SQL query.
*/
protected function get_sql_query_params( $query_args, $from_arg ) {
@ -118,6 +148,7 @@ class WC_Admin_Reports_Variations_Data_Store extends WC_Admin_Reports_Data_Store
* Maps ordering specified by the user to columns in the database/fields in the data.
*
* @param string $order_by Sorting criterion.
*
* @return string
*/
protected function normalize_order_by( $order_by ) {
@ -127,6 +158,9 @@ class WC_Admin_Reports_Variations_Data_Store extends WC_Admin_Reports_Data_Store
if ( 'date' === $order_by ) {
return $table_name . '.date_created';
}
if ( 'sku' === $order_by ) {
return 'meta_value';
}
return $order_by;
}
@ -184,6 +218,7 @@ class WC_Admin_Reports_Variations_Data_Store extends WC_Admin_Reports_Data_Store
* Returns the report data based on parameters supplied by the user.
*
* @param array $query_args Query parameters.
*
* @return stdClass|WP_Error Data.
*/
public function get_data( $query_args ) {
@ -317,6 +352,7 @@ class WC_Admin_Reports_Variations_Data_Store extends WC_Admin_Reports_Data_Store
* Returns string to be used as cache key for the data.
*
* @param array $params Query parameters.
*
* @return string
*/
protected function get_cache_key( $params ) {