Plugin Directory

Changeset 1189764


Ignore:
Timestamp:
06/29/2015 05:52:10 PM (10 years ago)
Author:
chuckmac
Message:

Fix issues with report count in WC 2.3

Location:
woocommerce-sales-by-location-report/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • woocommerce-sales-by-location-report/trunk/changelog.txt

    r1065346 r1189764  
    11*** WooCommerce Sales By Location Report Changelog ***
     2
     32015.XX.XX - Version 1.2
     4* Fix - Fix order total reporting issue with WooCommerce 2.3
    25
    362015.01.11 - Version 1.1.1
  • woocommerce-sales-by-location-report/trunk/classes/class-wc-report-sales-by-location.php

    r1029435 r1189764  
    1717    public $totals_by;
    1818
     19    private $report_data;
     20
     21
     22    /**
     23     * Get report data
     24     * @return array
     25     */
     26    public function get_report_data() {
     27        if ( empty( $this->report_data ) ) {
     28            $this->query_report_data();
     29        }
     30        return $this->report_data;
     31    }
     32
     33    /**
     34     * Get all data needed for this report and store in the class
     35     */
     36    private function query_report_data() {
     37
     38        $this->report_data = new stdClass;
     39
     40        $this->report_data->orders = (array) $this->get_order_report_data( array(
     41            'data' => array(
     42                '_' . $this->location_by . '_country' => array(
     43                    'type'     => 'meta',
     44                    'name'     => 'countries_data',
     45                    'function' => null
     46                ),
     47                '_order_total' => array(
     48                    'type'     => 'meta',
     49                    'function' => 'SUM',
     50                    'name'     => 'total_sales'
     51                ),
     52                'post_date' => array(
     53                    'type'     => 'post_data',
     54                    'function' => '',
     55                    'name'     => 'post_date'
     56                ),
     57            ),
     58            'group_by'            => 'YEAR(posts.post_date), MONTH(posts.post_date), DAY(posts.post_date), meta__' . $this->location_by . '_country.meta_value',
     59            'order_by'            => 'post_date ASC',
     60            'query_type'          => 'get_results',
     61            'filter_range'        => true,
     62            'order_types'         => array_merge( array( 'shop_order_refund' ), wc_get_order_types( 'sales-reports' ) ),
     63            'order_status'        => array( 'completed', 'processing', 'on-hold' ),
     64            'parent_order_status' => array( 'completed', 'processing', 'on-hold' ),
     65        ) );
     66
     67        $this->report_data->order_counts = (array) $this->get_order_report_data( array(
     68            'data' => array(
     69                '_' . $this->location_by . '_country' => array(
     70                    'type'     => 'meta',
     71                    'name'     => 'countries_data',
     72                    'function' => null
     73                ),
     74                'ID' => array(
     75                    'type'     => 'post_data',
     76                    'function' => 'COUNT',
     77                    'name'     => 'count',
     78                    'distinct' => true,
     79                ),
     80                'post_date' => array(
     81                    'type'     => 'post_data',
     82                    'function' => '',
     83                    'name'     => 'post_date'
     84                )
     85            ),
     86            'group_by'            => 'YEAR(posts.post_date), MONTH(posts.post_date), DAY(posts.post_date), meta__' . $this->location_by . '_country.meta_value',
     87            'order_by'            => 'post_date ASC',
     88            'query_type'          => 'get_results',
     89            'filter_range'        => true,
     90            'order_types'         => wc_get_order_types( 'order-count' ),
     91            'order_status'        => array( 'completed', 'processing', 'on-hold' )
     92        ) );
     93
     94    }
     95
    1996    /**
    2097     * Get the legend for the main chart sidebar
     
    28105        $this->totals_by     = ( isset($_REQUEST['report_by']) ? $_REQUEST['report_by'] : 'number-orders' );
    29106
     107
     108        $data = $this->get_report_data();
     109
    30110        add_filter( 'woocommerce_reports_get_order_report_query', array( $this, 'location_report_add_count' ) );
    31 
    32         $location_query = $this->get_order_report_data( array(
    33                 'data' => array(
    34                     '_' . $this->location_by . '_country' => array(
    35                         'type'     => 'meta',
    36                         'name'     => 'countries_data',
    37                         'function' => null
    38                     ),
    39                     '_order_total' => array(
    40                         'type'     => 'meta',
    41                         'function' => 'SUM',
    42                         'name'     => 'total_sales'
    43                     ),
    44                     'post_date' => array(
    45                         'type'     => 'post_data',
    46                         'function' => '',
    47                         'name'     => 'post_date'
    48                     ),
    49                 ),
    50                 'filter_range' => true,
    51                 'group_by' => 'YEAR(posts.post_date), MONTH(posts.post_date), DAY(posts.post_date), meta__' . $this->location_by . '_country.meta_value',
    52                 'query_type' => 'get_results'
    53             ) );
    54111
    55112
     
    57114        $country_data = array();
    58115        $export_data = array();
    59         foreach ( $location_query as $location_values ) {
    60 
    61             if ( '' == $location_values->countries_data ) {
    62                 $location_values->countries_data = 'UNDEFINED';
     116
     117        if ( 'number-orders' == $this->totals_by ) {
     118            foreach ( $data->order_counts as $location_values ) {
     119                if ( '' == $location_values->countries_data ) {
     120                    $location_values->countries_data = 'UNDEFINED';
     121                }
     122           
     123                $country_data[$location_values->countries_data] = ( isset( $country_data[$location_values->countries_data] ) ) ? $location_values->count + $country_data[$location_values->countries_data] : $location_values->count;
     124
     125                if ( 'UNDEFINED' != $location_values->countries_data ) {
     126                    $export_data[$location_values->countries_data][] = $location_values;
     127                }
    63128            }
    64 
    65             if ( 'number-orders' == $this->totals_by ) {
    66                 $country_data[$location_values->countries_data] = ( isset( $country_data[$location_values->countries_data] ) ) ? $location_values->countries_data_count + $country_data[$location_values->countries_data] : $location_values->countries_data_count;
    67             } elseif ( 'order-total' == $this->totals_by ) {
     129        } elseif ( 'order-total' == $this->totals_by ) {
     130            foreach ( $data->orders as $location_values ) {
     131   
     132                if ( '' == $location_values->countries_data ) {
     133                    $location_values->countries_data = 'UNDEFINED';
     134                }
     135                   
    68136                $country_data[$location_values->countries_data] = ( isset( $country_data[$location_values->countries_data] ) ) ? $location_values->total_sales + $country_data[$location_values->countries_data] : $location_values->total_sales;
     137   
     138                if ( 'UNDEFINED' != $location_values->countries_data ) {
     139                    $export_data[$location_values->countries_data][] = $location_values;
     140                }
    69141            }
    70 
    71             if ( 'UNDEFINED' != $location_values->countries_data ) {
    72                 $export_data[$location_values->countries_data][] = $location_values;
    73             }
    74         }
     142        }
     143
    75144
    76145        //Pass the data to the screen.
  • woocommerce-sales-by-location-report/trunk/woocommerce-location-report.php

    r1065346 r1189764  
    66 * Author: Chuck Mac
    77 * Author URI: http://www.chuckmac.info
    8  * Version: 1.1
     8 * Version: 1.2
    99 * Text Domain: wc_location_report
    1010 * Domain Path: /languages/
    1111 *
    12  * Copyright: (c) 2014 ChuckMac Development LLC
     12 * Copyright: (c) 2014-2015 ChuckMac Development LLC
    1313 *
    1414 * License: GNU General Public License v3.0
     
    1818 * @author    WooThemes
    1919 * @category  Reports
    20  * @copyright Copyright (c) 2014, ChuckMac Development LLC
     20 * @copyright Copyright (c) 2014-2015, ChuckMac Development LLC
    2121 * @license   http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
    2222 */
     
    4545
    4646    /** plugin version number */
    47     public static $version = '1.1';
     47    public static $version = '1.2';
    4848
    4949    /** @var string the plugin file */
     
    9595            //jVector includes - needs to be done in the footer so we can localize data as part of the report generation
    9696            wp_enqueue_script( 'jvectormap', plugins_url( '/lib/jquery-jvectormap-1.2.2.min.js', self::$plugin_file ), array( 'jquery' ), self::$version, true );
    97             wp_enqueue_script( 'jvectormap-world', plugins_url( '/lib/map-data/jquery-jvectormap-world-mill-en.js', self::$plugin_file ), array( 'jquery', 'jvectormap' ), self::$version, true );
     97            wp_enqueue_script( 'jvectormap-world', plugins_url( '/lib/map-data/jquery-jvectormap-world-mill-en', self::$plugin_file ), array( 'jquery', 'jvectormap' ), self::$version, true );
    9898
    9999            //jVector css
Note: See TracChangeset for help on using the changeset viewer.