PHPCS fixes for class-wc-report-sales-by-product
This commit is contained in:
parent
02841582de
commit
e8b9ad7e17
|
@ -1,7 +1,12 @@
|
|||
<?php
|
||||
/**
|
||||
* Sales By Product Reporting
|
||||
*
|
||||
* @package WooCommerce/Admin/Reporting
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -48,6 +53,7 @@ class WC_Report_Sales_By_Product extends WC_Admin_Report {
|
|||
|
||||
/**
|
||||
* Get the legend for the main chart sidebar.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_chart_legend() {
|
||||
|
@ -136,7 +142,7 @@ class WC_Report_Sales_By_Product extends WC_Admin_Report {
|
|||
'item_count' => '#d4d9dc',
|
||||
);
|
||||
|
||||
$current_range = ! empty( $_GET['range'] ) ? sanitize_text_field( $_GET['range'] ) : '7day';
|
||||
$current_range = ! empty( $_GET['range'] ) ? sanitize_text_field( wp_unslash( $_GET['range'] ) ) : '7day';
|
||||
|
||||
if ( ! in_array( $current_range, array( 'custom', 'year', 'last_month', 'month', '7day' ) ) ) {
|
||||
$current_range = '7day';
|
||||
|
@ -190,8 +196,8 @@ class WC_Report_Sales_By_Product extends WC_Admin_Report {
|
|||
}
|
||||
}
|
||||
|
||||
echo '<p>' . ' <strong>' . esc_html( implode( ', ', $this->product_ids_titles ) ) . '</strong></p>';
|
||||
echo '<p><a class="button" href="' . esc_url( remove_query_arg( 'product_ids' ) ) . '">' . __( 'Reset', 'woocommerce' ) . '</a></p>';
|
||||
echo '<p><strong>' . esc_html( implode( ', ', $this->product_ids_titles ) ) . '</strong></p>';
|
||||
echo '<p><a class="button" href="' . esc_url( remove_query_arg( 'product_ids' ) ) . '">' . esc_html__( 'Reset', 'woocommerce' ) . '</a></p>';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -199,10 +205,11 @@ class WC_Report_Sales_By_Product extends WC_Admin_Report {
|
|||
*/
|
||||
public function products_widget() {
|
||||
?>
|
||||
<h4 class="section_title"><span><?php _e( 'Product search', 'woocommerce' ); ?></span></h4>
|
||||
<h4 class="section_title"><span><?php esc_html_e( 'Product search', 'woocommerce' ); ?></span></h4>
|
||||
<div class="section">
|
||||
<form method="GET">
|
||||
<div>
|
||||
<?php // @codingStandardsIgnoreStart ?>
|
||||
<select class="wc-product-search" style="width:203px;" multiple="multiple" id="product_ids" name="product_ids[]" data-placeholder="<?php esc_attr_e( 'Search for a product…', 'woocommerce' ); ?>" data-action="woocommerce_json_search_products_and_variations"></select>
|
||||
<input type="submit" class="submit button" value="<?php esc_attr_e( 'Show', 'woocommerce' ); ?>" />
|
||||
<input type="hidden" name="range" value="<?php echo ( ! empty( $_GET['range'] ) ) ? esc_attr( $_GET['range'] ) : ''; ?>" />
|
||||
|
@ -212,10 +219,11 @@ class WC_Report_Sales_By_Product extends WC_Admin_Report {
|
|||
<input type="hidden" name="tab" value="<?php echo ( ! empty( $_GET['tab'] ) ) ? esc_attr( $_GET['tab'] ) : ''; ?>" />
|
||||
<input type="hidden" name="report" value="<?php echo ( ! empty( $_GET['report'] ) ) ? esc_attr( $_GET['report'] ) : ''; ?>" />
|
||||
<?php wp_nonce_field( 'custom_range', 'wc_reports_nonce', false ); ?>
|
||||
<?php // @codingStandardsIgnoreEnd ?>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<h4 class="section_title"><span><?php _e( 'Top sellers', 'woocommerce' ); ?></span></h4>
|
||||
<h4 class="section_title"><span><?php esc_html_e( 'Top sellers', 'woocommerce' ); ?></span></h4>
|
||||
<div class="section">
|
||||
<table cellspacing="0">
|
||||
<?php
|
||||
|
@ -242,20 +250,22 @@ class WC_Report_Sales_By_Product extends WC_Admin_Report {
|
|||
) );
|
||||
|
||||
if ( $top_sellers ) {
|
||||
// @codingStandardsIgnoreStart
|
||||
foreach ( $top_sellers as $product ) {
|
||||
echo '<tr class="' . ( in_array( $product->product_id, $this->product_ids ) ? 'active' : '' ) . '">
|
||||
<td class="count">' . $product->order_item_qty . '</td>
|
||||
<td class="count">' . esc_html( $product->order_item_qty ) . '</td>
|
||||
<td class="name"><a href="' . esc_url( add_query_arg( 'product_ids', $product->product_id ) ) . '">' . esc_html( get_the_title( $product->product_id ) ) . '</a></td>
|
||||
<td class="sparkline">' . $this->sales_sparkline( $product->product_id, 7, 'count' ) . '</td>
|
||||
</tr>';
|
||||
}
|
||||
// @codingStandardsIgnoreEnd
|
||||
} else {
|
||||
echo '<tr><td colspan="3">' . __( 'No products found in range', 'woocommerce' ) . '</td></tr>';
|
||||
echo '<tr><td colspan="3">' . esc_html__( 'No products found in range', 'woocommerce' ) . '</td></tr>';
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
</div>
|
||||
<h4 class="section_title"><span><?php _e( 'Top freebies', 'woocommerce' ); ?></span></h4>
|
||||
<h4 class="section_title"><span><?php esc_html_e( 'Top freebies', 'woocommerce' ); ?></span></h4>
|
||||
<div class="section">
|
||||
<table cellspacing="0">
|
||||
<?php
|
||||
|
@ -290,20 +300,22 @@ class WC_Report_Sales_By_Product extends WC_Admin_Report {
|
|||
) );
|
||||
|
||||
if ( $top_freebies ) {
|
||||
// @codingStandardsIgnoreStart
|
||||
foreach ( $top_freebies as $product ) {
|
||||
echo '<tr class="' . ( in_array( $product->product_id, $this->product_ids ) ? 'active' : '' ) . '">
|
||||
<td class="count">' . $product->order_item_qty . '</td>
|
||||
<td class="count">' . esc_html( $product->order_item_qty ) . '</td>
|
||||
<td class="name"><a href="' . esc_url( add_query_arg( 'product_ids', $product->product_id ) ) . '">' . esc_html( get_the_title( $product->product_id ) ) . '</a></td>
|
||||
<td class="sparkline">' . $this->sales_sparkline( $product->product_id, 7, 'count' ) . '</td>
|
||||
</tr>';
|
||||
}
|
||||
// @codingStandardsIgnoreEnd
|
||||
} else {
|
||||
echo '<tr><td colspan="3">' . __( 'No products found in range', 'woocommerce' ) . '</td></tr>';
|
||||
echo '<tr><td colspan="3">' . esc_html__( 'No products found in range', 'woocommerce' ) . '</td></tr>';
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
</div>
|
||||
<h4 class="section_title"><span><?php _e( 'Top earners', 'woocommerce' ); ?></span></h4>
|
||||
<h4 class="section_title"><span><?php esc_html_e( 'Top earners', 'woocommerce' ); ?></span></h4>
|
||||
<div class="section">
|
||||
<table cellspacing="0">
|
||||
<?php
|
||||
|
@ -330,6 +342,7 @@ class WC_Report_Sales_By_Product extends WC_Admin_Report {
|
|||
) );
|
||||
|
||||
if ( $top_earners ) {
|
||||
// @codingStandardsIgnoreStart
|
||||
foreach ( $top_earners as $product ) {
|
||||
echo '<tr class="' . ( in_array( $product->product_id, $this->product_ids ) ? 'active' : '' ) . '">
|
||||
<td class="count">' . wc_price( $product->order_item_total ) . '</td>
|
||||
|
@ -337,8 +350,9 @@ class WC_Report_Sales_By_Product extends WC_Admin_Report {
|
|||
<td class="sparkline">' . $this->sales_sparkline( $product->product_id, 7, 'sales' ) . '</td>
|
||||
</tr>';
|
||||
}
|
||||
// @codingStandardsIgnoreEnd
|
||||
} else {
|
||||
echo '<tr><td colspan="3">' . __( 'No products found in range', 'woocommerce' ) . '</td></tr>';
|
||||
echo '<tr><td colspan="3">' . esc_html__( 'No products found in range', 'woocommerce' ) . '</td></tr>';
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
|
@ -370,17 +384,17 @@ class WC_Report_Sales_By_Product extends WC_Admin_Report {
|
|||
*/
|
||||
public function get_export_button() {
|
||||
|
||||
$current_range = ! empty( $_GET['range'] ) ? sanitize_text_field( $_GET['range'] ) : '7day';
|
||||
$current_range = ! empty( $_GET['range'] ) ? sanitize_text_field( wp_unslash( $_GET['range'] ) ) : '7day';
|
||||
?>
|
||||
<a
|
||||
href="#"
|
||||
download="report-<?php echo esc_attr( $current_range ); ?>-<?php echo date_i18n( 'Y-m-d', current_time( 'timestamp' ) ); ?>.csv"
|
||||
download="report-<?php echo esc_attr( $current_range ); ?>-<?php echo esc_html( date_i18n( 'Y-m-d', current_time( 'timestamp' ) ) ); ?>.csv"
|
||||
class="export_csv"
|
||||
data-export="chart"
|
||||
data-xaxes="<?php esc_attr_e( 'Date', 'woocommerce' ); ?>"
|
||||
data-groupby="<?php echo $this->chart_groupby; ?>"
|
||||
data-groupby="<?php echo $this->chart_groupby; ?>"<?php // @codingStandardsIgnoreLine ?>
|
||||
>
|
||||
<?php _e( 'Export CSV', 'woocommerce' ); ?>
|
||||
<?php esc_html_e( 'Export CSV', 'woocommerce' ); ?>
|
||||
</a>
|
||||
<?php
|
||||
}
|
||||
|
@ -394,11 +408,11 @@ class WC_Report_Sales_By_Product extends WC_Admin_Report {
|
|||
if ( empty( $this->product_ids ) ) {
|
||||
?>
|
||||
<div class="chart-container">
|
||||
<p class="chart-prompt"><?php _e( 'Choose a product to view stats', 'woocommerce' ); ?></p>
|
||||
<p class="chart-prompt"><?php esc_html_e( 'Choose a product to view stats', 'woocommerce' ); ?></p>
|
||||
</div>
|
||||
<?php
|
||||
} else {
|
||||
// Get orders and dates in range - we want the SUM of order totals, COUNT of order items, COUNT of orders, and the date
|
||||
// Get orders and dates in range - we want the SUM of order totals, COUNT of order items, COUNT of orders, and the date.
|
||||
$order_item_counts = $this->get_order_report_data( array(
|
||||
'data' => array(
|
||||
'_qty' => array(
|
||||
|
@ -469,11 +483,11 @@ class WC_Report_Sales_By_Product extends WC_Admin_Report {
|
|||
'filter_range' => true,
|
||||
) );
|
||||
|
||||
// Prepare data for report
|
||||
// Prepare data for report.
|
||||
$order_item_counts = $this->prepare_chart_data( $order_item_counts, 'post_date', 'order_item_count', $this->chart_interval, $this->start_date, $this->chart_groupby );
|
||||
$order_item_amounts = $this->prepare_chart_data( $order_item_amounts, 'post_date', 'order_item_amount', $this->chart_interval, $this->start_date, $this->chart_groupby );
|
||||
|
||||
// Encode in json format
|
||||
// Encode in json format.
|
||||
$chart_data = json_encode( array(
|
||||
'order_item_counts' => array_values( $order_item_counts ),
|
||||
'order_item_amounts' => array_values( $order_item_amounts ),
|
||||
|
@ -482,6 +496,7 @@ class WC_Report_Sales_By_Product extends WC_Admin_Report {
|
|||
<div class="chart-container">
|
||||
<div class="chart-placeholder main"></div>
|
||||
</div>
|
||||
<?php // @codingStandardsIgnoreStart ?>
|
||||
<script type="text/javascript">
|
||||
var main_chart;
|
||||
|
||||
|
@ -586,6 +601,7 @@ class WC_Report_Sales_By_Product extends WC_Admin_Report {
|
|||
});
|
||||
</script>
|
||||
<?php
|
||||
// @codingStandardsIgnoreEnd
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue