|
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 | | - $this->id = 'taxonomy-report'; |
15 | | - $this->method_title = __( 'Taxonomy Report', 'woo-taxonomy-report' ); |
16 | | - $this->method_description = __( 'Add reports based on taxonomies.', 'woo-taxonomy-report' ); |
17 | | - // Actions. |
18 | | - add_action( 'woocommerce_update_options_integration_' . $this->id, array( $this, 'process_admin_options' ) ); |
19 | | - add_filter( 'woocommerce_admin_reports', array( $this, 'add_reports' ) ); |
20 | | - add_action( 'woocommerce_after_register_taxonomy', array( $this, 'load_taxonomies_by_wc' ) ); |
21 | | - } |
| 10 | + /** |
| 11 | + * Init and hook in the integration. |
| 12 | + */ |
| 13 | + public function __construct() { |
| 14 | + $this->id = 'taxonomy-report'; |
| 15 | + $this->method_title = __( 'Taxonomy Report', 'woo-taxonomy-report' ); |
| 16 | + $this->method_description = __( 'Add reports based on taxonomies.', 'woo-taxonomy-report' ); |
| 17 | + // Actions. |
| 18 | + add_action( 'woocommerce_update_options_integration_' . $this->id, array( $this, 'process_admin_options' ) ); |
| 19 | + add_filter( 'woocommerce_admin_reports', array( $this, 'add_reports' ) ); |
| 20 | + add_action( 'woocommerce_after_register_taxonomy', array( $this, 'load_taxonomies_by_wc' ) ); |
| 21 | + } |
22 | 22 |
|
23 | | - /** |
24 | | - * Initialize integration settings form fields. |
25 | | - */ |
26 | | - public function init_form_fields() { |
27 | | - $taxonomies = get_object_taxonomies( 'product', 'objects' ); |
28 | | - unset( $taxonomies[ 'product_shipping_class' ] ); |
29 | | - unset( $taxonomies[ 'product_type' ] ); |
30 | | - unset( $taxonomies[ 'product_attributes' ] ); |
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 ); |
| 23 | + /** |
| 24 | + * Initialize integration settings form fields. |
| 25 | + */ |
| 26 | + public function init_form_fields() { |
| 27 | + $taxonomies = get_object_taxonomies( 'product', 'objects' ); |
| 28 | + unset( $taxonomies[ 'product_shipping_class' ] ); |
| 29 | + unset( $taxonomies[ 'product_type' ] ); |
| 30 | + unset( $taxonomies[ 'product_attributes' ] ); |
| 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', 'woo-taxonomy-report' ), |
| 46 | + 'type' => 'multiselect', |
| 47 | + 'description' => __( 'Pick multiple taxonomies with ctrl key', 'woo-taxonomy-report' ), |
| 48 | + 'options' => $product_tags, |
| 49 | + ), |
| 50 | + 'chosen' => array( |
| 51 | + 'title' => __( 'Create new Taxonomies for WooCommerce', 'woo-taxonomy-report' ), |
| 52 | + 'type' => 'multiselect', |
| 53 | + 'description' => __( 'Pick multiple taxonomies with ctrl key', 'woo-taxonomy-report' ), |
| 54 | + 'options' => array( |
| 55 | + 'brand' => __( 'Brands', 'woo-taxonomy-report' ), 'vendor' => __( 'Vendors', 'woo-taxonomy-report' ), |
| 56 | + 'artist' => __( 'Artist', 'woo-taxonomy-report' ), 'author' => __( 'Author', 'woo-taxonomy-report' ), |
| 57 | + 'state' => __( 'State', 'woo-taxonomy-report' ), 'city' => __( 'City', 'woo-taxonomy-report' ) |
| 58 | + ), |
| 59 | + ), |
| 60 | + ); |
41 | 61 | } |
42 | | - } |
43 | | - $this->form_fields = array( |
44 | | - 'selected' => array( |
45 | | - 'title' => __( 'Taxonomies', 'woo-taxonomy-report' ), |
46 | | - 'type' => 'multiselect', |
47 | | - 'description' => __( 'Pick multiple taxonomies with ctrl key', 'woo-taxonomy-report' ), |
48 | | - 'options' => $product_tags, |
49 | | - ), |
50 | | - 'chosen' => array( |
51 | | - 'title' => __( 'Create new Taxonomies for WooCommerce', 'woo-taxonomy-report' ), |
52 | | - 'type' => 'multiselect', |
53 | | - 'description' => __( 'Pick multiple taxonomies with ctrl key', 'woo-taxonomy-report' ), |
54 | | - 'options' => array( |
55 | | - 'brand' => __( 'Brands', 'woo-taxonomy-report' ), 'vendor' => __( 'Vendors', 'woo-taxonomy-report' ), |
56 | | - 'artist' => __( 'Artist', 'woo-taxonomy-report' ), 'author' => __( 'Author', 'woo-taxonomy-report' ), |
57 | | - 'state' => __( 'State', 'woo-taxonomy-report' ), 'city' => __( 'City', 'woo-taxonomy-report' ) |
58 | | - ), |
59 | | - ), |
60 | | - ); |
61 | | - } |
62 | 62 |
|
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 | | - } |
| 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 | + } |
71 | 71 |
|
72 | | - /** |
73 | | - * Output the gateway settings screen. |
74 | | - */ |
75 | | - public function admin_options() { |
76 | | - parent::admin_options(); |
77 | | - } |
| 72 | + /** |
| 73 | + * Output the gateway settings screen. |
| 74 | + */ |
| 75 | + public function admin_options() { |
| 76 | + parent::admin_options(); |
| 77 | + } |
78 | 78 |
|
79 | | - /** |
80 | | - * Add Taxonomy reports to WC reports |
81 | | - * @param arr $reports Existing reports |
82 | | - * @return arr Modified reports |
83 | | - */ |
84 | | - public static function add_reports( $reports ) { |
85 | | - if ( current_user_can( 'manage_options' ) ) { |
86 | | - //get_option of WC_settings class not work with static method required for the reports part |
87 | | - $taxonomies = get_option( 'woocommerce_taxonomy-report_settings', null ); |
88 | | - if ( isset( $taxonomies [ 'selected' ] ) ) { |
89 | | - $taxonomies = $taxonomies [ 'selected' ]; |
90 | | - foreach ( $taxonomies as $taxonomy ) { |
91 | | - $name = get_taxonomy( $taxonomy ); |
92 | | - $name = $name->label; |
93 | | - $reports[ $taxonomy ] = array( |
94 | | - 'title' => $name, |
95 | | - 'reports' => array( |
96 | | - "sales_by_" . $taxonomy => array( |
97 | | - 'title' => __( $name, 'woo-taxonomy-report' ) . ' ' . __( 'Total', 'woo-taxonomy-report' ), |
98 | | - 'description' => '', |
99 | | - 'hide_title' => true, |
100 | | - 'callback' => array( __CLASS__, 'get_report' ) |
101 | | - ), |
102 | | - "sales_subtotal_by_" . $taxonomy => array( |
103 | | - 'title' => __( $name, 'woo-taxonomy-report' ) . ' ' . __( 'SubTotal', 'woo-taxonomy-report' ), |
104 | | - 'description' => '', |
105 | | - 'hide_title' => true, |
106 | | - 'callback' => array( __CLASS__, 'get_report_subtotal' ) |
107 | | - ) |
108 | | - ) |
109 | | - ); |
110 | | - } |
| 79 | + /** |
| 80 | + * Add Taxonomy reports to WC reports |
| 81 | + * @param arr $reports Existing reports |
| 82 | + * @return arr Modified reports |
| 83 | + */ |
| 84 | + public static function add_reports( $reports ) { |
| 85 | + if ( current_user_can( 'manage_options' ) ) { |
| 86 | + //get_option of WC_settings class not work with static method required for the reports part |
| 87 | + $taxonomies = get_option( 'woocommerce_taxonomy-report_settings', null ); |
| 88 | + if ( isset( $taxonomies [ 'selected' ] ) ) { |
| 89 | + $taxonomies = $taxonomies [ 'selected' ]; |
| 90 | + foreach ( $taxonomies as $key => $taxonomy ) { |
| 91 | + $name = get_taxonomy( $taxonomy ); |
| 92 | + $name = $name->label; |
| 93 | + $reports[ $taxonomy ] = array( |
| 94 | + 'title' => $name, |
| 95 | + 'reports' => array( |
| 96 | + "sales_by_" . $taxonomy => array( |
| 97 | + 'title' => __( $name, 'woo-taxonomy-report' ) . ' ' . __( 'Total', 'woo-taxonomy-report' ), |
| 98 | + 'description' => '', |
| 99 | + 'hide_title' => true, |
| 100 | + 'callback' => array( __CLASS__, 'get_report' ) |
| 101 | + ), |
| 102 | + "sales_subtotal_by_" . $taxonomy => array( |
| 103 | + 'title' => __( $name, 'woo-taxonomy-report' ) . ' ' . __( 'SubTotal', 'woo-taxonomy-report' ), |
| 104 | + 'description' => '', |
| 105 | + 'hide_title' => true, |
| 106 | + 'callback' => array( __CLASS__, 'get_report_subtotal' ) |
| 107 | + ) |
| 108 | + ) |
| 109 | + ); |
| 110 | + } |
| 111 | + } |
| 112 | + } |
| 113 | + return $reports; |
111 | 114 | } |
112 | | - } |
113 | | - return $reports; |
114 | | - } |
115 | 115 |
|
116 | | - public static function get_report( $name ) { |
117 | | - require_once( plugin_dir_path( __FILE__ ) . 'WC_Report_Sales_By_TReport.php' ); |
118 | | - $name = str_replace( 'sales_by_', '', $name ); |
119 | | - new WC_Report_Sales_By_TReport( $name ); |
120 | | - } |
| 116 | + public static function get_report( $name ) { |
| 117 | + require_once( plugin_dir_path( __FILE__ ) . 'WC_Report_Sales_By_TReport.php' ); |
| 118 | + $name = str_replace( 'sales_by_', '', $name ); |
| 119 | + $report = new WC_Report_Sales_By_TReport( $name ); |
| 120 | + $report->output_report(); |
| 121 | + } |
121 | 122 |
|
122 | | - public static function get_report_subtotal( $name ) { |
123 | | - require_once( plugin_dir_path( __FILE__ ) . 'WC_Report_Sales_By_TReport.php' ); |
124 | | - $name = str_replace( 'sales_subtotal_by_', '', $name ); |
125 | | - new WC_Report_Sales_By_TReport( $name, '_line_subtotal' ); |
126 | | - } |
| 123 | + public static function get_report_subtotal( $name ) { |
| 124 | + require_once( plugin_dir_path( __FILE__ ) . 'WC_Report_Sales_By_TReport.php' ); |
| 125 | + $name = str_replace( 'sales_subtotal_by_', '', $name ); |
| 126 | + $report = new WC_Report_Sales_By_TReport( $name, '_line_subtotal' ); |
| 127 | + $report->output_report(); |
| 128 | + } |
127 | 129 |
|
128 | 130 | } |
0 commit comments