|
2 | 2 |
|
3 | 3 | // If this file is called directly, abort.
|
4 | 4 | if ( !defined( 'WPINC' ) ) {
|
5 |
| - die; |
| 5 | + die; |
6 | 6 | }
|
7 | 7 |
|
8 | 8 | class WC_Integration_TReport extends WC_Integration {
|
9 | 9 |
|
10 |
| - /** |
11 |
| - * Init and hook in the integration. |
12 |
| - */ |
13 |
| - public function __construct() { |
14 |
| - global $woocommerce; |
15 |
| - $this->id = 'taxonomy-report'; |
16 |
| - $this->method_title = __( 'Taxonomy Report', 'woocommerce-taxonomy-report' ); |
17 |
| - $this->method_description = __( 'Add reports based on taxonomies.', 'woocommerce-taxonomy-report' ); |
18 |
| - // Actions. |
19 |
| - add_action( 'woocommerce_update_options_integration_' . $this->id, array( $this, 'process_admin_options' ) ); |
20 |
| - add_filter( 'woocommerce_admin_reports', __CLASS__ . '::add_reports' ); |
21 |
| - add_action( 'woocommerce_after_register_taxonomy', array( $this, 'load_taxonomies_by_wc' ) ); |
22 |
| - } |
| 10 | + /** |
| 11 | + * Init and hook in the integration. |
| 12 | + */ |
| 13 | + public function __construct() { |
| 14 | + global $woocommerce; |
| 15 | + $this->id = 'taxonomy-report'; |
| 16 | + $this->method_title = __( 'Taxonomy Report', 'woocommerce-taxonomy-report' ); |
| 17 | + $this->method_description = __( 'Add reports based on taxonomies.', 'woocommerce-taxonomy-report' ); |
| 18 | + // Actions. |
| 19 | + add_action( 'woocommerce_update_options_integration_' . $this->id, array( $this, 'process_admin_options' ) ); |
| 20 | + add_filter( 'woocommerce_admin_reports', __CLASS__ . '::add_reports' ); |
| 21 | + add_action( 'woocommerce_after_register_taxonomy', array( $this, 'load_taxonomies_by_wc' ) ); |
| 22 | + } |
23 | 23 |
|
24 |
| - /** |
25 |
| - * Initialize integration settings form fields. |
26 |
| - */ |
27 |
| - public function init_form_fields() { |
28 |
| - $taxonomies = get_object_taxonomies( 'product', 'objects' ); |
29 |
| - unset( $taxonomies[ 'product_shipping_class' ] ); |
30 |
| - unset( $taxonomies[ 'product_type' ] ); |
31 |
| - unset( $taxonomies[ 'pa_color' ] ); |
32 |
| - $product_tags = array(); |
33 |
| - foreach ( $taxonomies as $taxonomy ) { |
34 |
| - $product_tags[ $taxonomy->query_var ] = $taxonomy->label; |
35 |
| - } |
36 |
| - $taxonomies = get_option( 'woocommerce_taxonomy-report_settings', null ); |
37 |
| - if ( isset( $taxonomies [ 'chosen' ] ) && is_array($taxonomies [ 'chosen' ]) ) { |
38 |
| - $taxonomies = $taxonomies [ 'chosen' ]; |
39 |
| - foreach ( $taxonomies as $taxonomy ) { |
40 |
| - $product_tags[ $taxonomy ] = ucfirst( $taxonomy ); |
41 |
| - } |
42 |
| - } |
43 |
| - $this->form_fields = array( |
44 |
| - 'selected' => array( |
45 |
| - 'title' => __( 'Taxonomies', 'woocommerce-taxonomy-report' ), |
46 |
| - 'type' => 'multiselect', |
47 |
| - 'description' => __( 'Pick multiple taxonomies with ctrl key', 'woocommerce-taxonomy-report' ), |
48 |
| - 'options' => $product_tags, |
49 |
| - ), |
50 |
| - 'chosen' => array( |
51 |
| - 'title' => __( 'Create new Taxonomies for WooCommerce', 'woocommerce-taxonomy-report' ), |
52 |
| - 'type' => 'multiselect', |
53 |
| - 'description' => __( 'Pick multiple taxonomies with ctrl key', 'woocommerce-taxonomy-report' ), |
54 |
| - 'options' => array( 'brand' => __( 'Brands', 'woocommerce-taxonomy-report' ), 'vendor' => __( 'Vendors', 'woocommerce-taxonomy-report' ) ), |
55 |
| - ), |
56 |
| - ); |
| 24 | + /** |
| 25 | + * Initialize integration settings form fields. |
| 26 | + */ |
| 27 | + public function init_form_fields() { |
| 28 | + $taxonomies = get_object_taxonomies( 'product', 'objects' ); |
| 29 | + unset( $taxonomies[ 'product_shipping_class' ] ); |
| 30 | + unset( $taxonomies[ 'product_type' ] ); |
| 31 | + unset( $taxonomies[ 'pa_color' ] ); |
| 32 | + $product_tags = array(); |
| 33 | + foreach ( $taxonomies as $taxonomy ) { |
| 34 | + $product_tags[ $taxonomy->query_var ] = $taxonomy->label; |
| 35 | + } |
| 36 | + $taxonomies = get_option( 'woocommerce_taxonomy-report_settings', null ); |
| 37 | + if ( isset( $taxonomies [ 'chosen' ] ) && is_array( $taxonomies [ 'chosen' ] ) ) { |
| 38 | + $taxonomies = $taxonomies [ 'chosen' ]; |
| 39 | + foreach ( $taxonomies as $taxonomy ) { |
| 40 | + $product_tags[ $taxonomy ] = ucfirst( $taxonomy ); |
57 | 41 | }
|
| 42 | + } |
| 43 | + $this->form_fields = array( |
| 44 | + 'selected' => array( |
| 45 | + 'title' => __( 'Taxonomies', 'woocommerce-taxonomy-report' ), |
| 46 | + 'type' => 'multiselect', |
| 47 | + 'description' => __( 'Pick multiple taxonomies with ctrl key', 'woocommerce-taxonomy-report' ), |
| 48 | + 'options' => $product_tags, |
| 49 | + ), |
| 50 | + 'chosen' => array( |
| 51 | + 'title' => __( 'Create new Taxonomies for WooCommerce', 'woocommerce-taxonomy-report' ), |
| 52 | + 'type' => 'multiselect', |
| 53 | + 'description' => __( 'Pick multiple taxonomies with ctrl key', 'woocommerce-taxonomy-report' ), |
| 54 | + 'options' => array( |
| 55 | + 'brand' => __( 'Brands', 'woocommerce-taxonomy-report' ), 'vendor' => __( 'Vendors', 'woocommerce-taxonomy-report' ), |
| 56 | + 'artist' => __( 'Artist', 'woocommerce-taxonomy-report' ), 'author' => __( 'Author', 'woocommerce-taxonomy-report' ), |
| 57 | + 'state' => __( 'State', 'woocommerce-taxonomy-report' ), 'city' => __( 'City', 'woocommerce-taxonomy-report' ) |
| 58 | + ), |
| 59 | + ), |
| 60 | + ); |
| 61 | + } |
58 | 62 |
|
59 |
| - /** |
60 |
| - * Wait the loading of initialization of wWooCommerce taxonomies |
61 |
| - */ |
62 |
| - public function load_taxonomies_by_wc() { |
63 |
| - // Load the settings. |
64 |
| - $this->init_form_fields(); |
65 |
| - $this->init_settings(); |
66 |
| - } |
| 63 | + /** |
| 64 | + * Wait the loading of initialization of wWooCommerce taxonomies |
| 65 | + */ |
| 66 | + public function load_taxonomies_by_wc() { |
| 67 | + // Load the settings. |
| 68 | + $this->init_form_fields(); |
| 69 | + $this->init_settings(); |
| 70 | + } |
67 | 71 |
|
68 |
| - /** |
69 |
| - * Add Taxonomy reports to WC reports |
70 |
| - * @param arr $reports Existing reports |
71 |
| - * @return arr Modified reports |
72 |
| - */ |
73 |
| - public static function add_reports( $reports ) { |
74 |
| - if ( current_user_can( 'manage_options' ) ) { |
75 |
| - //get_option of WC_settings class not work with static method required for the reports part |
76 |
| - $taxonomies = get_option( 'woocommerce_taxonomy-report_settings', null ); |
77 |
| - if ( isset( $taxonomies [ 'selected' ] ) ) { |
78 |
| - $taxonomies = $taxonomies [ 'selected' ]; |
79 |
| - foreach ( $taxonomies as $taxonomy ) { |
80 |
| - $name = get_taxonomy( $taxonomy ); |
81 |
| - $name = $name->label; |
82 |
| - $reports[ $taxonomy ] = array( |
83 |
| - 'title' => $name, |
84 |
| - 'reports' => array( |
85 |
| - "sales_by_" . $taxonomy => array( |
86 |
| - 'title' => __( $name, 'woocommerce-taxonomy-report' ) . ' ' . __( 'Total', 'woocommerce-taxonomy-report' ), |
87 |
| - 'description' => '', |
88 |
| - 'hide_title' => true, |
89 |
| - 'callback' => array( __CLASS__, 'get_report' ) |
90 |
| - ), |
91 |
| - "sales_subtotal_by_" . $taxonomy => array( |
92 |
| - 'title' => __( $name, 'woocommerce-taxonomy-report' ) . ' ' . __( 'SubTotal', 'woocommerce-taxonomy-report' ), |
93 |
| - 'description' => '', |
94 |
| - 'hide_title' => true, |
95 |
| - 'callback' => array( __CLASS__, 'get_report_subtotal' ) |
96 |
| - ) |
97 |
| - ) |
98 |
| - ); |
99 |
| - } |
100 |
| - } |
101 |
| - } |
102 |
| - return $reports; |
| 72 | + /** |
| 73 | + * Add Taxonomy reports to WC reports |
| 74 | + * @param arr $reports Existing reports |
| 75 | + * @return arr Modified reports |
| 76 | + */ |
| 77 | + public static function add_reports( $reports ) { |
| 78 | + if ( current_user_can( 'manage_options' ) ) { |
| 79 | + //get_option of WC_settings class not work with static method required for the reports part |
| 80 | + $taxonomies = get_option( 'woocommerce_taxonomy-report_settings', null ); |
| 81 | + if ( isset( $taxonomies [ 'selected' ] ) ) { |
| 82 | + $taxonomies = $taxonomies [ 'selected' ]; |
| 83 | + foreach ( $taxonomies as $taxonomy ) { |
| 84 | + $name = get_taxonomy( $taxonomy ); |
| 85 | + $name = $name->label; |
| 86 | + $reports[ $taxonomy ] = array( |
| 87 | + 'title' => $name, |
| 88 | + 'reports' => array( |
| 89 | + "sales_by_" . $taxonomy => array( |
| 90 | + 'title' => __( $name, 'woocommerce-taxonomy-report' ) . ' ' . __( 'Total', 'woocommerce-taxonomy-report' ), |
| 91 | + 'description' => '', |
| 92 | + 'hide_title' => true, |
| 93 | + 'callback' => array( __CLASS__, 'get_report' ) |
| 94 | + ), |
| 95 | + "sales_subtotal_by_" . $taxonomy => array( |
| 96 | + 'title' => __( $name, 'woocommerce-taxonomy-report' ) . ' ' . __( 'SubTotal', 'woocommerce-taxonomy-report' ), |
| 97 | + 'description' => '', |
| 98 | + 'hide_title' => true, |
| 99 | + 'callback' => array( __CLASS__, 'get_report_subtotal' ) |
| 100 | + ) |
| 101 | + ) |
| 102 | + ); |
| 103 | + } |
103 | 104 | }
|
| 105 | + } |
| 106 | + return $reports; |
| 107 | + } |
104 | 108 |
|
105 |
| - public static function get_report( $name ) { |
106 |
| - require_once( plugin_dir_path( __FILE__ ) . 'WC_Report_Sales_By_TReport.php' ); |
107 |
| - $name = str_replace( 'sales_by_', '', $name ); |
108 |
| - new WC_Report_Sales_By_TReport( $name ); |
109 |
| - } |
| 109 | + public static function get_report( $name ) { |
| 110 | + require_once( plugin_dir_path( __FILE__ ) . 'WC_Report_Sales_By_TReport.php' ); |
| 111 | + $name = str_replace( 'sales_by_', '', $name ); |
| 112 | + new WC_Report_Sales_By_TReport( $name ); |
| 113 | + } |
110 | 114 |
|
111 |
| - public static function get_report_subtotal( $name ) { |
112 |
| - require_once( plugin_dir_path( __FILE__ ) . 'WC_Report_Sales_By_TReport.php' ); |
113 |
| - $name = str_replace( 'sales_subtotal_by_', '', $name ); |
114 |
| - new WC_Report_Sales_By_TReport( $name, '_line_subtotal' ); |
115 |
| - } |
| 115 | + public static function get_report_subtotal( $name ) { |
| 116 | + require_once( plugin_dir_path( __FILE__ ) . 'WC_Report_Sales_By_TReport.php' ); |
| 117 | + $name = str_replace( 'sales_subtotal_by_', '', $name ); |
| 118 | + new WC_Report_Sales_By_TReport( $name, '_line_subtotal' ); |
| 119 | + } |
116 | 120 |
|
117 | 121 | }
|
0 commit comments