by category
This commit is contained in:
parent
6f5200de1b
commit
72bb335662
|
@ -1510,322 +1510,3 @@ function woocommerce_monthly_taxes() {
|
|||
<?php
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* woocommerce_category_sales function.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function woocommerce_category_sales() {
|
||||
global $start_date, $end_date, $woocommerce, $wpdb, $wp_locale;
|
||||
|
||||
$first_year = $wpdb->get_var( "SELECT post_date FROM $wpdb->posts WHERE post_date != 0 ORDER BY post_date ASC LIMIT 1;" );
|
||||
$first_year = ( $first_year ) ? date( 'Y', strtotime( $first_year ) ) : date( 'Y' );
|
||||
|
||||
$current_year = isset( $_POST['show_year'] ) ? $_POST['show_year'] : date( 'Y', current_time( 'timestamp' ) );
|
||||
|
||||
$categories = get_terms( 'product_cat', array( 'orderby' => 'name' ) );
|
||||
?>
|
||||
<form method="post" action="" class="report_filters">
|
||||
<p>
|
||||
<label for="show_year"><?php _e( 'Show:', 'woocommerce' ); ?></label>
|
||||
<select name="show_year" id="show_year">
|
||||
<?php
|
||||
for ( $i = $first_year; $i <= date( 'Y' ); $i++ )
|
||||
printf( '<option value="%s" %s>%s</option>', $i, selected( $current_year, $i, false ), $i );
|
||||
?>
|
||||
</select>
|
||||
|
||||
<select multiple="multiple" class="chosen_select" id="show_categories" name="show_categories[]" style="width: 300px;">
|
||||
<?php
|
||||
$r = array();
|
||||
$r['pad_counts'] = 1;
|
||||
$r['hierarchal'] = 1;
|
||||
$r['hide_empty'] = 1;
|
||||
$r['value'] = 'id';
|
||||
$r['selected'] = isset( $_POST['show_categories'] ) ? $_POST['show_categories'] : '';
|
||||
|
||||
include_once( $woocommerce->plugin_path() . '/includes/walkers/class-product-cat-dropdown-walker.php' );
|
||||
|
||||
echo woocommerce_walk_category_dropdown_tree( $categories, 0, $r );
|
||||
?>
|
||||
</select>
|
||||
|
||||
<input type="submit" class="button" value="<?php _e( 'Show', 'woocommerce' ); ?>" />
|
||||
</p>
|
||||
</form>
|
||||
<?php
|
||||
|
||||
$item_sales = array();
|
||||
|
||||
// Get order items
|
||||
$order_items = apply_filters( 'woocommerce_reports_category_sales_order_items', $wpdb->get_results( $wpdb->prepare( "
|
||||
SELECT order_item_meta_2.meta_value as product_id, posts.post_date, SUM( order_item_meta.meta_value ) as line_total
|
||||
FROM {$wpdb->prefix}woocommerce_order_items as order_items
|
||||
|
||||
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id
|
||||
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta_2 ON order_items.order_item_id = order_item_meta_2.order_item_id
|
||||
LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID
|
||||
LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID = rel.object_ID
|
||||
LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id )
|
||||
LEFT JOIN {$wpdb->terms} AS term USING( term_id )
|
||||
|
||||
WHERE posts.post_type = 'shop_order'
|
||||
AND posts.post_status = 'publish'
|
||||
AND tax.taxonomy = 'shop_order_status'
|
||||
AND term.slug IN ('" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "')
|
||||
AND date_format(posts.post_date,'%%Y') = %s
|
||||
AND order_items.order_item_type = 'line_item'
|
||||
AND order_item_meta.meta_key = '_line_total'
|
||||
AND order_item_meta_2.meta_key = '_product_id'
|
||||
GROUP BY order_items.order_item_id
|
||||
ORDER BY posts.post_date ASC
|
||||
", $current_year ) ) );
|
||||
|
||||
if ( $order_items ) {
|
||||
foreach ( $order_items as $order_item ) {
|
||||
|
||||
$month = date( 'm', strtotime( $order_item->post_date ) ) - 1;
|
||||
|
||||
$item_sales[ $month ][ $order_item->product_id ] = isset( $item_sales[ $month ][ $order_item->product_id ] ) ? $item_sales[ $month ][ $order_item->product_id ] + $order_item->line_total : $order_item->line_total;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $_POST['show_categories'] ) && sizeof( $_POST['show_categories'] ) > 0 ) {
|
||||
|
||||
$show_categories = $include_categories = array_map( 'absint', $_POST['show_categories'] );
|
||||
|
||||
foreach( $show_categories as $cat )
|
||||
$include_categories = array_merge( $include_categories, get_term_children( $cat, 'product_cat' ) );
|
||||
|
||||
$categories = get_terms( 'product_cat', array( 'include' => array_unique( $include_categories ) ) );
|
||||
?>
|
||||
<div class="woocommerce-wide-reports-wrap">
|
||||
<table class="widefat">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?php _e( 'Category', 'woocommerce' ); ?></th>
|
||||
<?php
|
||||
$column_count = 0;
|
||||
for ( $count = 0; $count < 12; $count++ ) :
|
||||
if ( $count >= date ( 'm' ) && $current_year == date( 'Y' ) )
|
||||
continue;
|
||||
$column_count++;
|
||||
?>
|
||||
<th><?php echo date( 'F', strtotime( '2012-' . ( $count + 1 ) . '-01' ) ); ?></th>
|
||||
<?php endfor; ?>
|
||||
<th><strong><?php _e( 'Total', 'woocommerce' ); ?></strong></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><?php
|
||||
// While outputting, lets store them for the chart
|
||||
$chart_data = $month_totals = $category_totals = array();
|
||||
$top_cat = $bottom_cat = $top_cat_name = $bottom_cat_name = '';
|
||||
|
||||
for ( $count = 0; $count < 12; $count++ )
|
||||
if ( $count >= date( 'm' ) && $current_year == date( 'Y' ) )
|
||||
break;
|
||||
else
|
||||
$month_totals[ $count ] = 0;
|
||||
|
||||
foreach ( $categories as $category ) {
|
||||
|
||||
$cat_total = 0;
|
||||
$category_chart_data = $term_ids = array();
|
||||
|
||||
$term_ids = get_term_children( $category->term_id, 'product_cat' );
|
||||
$term_ids[] = $category->term_id;
|
||||
$product_ids = get_objects_in_term( $term_ids, 'product_cat' );
|
||||
|
||||
if ( $category->parent > 0 )
|
||||
$prepend = '— ';
|
||||
else
|
||||
$prepend = '';
|
||||
|
||||
$category_sales_html = '<tr><th>' . $prepend . $category->name . '</th>';
|
||||
|
||||
for ( $count = 0; $count < 12; $count++ ) {
|
||||
|
||||
if ( $count >= date( 'm' ) && $current_year == date( 'Y' ) )
|
||||
continue;
|
||||
|
||||
if ( ! empty( $item_sales[ $count ] ) ) {
|
||||
$matches = array_intersect_key( $item_sales[ $count ], array_flip( $product_ids ) );
|
||||
$total = array_sum( $matches );
|
||||
$cat_total += $total;
|
||||
} else {
|
||||
$total = 0;
|
||||
}
|
||||
|
||||
if ( sizeof( array_intersect( $include_categories, get_ancestors( $category->term_id, 'product_cat' ) ) ) == 0 )
|
||||
$month_totals[ $count ] += $total;
|
||||
|
||||
$category_sales_html .= '<td>' . woocommerce_price( $total ) . '</td>';
|
||||
|
||||
$category_chart_data[] = array( strtotime( date( 'Ymd', strtotime( '2012-' . ( $count + 1 ) . '-01' ) ) ) . '000', $total );
|
||||
}
|
||||
|
||||
if ( $cat_total == 0 )
|
||||
continue;
|
||||
|
||||
$category_totals[] = $cat_total;
|
||||
|
||||
$category_sales_html .= '<td><strong>' . woocommerce_price( $cat_total ) . '</strong></td>';
|
||||
|
||||
$category_sales_html .= '</tr>';
|
||||
|
||||
echo $category_sales_html;
|
||||
|
||||
$chart_data[ $category->name ] = $category_chart_data;
|
||||
|
||||
if ( $cat_total > $top_cat ) {
|
||||
$top_cat = $cat_total;
|
||||
$top_cat_name = $category->name;
|
||||
}
|
||||
|
||||
if ( $cat_total < $bottom_cat || $bottom_cat === '' ) {
|
||||
$bottom_cat = $cat_total;
|
||||
$bottom_cat_name = $category->name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sort( $category_totals );
|
||||
|
||||
echo '<tr><th><strong>' . __( 'Total', 'woocommerce' ) . '</strong></th>';
|
||||
for ( $count = 0; $count < 12; $count++ )
|
||||
if ( $count >= date( 'm' ) && $current_year == date( 'Y' ) )
|
||||
break;
|
||||
else
|
||||
echo '<td><strong>' . woocommerce_price( $month_totals[ $count ] ) . '</strong></td>';
|
||||
echo '<td><strong>' . woocommerce_price( array_sum( $month_totals ) ) . '</strong></td></tr>';
|
||||
|
||||
?></tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div id="poststuff" class="woocommerce-reports-wrap">
|
||||
<div class="woocommerce-reports-sidebar">
|
||||
<div class="postbox">
|
||||
<h3><span><?php _e( 'Top category', 'woocommerce' ); ?></span></h3>
|
||||
<div class="inside">
|
||||
<p class="stat"><?php
|
||||
echo $top_cat_name . ' (' . woocommerce_price( $top_cat ) . ')';
|
||||
?></p>
|
||||
</div>
|
||||
</div>
|
||||
<?php if ( sizeof( $category_totals ) > 1 ) : ?>
|
||||
<div class="postbox">
|
||||
<h3><span><?php _e( 'Worst category', 'woocommerce' ); ?></span></h3>
|
||||
<div class="inside">
|
||||
<p class="stat"><?php
|
||||
echo $bottom_cat_name . ' (' . woocommerce_price( $bottom_cat ) . ')';
|
||||
?></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="postbox">
|
||||
<h3><span><?php _e( 'Category sales average', 'woocommerce' ); ?></span></h3>
|
||||
<div class="inside">
|
||||
<p class="stat"><?php
|
||||
if ( sizeof( $category_totals ) > 0 )
|
||||
echo woocommerce_price( array_sum( $category_totals ) / sizeof( $category_totals ) );
|
||||
else
|
||||
echo __( 'N/A', 'woocommerce' );
|
||||
?></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="postbox">
|
||||
<h3><span><?php _e( 'Category sales median', 'woocommerce' ); ?></span></h3>
|
||||
<div class="inside">
|
||||
<p class="stat"><?php
|
||||
if ( sizeof( $category_totals ) == 0 )
|
||||
echo __( 'N/A', 'woocommerce' );
|
||||
elseif ( sizeof( $category_totals ) % 2 )
|
||||
echo woocommerce_price(
|
||||
(
|
||||
$category_totals[ floor( sizeof( $category_totals ) / 2 ) ] + $category_totals[ ceil( sizeof( $category_totals ) / 2 ) ]
|
||||
) / 2
|
||||
);
|
||||
else
|
||||
echo woocommerce_price( $category_totals[ sizeof( $category_totals ) / 2 ] );
|
||||
?></p>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="woocommerce-reports-main">
|
||||
<div class="postbox">
|
||||
<h3><span><?php _e( 'Monthly sales by category', 'woocommerce' ); ?></span></h3>
|
||||
<div class="inside chart">
|
||||
<div id="placeholder" style="width:100%; overflow:hidden; height:568px; position:relative;"></div>
|
||||
<div id="chart-legend"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
jQuery(function(){
|
||||
|
||||
<?php
|
||||
// Variables
|
||||
foreach ( $chart_data as $name => $data ) {
|
||||
$varname = 'cat_' . str_replace( '-', '_', sanitize_title( $name ) ) . '_data';
|
||||
echo 'var ' . $varname . ' = jQuery.parseJSON( \'' . json_encode( $data ) . '\' );';
|
||||
}
|
||||
?>
|
||||
|
||||
var placeholder = jQuery("#placeholder");
|
||||
|
||||
var plot = jQuery.plot(placeholder, [
|
||||
<?php
|
||||
$labels = array();
|
||||
|
||||
foreach ( $chart_data as $name => $data ) {
|
||||
$labels[] = '{ label: "' . esc_js( $name ) . '", data: ' . 'cat_' . str_replace( '-', '_', sanitize_title( $name ) ) . '_data }';
|
||||
}
|
||||
|
||||
echo implode( ',', $labels );
|
||||
?>
|
||||
], {
|
||||
legend: {
|
||||
container: jQuery('#chart-legend'),
|
||||
noColumns: 2
|
||||
},
|
||||
series: {
|
||||
lines: { show: true, fill: true },
|
||||
points: { show: true, align: "left" }
|
||||
},
|
||||
grid: {
|
||||
show: true,
|
||||
aboveData: false,
|
||||
color: '#aaa',
|
||||
backgroundColor: '#fff',
|
||||
borderWidth: 2,
|
||||
borderColor: '#aaa',
|
||||
clickable: false,
|
||||
hoverable: true
|
||||
},
|
||||
xaxis: {
|
||||
mode: "time",
|
||||
timeformat: "%b",
|
||||
monthNames: <?php echo json_encode( array_values( $wp_locale->month_abbrev ) ) ?>,
|
||||
tickLength: 1,
|
||||
minTickSize: [1, "month"]
|
||||
},
|
||||
yaxes: [ { min: 0, tickDecimals: 2 } ]
|
||||
});
|
||||
|
||||
placeholder.resize();
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
jQuery(function(){
|
||||
jQuery("select.chosen_select").chosen();
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
|
|
@ -25,26 +25,31 @@ class WC_Report_Sales_By_Category extends WC_Admin_Report {
|
|||
return array();
|
||||
|
||||
$legend = array();
|
||||
$total = 0;
|
||||
$found_ids = array();
|
||||
$index = 0;
|
||||
|
||||
foreach( $this->show_categories as $category ) {
|
||||
$term_ids = get_term_children( $category, 'product_cat' );
|
||||
$term_ids[] = $category;
|
||||
$product_ids = get_objects_in_term( $term_ids, 'product_cat' );
|
||||
$category = get_term( $category, 'product_cat' );
|
||||
$term_ids = get_term_children( $category->term_id, 'product_cat' );
|
||||
$term_ids[] = $category->term_id;
|
||||
$total = 0;
|
||||
$product_ids = array_unique( get_objects_in_term( $term_ids, 'product_cat' ) );
|
||||
|
||||
foreach ( $product_ids as $id ) {
|
||||
if ( ! in_array( $id, $found_ids ) && isset( $this->item_sales[ $id ] ) ) {
|
||||
if ( isset( $this->item_sales[ $id ] ) ) {
|
||||
$total += $this->item_sales[ $id ];
|
||||
$found_ids[] = $id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$legend[] = array(
|
||||
'title' => sprintf( __( '%s sales in the selected categories', 'woocommerce' ), '<strong>' . woocommerce_price( $total ) . '</strong>' ),
|
||||
'color' => $this->chart_colours['sales_amount']
|
||||
);
|
||||
if ( ! $total )
|
||||
continue;
|
||||
|
||||
$legend[] = array(
|
||||
'title' => sprintf( __( '%s sales in %s', 'woocommerce' ), '<strong>' . woocommerce_price( $total ) . '</strong>', $category->name ),
|
||||
'color' => isset( $this->chart_colours[ $index ] ) ? $this->chart_colours[ $index ] : $this->chart_colours[ 0 ]
|
||||
);
|
||||
|
||||
$index++;
|
||||
}
|
||||
|
||||
return $legend;
|
||||
}
|
||||
|
@ -62,10 +67,7 @@ class WC_Report_Sales_By_Category extends WC_Admin_Report {
|
|||
'7day' => __( 'Last 7 Days', 'woocommerce' )
|
||||
);
|
||||
|
||||
$this->chart_colours = array(
|
||||
'sales_amount' => '#3498db',
|
||||
'item_count' => '#d4d9dc',
|
||||
);
|
||||
$this->chart_colours = array( '#3498db', '#9b59b6', '#34495e', '#1abc9c', '#2ecc71', '#f1c40f', '#e67e22', '#e74c3c', '#2980b9', '#8e44ad', '#2c3e50', '#16a085', '#27ae60', '#f39c12', '#d35400', '#c0392b' );
|
||||
|
||||
$current_range = ! empty( $_GET['range'] ) ? $_GET['range'] : '7day';
|
||||
|
||||
|
@ -83,8 +85,8 @@ class WC_Report_Sales_By_Category extends WC_Admin_Report {
|
|||
$interval ++;
|
||||
}
|
||||
|
||||
// 3 months max for day view
|
||||
if ( $interval > 3 )
|
||||
// 1 months max for day view
|
||||
if ( $interval > 1 )
|
||||
$this->chart_groupby = 'month';
|
||||
else
|
||||
$this->chart_groupby = 'day';
|
||||
|
@ -112,6 +114,24 @@ class WC_Report_Sales_By_Category extends WC_Admin_Report {
|
|||
break;
|
||||
}
|
||||
|
||||
// Group by
|
||||
switch ( $this->chart_groupby ) {
|
||||
case 'day' :
|
||||
$this->group_by_query = 'YEAR(post_date), MONTH(post_date), DAY(post_date)';
|
||||
$this->chart_interval = max( 0, ( $this->end_date - $this->start_date ) / ( 60 * 60 * 24 ) );
|
||||
$this->barwidth = 60 * 60 * 24 * 1000;
|
||||
break;
|
||||
case 'month' :
|
||||
$this->group_by_query = 'YEAR(post_date), MONTH(post_date)';
|
||||
$this->chart_interval = 0;
|
||||
$min_date = $this->start_date;
|
||||
while ( ( $min_date = strtotime( "+1 MONTH", $min_date ) ) <= $this->end_date ) {
|
||||
$this->chart_interval ++;
|
||||
}
|
||||
$this->barwidth = 60 * 60 * 24 * 7 * 4 * 1000;
|
||||
break;
|
||||
}
|
||||
|
||||
// Get item sales data
|
||||
if ( $this->show_categories ) {
|
||||
$order_items = $this->get_order_report_data( array(
|
||||
|
@ -125,20 +145,36 @@ class WC_Report_Sales_By_Category extends WC_Admin_Report {
|
|||
'_line_total' => array(
|
||||
'type' => 'order_item_meta',
|
||||
'order_item_type' => 'line_item',
|
||||
'function' => 'SUM',
|
||||
'function' => '',
|
||||
'name' => 'order_item_amount'
|
||||
)
|
||||
),
|
||||
'post_date' => array(
|
||||
'type' => 'post_data',
|
||||
'function' => '',
|
||||
'name' => 'post_date'
|
||||
),
|
||||
),
|
||||
'group_by' => 'product_id',
|
||||
'order_by' => 'post_date ASC',
|
||||
'group_by' => 'ID, product_id',
|
||||
'query_type' => 'get_results',
|
||||
'filter_range' => true
|
||||
) );
|
||||
|
||||
$this->item_sales = array();
|
||||
$this->item_sales_and_times = array();
|
||||
|
||||
if ( $order_items ) {
|
||||
foreach ( $order_items as $order_item ) {
|
||||
switch ( $this->chart_groupby ) {
|
||||
case 'day' :
|
||||
$time = strtotime( date( 'Ymd', strtotime( $order_item->post_date ) ) ) * 1000;
|
||||
break;
|
||||
case 'month' :
|
||||
$time = strtotime( date( 'Ym', strtotime( $order_item->post_date ) ) . '01' ) * 1000;
|
||||
break;
|
||||
}
|
||||
|
||||
$this->item_sales_and_times[ $time ][ $order_item->product_id ] = isset( $this->item_sales_and_times[ $time ][ $order_item->product_id ] ) ? $this->item_sales_and_times[ $time ][ $order_item->product_id ] + $order_item->order_item_amount : $order_item->order_item_amount;
|
||||
|
||||
$this->item_sales[ $order_item->product_id ] = isset( $this->item_sales[ $order_item->product_id ] ) ? $this->item_sales[ $order_item->product_id ] + $order_item->order_item_amount : $order_item->order_item_amount;
|
||||
}
|
||||
}
|
||||
|
@ -238,19 +274,37 @@ class WC_Report_Sales_By_Category extends WC_Admin_Report {
|
|||
$category = get_term( $category, 'product_cat' );
|
||||
$term_ids = get_term_children( $category->term_id, 'product_cat' );
|
||||
$term_ids[] = $category->term_id;
|
||||
$product_ids = get_objects_in_term( $term_ids, 'product_cat' );
|
||||
$product_ids = array_unique( get_objects_in_term( $term_ids, 'product_cat' ) );
|
||||
$category_total = 0;
|
||||
$found_ids = array();
|
||||
$category_chart_data = array();
|
||||
|
||||
foreach ( $product_ids as $id ) {
|
||||
if ( ! in_array( $id, $found_ids ) && isset( $this->item_sales[ $id ] ) ) {
|
||||
$category_total += $this->item_sales[ $id ];
|
||||
$found_ids[] = $id;
|
||||
for ( $i = 0; $i <= $this->chart_interval; $i ++ ) {
|
||||
$interval_total = 0;
|
||||
|
||||
switch ( $this->chart_groupby ) {
|
||||
case 'day' :
|
||||
$time = strtotime( date( 'Ymd', strtotime( "+{$i} DAY", $this->start_date ) ) ) * 1000;
|
||||
break;
|
||||
case 'month' :
|
||||
$time = strtotime( date( 'Ym', strtotime( "+{$i} MONTH", $this->start_date ) ) . '01' ) * 1000;
|
||||
break;
|
||||
}
|
||||
|
||||
foreach ( $product_ids as $id ) {
|
||||
if ( isset( $this->item_sales_and_times[ $time ][ $id ] ) ) {
|
||||
$interval_total += $this->item_sales_and_times[ $time ][ $id ];
|
||||
$category_total += $this->item_sales_and_times[ $time ][ $id ];
|
||||
}
|
||||
}
|
||||
|
||||
$category_chart_data[] = array( $time, $interval_total );
|
||||
}
|
||||
|
||||
$chart_data[] = array( $index, $category_total );
|
||||
$chart_ticks[] = array( $index, $category->name );
|
||||
if ( ! $category_total )
|
||||
continue;
|
||||
|
||||
$chart_data[ $category->term_id ]['category'] = $category->name;
|
||||
$chart_data[ $category->term_id ]['data'] = $category_chart_data;
|
||||
|
||||
$index ++;
|
||||
}
|
||||
|
@ -260,28 +314,35 @@ class WC_Report_Sales_By_Category extends WC_Admin_Report {
|
|||
</div>
|
||||
<script type="text/javascript">
|
||||
jQuery(function(){
|
||||
var data = jQuery.parseJSON( '<?php echo json_encode( $chart_data ); ?>' );
|
||||
var ticks = jQuery.parseJSON( '<?php echo json_encode( $chart_ticks ); ?>' );
|
||||
|
||||
jQuery.plot(
|
||||
jQuery('.chart-placeholder.main'),
|
||||
[
|
||||
{
|
||||
label: "<?php echo esc_js( __( 'Sales amount', 'woocommerce' ) ) ?>",
|
||||
data: data,
|
||||
color: '<?php echo $this->chart_colours['sales_amount']; ?>',
|
||||
bars: { fillColor: '<?php echo $this->chart_colours['sales_amount']; ?>', fill: true, show: true, lineWidth: 2, align: 'center', barWidth: 0.75 },
|
||||
prepend_tooltip: "<?php echo get_woocommerce_currency_symbol(); ?>",
|
||||
enable_tooltip: true
|
||||
}
|
||||
<?php
|
||||
$index = 0;
|
||||
foreach ( $chart_data as $data ) {
|
||||
$color = isset( $this->chart_colours[ $index ] ) ? $this->chart_colours[ $index ] : $this->chart_colours[0];
|
||||
$width = $this->barwidth / sizeof( $chart_data );
|
||||
$offset = ( $width * $index );
|
||||
$series = $data['data'];
|
||||
foreach ( $series as $key => $series_data )
|
||||
$series[ $key ][0] = $series_data[0] + $offset;
|
||||
echo '{
|
||||
label: "' . esc_js( $data['category'] ) . '",
|
||||
data: jQuery.parseJSON( "' . json_encode( $series ) . '" ),
|
||||
color: "' . $color . '",
|
||||
bars: { fillColor: "' . $color . '", fill: true, show: true, lineWidth: 1, align: "center", barWidth: ' . $width * 0.75 . ', stack: false },
|
||||
prepend_tooltip: "' . get_woocommerce_currency_symbol() . '",
|
||||
enable_tooltip: true,
|
||||
prepend_label: true
|
||||
},';
|
||||
$index++;
|
||||
}
|
||||
?>
|
||||
],
|
||||
{
|
||||
legend: {
|
||||
show: false
|
||||
},
|
||||
series: {
|
||||
stack: true
|
||||
},
|
||||
grid: {
|
||||
color: '#aaa',
|
||||
borderColor: 'transparent',
|
||||
|
@ -290,9 +351,15 @@ class WC_Report_Sales_By_Category extends WC_Admin_Report {
|
|||
},
|
||||
xaxes: [ {
|
||||
color: '#aaa',
|
||||
reserveSpace: true,
|
||||
position: "bottom",
|
||||
tickColor: 'transparent',
|
||||
ticks: ticks,
|
||||
mode: "time",
|
||||
timeformat: "<?php if ( $this->chart_groupby == 'day' ) echo '%d %b'; else echo '%b'; ?>",
|
||||
monthNames: <?php echo json_encode( array_values( $wp_locale->month_abbrev ) ) ?>,
|
||||
tickLength: 1,
|
||||
minTickSize: [1, "<?php echo $this->chart_groupby; ?>"],
|
||||
tickSize: [1, "<?php echo $this->chart_groupby; ?>"],
|
||||
font: {
|
||||
color: "#aaa"
|
||||
}
|
||||
|
|
|
@ -20,10 +20,15 @@ jQuery(document).ready(function($) {
|
|||
|
||||
var y = item.datapoint[1];
|
||||
|
||||
if ( ! item.series.prepend_tooltip )
|
||||
item.series.prepend_tooltip = item.series.label + ": ";
|
||||
tooltip_content = '';
|
||||
|
||||
showTooltip( item.pageX, item.pageY, item.series.prepend_tooltip + y );
|
||||
if ( item.series.prepend_label )
|
||||
tooltip_content = tooltip_content + item.series.label + ": ";
|
||||
|
||||
if ( item.series.prepend_tooltip )
|
||||
tooltip_content = tooltip_content + item.series.prepend_tooltip;
|
||||
|
||||
showTooltip( item.pageX, item.pageY, tooltip_content + y );
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
jQuery(document).ready(function(e){function t(e,t,n){jQuery('<div class="chart-tooltip">'+n+"</div>").css({top:t-16,left:e+20}).appendTo("body").fadeIn(200)}var n=null;jQuery(".chart-placeholder").bind("plothover",function(e,r,i){if(i){if(n!=i.dataIndex){n=i.dataIndex;jQuery(".chart-tooltip").remove();if(i.series.points.show||i.series.enable_tooltip){var s=i.datapoint[1];i.series.prepend_tooltip||(i.series.prepend_tooltip=i.series.label+": ");t(i.pageX,i.pageY,i.series.prepend_tooltip+s)}}}else{jQuery(".chart-tooltip").remove();n=null}});e(".wc_sparkline.bars").each(function(){var t=e(this).data("sparkline"),n={grid:{show:!1}},r=[{data:t,color:e(this).data("color"),bars:{fillColor:e(this).data("color"),fill:!0,show:!0,lineWidth:1,barWidth:e(this).data("barwidth"),align:"center"},shadowSize:0}],i=e.plot(e(this),r,n)});e(".wc_sparkline.lines").each(function(){var t=e(this).data("sparkline"),n={grid:{show:!1}},r=[{data:t,color:e(this).data("color"),lines:{fill:!1,show:!0,lineWidth:1,align:"center"},shadowSize:0}],i=e.plot(e(this),r,n)});var r=jQuery(".range_datepicker").datepicker({defaultDate:"",dateFormat:"yy-mm-dd",numberOfMonths:1,maxDate:"+0D",showButtonPanel:!0,showOn:"focus",buttonImageOnly:!0,onSelect:function(e){var t=jQuery(this).is(".from")?"minDate":"maxDate",n=jQuery(this).data("datepicker"),i=jQuery.datepicker.parseDate(n.settings.dateFormat||jQuery.datepicker._defaults.dateFormat,e,n.settings);r.not(this).datepicker("option",t,i)}})});
|
||||
jQuery(document).ready(function(e){function t(e,t,n){jQuery('<div class="chart-tooltip">'+n+"</div>").css({top:t-16,left:e+20}).appendTo("body").fadeIn(200)}var n=null;jQuery(".chart-placeholder").bind("plothover",function(e,r,i){if(i){if(n!=i.dataIndex){n=i.dataIndex;jQuery(".chart-tooltip").remove();if(i.series.points.show||i.series.enable_tooltip){var s=i.datapoint[1];tooltip_content="";i.series.prepend_label&&(tooltip_content=tooltip_content+i.series.label+": ");i.series.prepend_tooltip&&(tooltip_content+=i.series.prepend_tooltip);t(i.pageX,i.pageY,tooltip_content+s)}}}else{jQuery(".chart-tooltip").remove();n=null}});e(".wc_sparkline.bars").each(function(){var t=e(this).data("sparkline"),n={grid:{show:!1}},r=[{data:t,color:e(this).data("color"),bars:{fillColor:e(this).data("color"),fill:!0,show:!0,lineWidth:1,barWidth:e(this).data("barwidth"),align:"center"},shadowSize:0}],i=e.plot(e(this),r,n)});e(".wc_sparkline.lines").each(function(){var t=e(this).data("sparkline"),n={grid:{show:!1}},r=[{data:t,color:e(this).data("color"),lines:{fill:!1,show:!0,lineWidth:1,align:"center"},shadowSize:0}],i=e.plot(e(this),r,n)});var r=jQuery(".range_datepicker").datepicker({defaultDate:"",dateFormat:"yy-mm-dd",numberOfMonths:1,maxDate:"+0D",showButtonPanel:!0,showOn:"focus",buttonImageOnly:!0,onSelect:function(e){var t=jQuery(this).is(".from")?"minDate":"maxDate",n=jQuery(this).data("datepicker"),i=jQuery.datepicker.parseDate(n.settings.dateFormat||jQuery.datepicker._defaults.dateFormat,e,n.settings);r.not(this).datepicker("option",t,i)}})});
|
Loading…
Reference in New Issue