@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | namespace WooCommerce\RestApi\Version4\Controllers\Reports; |
| 11 | 11 | |
| 12 | -defined( 'ABSPATH' ) || exit; |
|
| 12 | +defined('ABSPATH') || exit; |
|
| 13 | 13 | |
| 14 | 14 | use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports; |
| 15 | 15 | |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * @param array $request Request array. |
| 32 | 32 | * @return array |
| 33 | 33 | */ |
| 34 | - protected function prepare_reports_query( $request ) { |
|
| 34 | + protected function prepare_reports_query($request) { |
|
| 35 | 35 | $args = array(); |
| 36 | 36 | $args['before'] = $request['before']; |
| 37 | 37 | $args['after'] = $request['after']; |
@@ -57,38 +57,38 @@ discard block |
||
| 57 | 57 | * @param \WP_REST_Request $request Request data. |
| 58 | 58 | * @return array|\WP_Error |
| 59 | 59 | */ |
| 60 | - public function get_items( $request ) { |
|
| 61 | - $query_args = $this->prepare_reports_query( $request ); |
|
| 62 | - $orders_query = new \WC_Admin_Reports_Orders_Query( $query_args ); |
|
| 60 | + public function get_items($request) { |
|
| 61 | + $query_args = $this->prepare_reports_query($request); |
|
| 62 | + $orders_query = new \WC_Admin_Reports_Orders_Query($query_args); |
|
| 63 | 63 | $report_data = $orders_query->get_data(); |
| 64 | 64 | |
| 65 | 65 | $data = array(); |
| 66 | 66 | |
| 67 | - foreach ( $report_data->data as $orders_data ) { |
|
| 68 | - $orders_data['order_number'] = $this->get_order_number( $orders_data['order_id'] ); |
|
| 69 | - $item = $this->prepare_item_for_response( $orders_data, $request ); |
|
| 70 | - $data[] = $this->prepare_response_for_collection( $item ); |
|
| 67 | + foreach ($report_data->data as $orders_data) { |
|
| 68 | + $orders_data['order_number'] = $this->get_order_number($orders_data['order_id']); |
|
| 69 | + $item = $this->prepare_item_for_response($orders_data, $request); |
|
| 70 | + $data[] = $this->prepare_response_for_collection($item); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - $response = rest_ensure_response( $data ); |
|
| 74 | - $response->header( 'X-WP-Total', (int) $report_data->total ); |
|
| 75 | - $response->header( 'X-WP-TotalPages', (int) $report_data->pages ); |
|
| 73 | + $response = rest_ensure_response($data); |
|
| 74 | + $response->header('X-WP-Total', (int) $report_data->total); |
|
| 75 | + $response->header('X-WP-TotalPages', (int) $report_data->pages); |
|
| 76 | 76 | |
| 77 | 77 | $page = $report_data->page_no; |
| 78 | 78 | $max_pages = $report_data->pages; |
| 79 | - $base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) ); |
|
| 80 | - if ( $page > 1 ) { |
|
| 79 | + $base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base))); |
|
| 80 | + if ($page > 1) { |
|
| 81 | 81 | $prev_page = $page - 1; |
| 82 | - if ( $prev_page > $max_pages ) { |
|
| 82 | + if ($prev_page > $max_pages) { |
|
| 83 | 83 | $prev_page = $max_pages; |
| 84 | 84 | } |
| 85 | - $prev_link = add_query_arg( 'page', $prev_page, $base ); |
|
| 86 | - $response->link_header( 'prev', $prev_link ); |
|
| 85 | + $prev_link = add_query_arg('page', $prev_page, $base); |
|
| 86 | + $response->link_header('prev', $prev_link); |
|
| 87 | 87 | } |
| 88 | - if ( $max_pages > $page ) { |
|
| 88 | + if ($max_pages > $page) { |
|
| 89 | 89 | $next_page = $page + 1; |
| 90 | - $next_link = add_query_arg( 'page', $next_page, $base ); |
|
| 91 | - $response->link_header( 'next', $next_link ); |
|
| 90 | + $next_link = add_query_arg('page', $next_page, $base); |
|
| 91 | + $response->link_header('next', $next_link); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | return $response; |
@@ -101,16 +101,16 @@ discard block |
||
| 101 | 101 | * @param \WP_REST_Request $request Request object. |
| 102 | 102 | * @return \WP_REST_Response |
| 103 | 103 | */ |
| 104 | - public function prepare_item_for_response( $report, $request ) { |
|
| 104 | + public function prepare_item_for_response($report, $request) { |
|
| 105 | 105 | $data = $report; |
| 106 | 106 | |
| 107 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 108 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
| 109 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 107 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
| 108 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
| 109 | + $data = $this->filter_response_by_context($data, $context); |
|
| 110 | 110 | |
| 111 | 111 | // Wrap the data in a response object. |
| 112 | - $response = rest_ensure_response( $data ); |
|
| 113 | - $response->add_links( $this->prepare_links( $report ) ); |
|
| 112 | + $response = rest_ensure_response($data); |
|
| 113 | + $response->add_links($this->prepare_links($report)); |
|
| 114 | 114 | |
| 115 | 115 | /** |
| 116 | 116 | * Filter a report returned from the API. |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | * @param object $report The original report object. |
| 122 | 122 | * @param \WP_REST_Request $request Request used to generate the response. |
| 123 | 123 | */ |
| 124 | - return apply_filters( 'woocommerce_rest_prepare_report_orders', $response, $report, $request ); |
|
| 124 | + return apply_filters('woocommerce_rest_prepare_report_orders', $response, $report, $request); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -130,10 +130,10 @@ discard block |
||
| 130 | 130 | * @param WC_Reports_Query $object Object data. |
| 131 | 131 | * @return array |
| 132 | 132 | */ |
| 133 | - protected function prepare_links( $object ) { |
|
| 133 | + protected function prepare_links($object) { |
|
| 134 | 134 | $links = array( |
| 135 | 135 | 'order' => array( |
| 136 | - 'href' => rest_url( sprintf( '/%s/orders/%d', $this->namespace, $object['order_id'] ) ), |
|
| 136 | + 'href' => rest_url(sprintf('/%s/orders/%d', $this->namespace, $object['order_id'])), |
|
| 137 | 137 | ), |
| 138 | 138 | ); |
| 139 | 139 | |
@@ -152,71 +152,71 @@ discard block |
||
| 152 | 152 | 'type' => 'object', |
| 153 | 153 | 'properties' => array( |
| 154 | 154 | 'order_id' => array( |
| 155 | - 'description' => __( 'Order ID.', 'woocommerce' ), |
|
| 155 | + 'description' => __('Order ID.', 'woocommerce'), |
|
| 156 | 156 | 'type' => 'integer', |
| 157 | - 'context' => array( 'view', 'edit' ), |
|
| 157 | + 'context' => array('view', 'edit'), |
|
| 158 | 158 | 'readonly' => true, |
| 159 | 159 | ), |
| 160 | 160 | 'order_number' => array( |
| 161 | - 'description' => __( 'Order Number.', 'woocommerce' ), |
|
| 161 | + 'description' => __('Order Number.', 'woocommerce'), |
|
| 162 | 162 | 'type' => 'string', |
| 163 | - 'context' => array( 'view', 'edit' ), |
|
| 163 | + 'context' => array('view', 'edit'), |
|
| 164 | 164 | 'readonly' => true, |
| 165 | 165 | ), |
| 166 | 166 | 'date_created' => array( |
| 167 | - 'description' => __( 'Date the order was created.', 'woocommerce' ), |
|
| 167 | + 'description' => __('Date the order was created.', 'woocommerce'), |
|
| 168 | 168 | 'type' => 'string', |
| 169 | - 'context' => array( 'view', 'edit' ), |
|
| 169 | + 'context' => array('view', 'edit'), |
|
| 170 | 170 | 'readonly' => true, |
| 171 | 171 | ), |
| 172 | 172 | 'status' => array( |
| 173 | - 'description' => __( 'Order status.', 'woocommerce' ), |
|
| 173 | + 'description' => __('Order status.', 'woocommerce'), |
|
| 174 | 174 | 'type' => 'string', |
| 175 | - 'context' => array( 'view', 'edit' ), |
|
| 175 | + 'context' => array('view', 'edit'), |
|
| 176 | 176 | 'readonly' => true, |
| 177 | 177 | ), |
| 178 | 178 | 'customer_id' => array( |
| 179 | - 'description' => __( 'Customer ID.', 'woocommerce' ), |
|
| 179 | + 'description' => __('Customer ID.', 'woocommerce'), |
|
| 180 | 180 | 'type' => 'integer', |
| 181 | - 'context' => array( 'view', 'edit' ), |
|
| 181 | + 'context' => array('view', 'edit'), |
|
| 182 | 182 | 'readonly' => true, |
| 183 | 183 | ), |
| 184 | 184 | 'num_items_sold' => array( |
| 185 | - 'description' => __( 'Number of items sold.', 'woocommerce' ), |
|
| 185 | + 'description' => __('Number of items sold.', 'woocommerce'), |
|
| 186 | 186 | 'type' => 'integer', |
| 187 | - 'context' => array( 'view', 'edit' ), |
|
| 187 | + 'context' => array('view', 'edit'), |
|
| 188 | 188 | 'readonly' => true, |
| 189 | 189 | ), |
| 190 | 190 | 'net_total' => array( |
| 191 | - 'description' => __( 'Net total revenue.', 'woocommerce' ), |
|
| 191 | + 'description' => __('Net total revenue.', 'woocommerce'), |
|
| 192 | 192 | 'type' => 'float', |
| 193 | - 'context' => array( 'view', 'edit' ), |
|
| 193 | + 'context' => array('view', 'edit'), |
|
| 194 | 194 | 'readonly' => true, |
| 195 | 195 | ), |
| 196 | 196 | 'customer_type' => array( |
| 197 | - 'description' => __( 'Returning or new customer.', 'woocommerce' ), |
|
| 197 | + 'description' => __('Returning or new customer.', 'woocommerce'), |
|
| 198 | 198 | 'type' => 'string', |
| 199 | - 'context' => array( 'view', 'edit' ), |
|
| 199 | + 'context' => array('view', 'edit'), |
|
| 200 | 200 | 'readonly' => true, |
| 201 | 201 | ), |
| 202 | 202 | 'extended_info' => array( |
| 203 | 203 | 'products' => array( |
| 204 | 204 | 'type' => 'array', |
| 205 | 205 | 'readonly' => true, |
| 206 | - 'context' => array( 'view', 'edit' ), |
|
| 207 | - 'description' => __( 'List of product IDs and names.', 'woocommerce' ), |
|
| 206 | + 'context' => array('view', 'edit'), |
|
| 207 | + 'description' => __('List of product IDs and names.', 'woocommerce'), |
|
| 208 | 208 | ), |
| 209 | 209 | 'categories' => array( |
| 210 | 210 | 'type' => 'array', |
| 211 | 211 | 'readonly' => true, |
| 212 | - 'context' => array( 'view', 'edit' ), |
|
| 213 | - 'description' => __( 'Category IDs.', 'woocommerce' ), |
|
| 212 | + 'context' => array('view', 'edit'), |
|
| 213 | + 'description' => __('Category IDs.', 'woocommerce'), |
|
| 214 | 214 | ), |
| 215 | 215 | ), |
| 216 | 216 | ), |
| 217 | 217 | ); |
| 218 | 218 | |
| 219 | - return $this->add_additional_fields_schema( $schema ); |
|
| 219 | + return $this->add_additional_fields_schema($schema); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
@@ -226,17 +226,17 @@ discard block |
||
| 226 | 226 | */ |
| 227 | 227 | public function get_collection_params() { |
| 228 | 228 | $params = array(); |
| 229 | - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); |
|
| 229 | + $params['context'] = $this->get_context_param(array('default' => 'view')); |
|
| 230 | 230 | $params['page'] = array( |
| 231 | - 'description' => __( 'Current page of the collection.', 'woocommerce' ), |
|
| 231 | + 'description' => __('Current page of the collection.', 'woocommerce'), |
|
| 232 | 232 | 'type' => 'integer', |
| 233 | 233 | 'default' => 1, |
| 234 | 234 | 'sanitize_callback' => 'absint', |
| 235 | 235 | 'validate_callback' => 'rest_validate_request_arg', |
| 236 | 236 | 'minimum' => 1, |
| 237 | 237 | ); |
| 238 | - $params['per_page'] = array( |
|
| 239 | - 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ), |
|
| 238 | + $params['per_page'] = array( |
|
| 239 | + 'description' => __('Maximum number of items to be returned in result set.', 'woocommerce'), |
|
| 240 | 240 | 'type' => 'integer', |
| 241 | 241 | 'default' => 10, |
| 242 | 242 | 'minimum' => 0, |
@@ -244,27 +244,27 @@ discard block |
||
| 244 | 244 | 'sanitize_callback' => 'absint', |
| 245 | 245 | 'validate_callback' => 'rest_validate_request_arg', |
| 246 | 246 | ); |
| 247 | - $params['after'] = array( |
|
| 248 | - 'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ), |
|
| 247 | + $params['after'] = array( |
|
| 248 | + 'description' => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'), |
|
| 249 | 249 | 'type' => 'string', |
| 250 | 250 | 'format' => 'date-time', |
| 251 | 251 | 'validate_callback' => 'rest_validate_request_arg', |
| 252 | 252 | ); |
| 253 | - $params['before'] = array( |
|
| 254 | - 'description' => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ), |
|
| 253 | + $params['before'] = array( |
|
| 254 | + 'description' => __('Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce'), |
|
| 255 | 255 | 'type' => 'string', |
| 256 | 256 | 'format' => 'date-time', |
| 257 | 257 | 'validate_callback' => 'rest_validate_request_arg', |
| 258 | 258 | ); |
| 259 | - $params['order'] = array( |
|
| 260 | - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), |
|
| 259 | + $params['order'] = array( |
|
| 260 | + 'description' => __('Order sort attribute ascending or descending.', 'woocommerce'), |
|
| 261 | 261 | 'type' => 'string', |
| 262 | 262 | 'default' => 'desc', |
| 263 | - 'enum' => array( 'asc', 'desc' ), |
|
| 263 | + 'enum' => array('asc', 'desc'), |
|
| 264 | 264 | 'validate_callback' => 'rest_validate_request_arg', |
| 265 | 265 | ); |
| 266 | - $params['orderby'] = array( |
|
| 267 | - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), |
|
| 266 | + $params['orderby'] = array( |
|
| 267 | + 'description' => __('Sort collection by object attribute.', 'woocommerce'), |
|
| 268 | 268 | 'type' => 'string', |
| 269 | 269 | 'default' => 'date', |
| 270 | 270 | 'enum' => array( |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | 'validate_callback' => 'rest_validate_request_arg', |
| 276 | 276 | ); |
| 277 | 277 | $params['product_includes'] = array( |
| 278 | - 'description' => __( 'Limit result set to items that have the specified product(s) assigned.', 'woocommerce' ), |
|
| 278 | + 'description' => __('Limit result set to items that have the specified product(s) assigned.', 'woocommerce'), |
|
| 279 | 279 | 'type' => 'array', |
| 280 | 280 | 'items' => array( |
| 281 | 281 | 'type' => 'integer', |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | 'validate_callback' => 'rest_validate_request_arg', |
| 286 | 286 | ); |
| 287 | 287 | $params['product_excludes'] = array( |
| 288 | - 'description' => __( 'Limit result set to items that don\'t have the specified product(s) assigned.', 'woocommerce' ), |
|
| 288 | + 'description' => __('Limit result set to items that don\'t have the specified product(s) assigned.', 'woocommerce'), |
|
| 289 | 289 | 'type' => 'array', |
| 290 | 290 | 'items' => array( |
| 291 | 291 | 'type' => 'integer', |
@@ -294,8 +294,8 @@ discard block |
||
| 294 | 294 | 'validate_callback' => 'rest_validate_request_arg', |
| 295 | 295 | 'sanitize_callback' => 'wp_parse_id_list', |
| 296 | 296 | ); |
| 297 | - $params['coupon_includes'] = array( |
|
| 298 | - 'description' => __( 'Limit result set to items that have the specified coupon(s) assigned.', 'woocommerce' ), |
|
| 297 | + $params['coupon_includes'] = array( |
|
| 298 | + 'description' => __('Limit result set to items that have the specified coupon(s) assigned.', 'woocommerce'), |
|
| 299 | 299 | 'type' => 'array', |
| 300 | 300 | 'items' => array( |
| 301 | 301 | 'type' => 'integer', |
@@ -304,8 +304,8 @@ discard block |
||
| 304 | 304 | 'sanitize_callback' => 'wp_parse_id_list', |
| 305 | 305 | 'validate_callback' => 'rest_validate_request_arg', |
| 306 | 306 | ); |
| 307 | - $params['coupon_excludes'] = array( |
|
| 308 | - 'description' => __( 'Limit result set to items that don\'t have the specified coupon(s) assigned.', 'woocommerce' ), |
|
| 307 | + $params['coupon_excludes'] = array( |
|
| 308 | + 'description' => __('Limit result set to items that don\'t have the specified coupon(s) assigned.', 'woocommerce'), |
|
| 309 | 309 | 'type' => 'array', |
| 310 | 310 | 'items' => array( |
| 311 | 311 | 'type' => 'integer', |
@@ -314,8 +314,8 @@ discard block |
||
| 314 | 314 | 'validate_callback' => 'rest_validate_request_arg', |
| 315 | 315 | 'sanitize_callback' => 'wp_parse_id_list', |
| 316 | 316 | ); |
| 317 | - $params['status_is'] = array( |
|
| 318 | - 'description' => __( 'Limit result set to items that have the specified order status.', 'woocommerce' ), |
|
| 317 | + $params['status_is'] = array( |
|
| 318 | + 'description' => __('Limit result set to items that have the specified order status.', 'woocommerce'), |
|
| 319 | 319 | 'type' => 'array', |
| 320 | 320 | 'sanitize_callback' => 'wp_parse_slug_list', |
| 321 | 321 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -324,8 +324,8 @@ discard block |
||
| 324 | 324 | 'type' => 'string', |
| 325 | 325 | ), |
| 326 | 326 | ); |
| 327 | - $params['status_is_not'] = array( |
|
| 328 | - 'description' => __( 'Limit result set to items that don\'t have the specified order status.', 'woocommerce' ), |
|
| 327 | + $params['status_is_not'] = array( |
|
| 328 | + 'description' => __('Limit result set to items that don\'t have the specified order status.', 'woocommerce'), |
|
| 329 | 329 | 'type' => 'array', |
| 330 | 330 | 'sanitize_callback' => 'wp_parse_slug_list', |
| 331 | 331 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -334,8 +334,8 @@ discard block |
||
| 334 | 334 | 'type' => 'string', |
| 335 | 335 | ), |
| 336 | 336 | ); |
| 337 | - $params['customer_type'] = array( |
|
| 338 | - 'description' => __( 'Limit result set to returning or new customers.', 'woocommerce' ), |
|
| 337 | + $params['customer_type'] = array( |
|
| 338 | + 'description' => __('Limit result set to returning or new customers.', 'woocommerce'), |
|
| 339 | 339 | 'type' => 'string', |
| 340 | 340 | 'default' => '', |
| 341 | 341 | 'enum' => array( |
@@ -345,8 +345,8 @@ discard block |
||
| 345 | 345 | ), |
| 346 | 346 | 'validate_callback' => 'rest_validate_request_arg', |
| 347 | 347 | ); |
| 348 | - $params['refunds'] = array( |
|
| 349 | - 'description' => __( 'Limit result set to specific types of refunds.', 'woocommerce' ), |
|
| 348 | + $params['refunds'] = array( |
|
| 349 | + 'description' => __('Limit result set to specific types of refunds.', 'woocommerce'), |
|
| 350 | 350 | 'type' => 'string', |
| 351 | 351 | 'default' => '', |
| 352 | 352 | 'enum' => array( |
@@ -358,8 +358,8 @@ discard block |
||
| 358 | 358 | ), |
| 359 | 359 | 'validate_callback' => 'rest_validate_request_arg', |
| 360 | 360 | ); |
| 361 | - $params['extended_info'] = array( |
|
| 362 | - 'description' => __( 'Add additional piece of info about each coupon to the report.', 'woocommerce' ), |
|
| 361 | + $params['extended_info'] = array( |
|
| 362 | + 'description' => __('Add additional piece of info about each coupon to the report.', 'woocommerce'), |
|
| 363 | 363 | 'type' => 'boolean', |
| 364 | 364 | 'default' => false, |
| 365 | 365 | 'sanitize_callback' => 'wc_string_to_bool', |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | namespace WooCommerce\RestApi\Version4\Controllers\Reports; |
| 11 | 11 | |
| 12 | -defined( 'ABSPATH' ) || exit; |
|
| 12 | +defined('ABSPATH') || exit; |
|
| 13 | 13 | |
| 14 | 14 | use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports; |
| 15 | 15 | |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * @param array $request Request array. |
| 32 | 32 | * @return array |
| 33 | 33 | */ |
| 34 | - protected function prepare_reports_query( $request ) { |
|
| 34 | + protected function prepare_reports_query($request) { |
|
| 35 | 35 | $args = array(); |
| 36 | 36 | $args['registered_before'] = $request['registered_before']; |
| 37 | 37 | $args['registered_after'] = $request['registered_after']; |
@@ -57,11 +57,11 @@ discard block |
||
| 57 | 57 | $args['last_order_after'] = $request['last_order_after']; |
| 58 | 58 | $args['customers'] = $request['customers']; |
| 59 | 59 | |
| 60 | - $between_params_numeric = array( 'orders_count', 'total_spend', 'avg_order_value' ); |
|
| 61 | - $normalized_params_numeric = \WC_Admin_Reports_Interval::normalize_between_params( $request, $between_params_numeric, false ); |
|
| 62 | - $between_params_date = array( 'last_active', 'registered' ); |
|
| 63 | - $normalized_params_date = \WC_Admin_Reports_Interval::normalize_between_params( $request, $between_params_date, true ); |
|
| 64 | - $args = array_merge( $args, $normalized_params_numeric, $normalized_params_date ); |
|
| 60 | + $between_params_numeric = array('orders_count', 'total_spend', 'avg_order_value'); |
|
| 61 | + $normalized_params_numeric = \WC_Admin_Reports_Interval::normalize_between_params($request, $between_params_numeric, false); |
|
| 62 | + $between_params_date = array('last_active', 'registered'); |
|
| 63 | + $normalized_params_date = \WC_Admin_Reports_Interval::normalize_between_params($request, $between_params_date, true); |
|
| 64 | + $args = array_merge($args, $normalized_params_numeric, $normalized_params_date); |
|
| 65 | 65 | |
| 66 | 66 | return $args; |
| 67 | 67 | } |
@@ -72,15 +72,15 @@ discard block |
||
| 72 | 72 | * @param \WP_REST_Request $request Request data. |
| 73 | 73 | * @return array|\WP_Error |
| 74 | 74 | */ |
| 75 | - public function get_items( $request ) { |
|
| 76 | - $query_args = $this->prepare_reports_query( $request ); |
|
| 77 | - $customers_query = new \WC_Admin_Reports_Customers_Stats_Query( $query_args ); |
|
| 75 | + public function get_items($request) { |
|
| 76 | + $query_args = $this->prepare_reports_query($request); |
|
| 77 | + $customers_query = new \WC_Admin_Reports_Customers_Stats_Query($query_args); |
|
| 78 | 78 | $report_data = $customers_query->get_data(); |
| 79 | 79 | $out_data = array( |
| 80 | 80 | 'totals' => $report_data, |
| 81 | 81 | ); |
| 82 | 82 | |
| 83 | - return rest_ensure_response( $out_data ); |
|
| 83 | + return rest_ensure_response($out_data); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -90,15 +90,15 @@ discard block |
||
| 90 | 90 | * @param \WP_REST_Request $request Request object. |
| 91 | 91 | * @return \WP_REST_Response |
| 92 | 92 | */ |
| 93 | - public function prepare_item_for_response( $report, $request ) { |
|
| 93 | + public function prepare_item_for_response($report, $request) { |
|
| 94 | 94 | $data = $report; |
| 95 | 95 | |
| 96 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 97 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
| 98 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 96 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
| 97 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
| 98 | + $data = $this->filter_response_by_context($data, $context); |
|
| 99 | 99 | |
| 100 | 100 | // Wrap the data in a response object. |
| 101 | - $response = rest_ensure_response( $data ); |
|
| 101 | + $response = rest_ensure_response($data); |
|
| 102 | 102 | |
| 103 | 103 | /** |
| 104 | 104 | * Filter a report returned from the API. |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | * @param object $report The original report object. |
| 110 | 110 | * @param \WP_REST_Request $request Request used to generate the response. |
| 111 | 111 | */ |
| 112 | - return apply_filters( 'woocommerce_rest_prepare_report_customers_stats', $response, $report, $request ); |
|
| 112 | + return apply_filters('woocommerce_rest_prepare_report_customers_stats', $response, $report, $request); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
@@ -121,28 +121,28 @@ discard block |
||
| 121 | 121 | // @todo Should any of these be 'indicator's? |
| 122 | 122 | $totals = array( |
| 123 | 123 | 'customers_count' => array( |
| 124 | - 'description' => __( 'Number of customers.', 'woocommerce' ), |
|
| 124 | + 'description' => __('Number of customers.', 'woocommerce'), |
|
| 125 | 125 | 'type' => 'integer', |
| 126 | - 'context' => array( 'view', 'edit' ), |
|
| 126 | + 'context' => array('view', 'edit'), |
|
| 127 | 127 | 'readonly' => true, |
| 128 | 128 | ), |
| 129 | 129 | 'avg_orders_count' => array( |
| 130 | - 'description' => __( 'Average number of orders.', 'woocommerce' ), |
|
| 130 | + 'description' => __('Average number of orders.', 'woocommerce'), |
|
| 131 | 131 | 'type' => 'integer', |
| 132 | - 'context' => array( 'view', 'edit' ), |
|
| 132 | + 'context' => array('view', 'edit'), |
|
| 133 | 133 | 'readonly' => true, |
| 134 | 134 | ), |
| 135 | 135 | 'avg_total_spend' => array( |
| 136 | - 'description' => __( 'Average total spend per customer.', 'woocommerce' ), |
|
| 136 | + 'description' => __('Average total spend per customer.', 'woocommerce'), |
|
| 137 | 137 | 'type' => 'number', |
| 138 | - 'context' => array( 'view', 'edit' ), |
|
| 138 | + 'context' => array('view', 'edit'), |
|
| 139 | 139 | 'readonly' => true, |
| 140 | 140 | 'format' => 'currency', |
| 141 | 141 | ), |
| 142 | 142 | 'avg_avg_order_value' => array( |
| 143 | - 'description' => __( 'Average AOV per customer.', 'woocommerce' ), |
|
| 143 | + 'description' => __('Average AOV per customer.', 'woocommerce'), |
|
| 144 | 144 | 'type' => 'number', |
| 145 | - 'context' => array( 'view', 'edit' ), |
|
| 145 | + 'context' => array('view', 'edit'), |
|
| 146 | 146 | 'readonly' => true, |
| 147 | 147 | 'format' => 'currency', |
| 148 | 148 | ), |
@@ -154,16 +154,16 @@ discard block |
||
| 154 | 154 | 'type' => 'object', |
| 155 | 155 | 'properties' => array( |
| 156 | 156 | 'totals' => array( |
| 157 | - 'description' => __( 'Totals data.', 'woocommerce' ), |
|
| 157 | + 'description' => __('Totals data.', 'woocommerce'), |
|
| 158 | 158 | 'type' => 'object', |
| 159 | - 'context' => array( 'view', 'edit' ), |
|
| 159 | + 'context' => array('view', 'edit'), |
|
| 160 | 160 | 'readonly' => true, |
| 161 | 161 | 'properties' => $totals, |
| 162 | 162 | ), |
| 163 | 163 | ), |
| 164 | 164 | ); |
| 165 | 165 | |
| 166 | - return $this->add_additional_fields_schema( $schema ); |
|
| 166 | + return $this->add_additional_fields_schema($schema); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** |
@@ -173,21 +173,21 @@ discard block |
||
| 173 | 173 | */ |
| 174 | 174 | public function get_collection_params() { |
| 175 | 175 | $params = array(); |
| 176 | - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); |
|
| 176 | + $params['context'] = $this->get_context_param(array('default' => 'view')); |
|
| 177 | 177 | $params['registered_before'] = array( |
| 178 | - 'description' => __( 'Limit response to objects registered before (or at) a given ISO8601 compliant datetime.', 'woocommerce' ), |
|
| 178 | + 'description' => __('Limit response to objects registered before (or at) a given ISO8601 compliant datetime.', 'woocommerce'), |
|
| 179 | 179 | 'type' => 'string', |
| 180 | 180 | 'format' => 'date-time', |
| 181 | 181 | 'validate_callback' => 'rest_validate_request_arg', |
| 182 | 182 | ); |
| 183 | - $params['registered_after'] = array( |
|
| 184 | - 'description' => __( 'Limit response to objects registered after (or at) a given ISO8601 compliant datetime.', 'woocommerce' ), |
|
| 183 | + $params['registered_after'] = array( |
|
| 184 | + 'description' => __('Limit response to objects registered after (or at) a given ISO8601 compliant datetime.', 'woocommerce'), |
|
| 185 | 185 | 'type' => 'string', |
| 186 | 186 | 'format' => 'date-time', |
| 187 | 187 | 'validate_callback' => 'rest_validate_request_arg', |
| 188 | 188 | ); |
| 189 | - $params['match'] = array( |
|
| 190 | - 'description' => __( 'Indicates whether all the conditions should be true for the resulting set, or if any one of them is sufficient. Match affects the following parameters: status_is, status_is_not, product_includes, product_excludes, coupon_includes, coupon_excludes, customer, categories', 'woocommerce' ), |
|
| 189 | + $params['match'] = array( |
|
| 190 | + 'description' => __('Indicates whether all the conditions should be true for the resulting set, or if any one of them is sufficient. Match affects the following parameters: status_is, status_is_not, product_includes, product_excludes, coupon_includes, coupon_excludes, customer, categories', 'woocommerce'), |
|
| 191 | 191 | 'type' => 'string', |
| 192 | 192 | 'default' => 'all', |
| 193 | 193 | 'enum' => array( |
@@ -196,12 +196,12 @@ discard block |
||
| 196 | 196 | ), |
| 197 | 197 | 'validate_callback' => 'rest_validate_request_arg', |
| 198 | 198 | ); |
| 199 | - $params['search'] = array( |
|
| 200 | - 'description' => __( 'Limit response to objects with a customer field containing the search term. Searches the field provided by `searchby`.', 'woocommerce' ), |
|
| 199 | + $params['search'] = array( |
|
| 200 | + 'description' => __('Limit response to objects with a customer field containing the search term. Searches the field provided by `searchby`.', 'woocommerce'), |
|
| 201 | 201 | 'type' => 'string', |
| 202 | 202 | 'validate_callback' => 'rest_validate_request_arg', |
| 203 | 203 | ); |
| 204 | - $params['searchby'] = array( |
|
| 204 | + $params['searchby'] = array( |
|
| 205 | 205 | 'description' => 'Limit results with `search` and `searchby` to specific fields containing the search term.', |
| 206 | 206 | 'type' => 'string', |
| 207 | 207 | 'default' => 'name', |
@@ -211,141 +211,141 @@ discard block |
||
| 211 | 211 | 'email', |
| 212 | 212 | ), |
| 213 | 213 | ); |
| 214 | - $params['name_includes'] = array( |
|
| 215 | - 'description' => __( 'Limit response to objects with specfic names.', 'woocommerce' ), |
|
| 214 | + $params['name_includes'] = array( |
|
| 215 | + 'description' => __('Limit response to objects with specfic names.', 'woocommerce'), |
|
| 216 | 216 | 'type' => 'string', |
| 217 | 217 | 'validate_callback' => 'rest_validate_request_arg', |
| 218 | 218 | ); |
| 219 | - $params['name_excludes'] = array( |
|
| 220 | - 'description' => __( 'Limit response to objects excluding specfic names.', 'woocommerce' ), |
|
| 219 | + $params['name_excludes'] = array( |
|
| 220 | + 'description' => __('Limit response to objects excluding specfic names.', 'woocommerce'), |
|
| 221 | 221 | 'type' => 'string', |
| 222 | 222 | 'validate_callback' => 'rest_validate_request_arg', |
| 223 | 223 | ); |
| 224 | - $params['username_includes'] = array( |
|
| 225 | - 'description' => __( 'Limit response to objects with specfic usernames.', 'woocommerce' ), |
|
| 224 | + $params['username_includes'] = array( |
|
| 225 | + 'description' => __('Limit response to objects with specfic usernames.', 'woocommerce'), |
|
| 226 | 226 | 'type' => 'string', |
| 227 | 227 | 'validate_callback' => 'rest_validate_request_arg', |
| 228 | 228 | ); |
| 229 | - $params['username_excludes'] = array( |
|
| 230 | - 'description' => __( 'Limit response to objects excluding specfic usernames.', 'woocommerce' ), |
|
| 229 | + $params['username_excludes'] = array( |
|
| 230 | + 'description' => __('Limit response to objects excluding specfic usernames.', 'woocommerce'), |
|
| 231 | 231 | 'type' => 'string', |
| 232 | 232 | 'validate_callback' => 'rest_validate_request_arg', |
| 233 | 233 | ); |
| 234 | - $params['email_includes'] = array( |
|
| 235 | - 'description' => __( 'Limit response to objects including emails.', 'woocommerce' ), |
|
| 234 | + $params['email_includes'] = array( |
|
| 235 | + 'description' => __('Limit response to objects including emails.', 'woocommerce'), |
|
| 236 | 236 | 'type' => 'string', |
| 237 | 237 | 'validate_callback' => 'rest_validate_request_arg', |
| 238 | 238 | ); |
| 239 | - $params['email_excludes'] = array( |
|
| 240 | - 'description' => __( 'Limit response to objects excluding emails.', 'woocommerce' ), |
|
| 239 | + $params['email_excludes'] = array( |
|
| 240 | + 'description' => __('Limit response to objects excluding emails.', 'woocommerce'), |
|
| 241 | 241 | 'type' => 'string', |
| 242 | 242 | 'validate_callback' => 'rest_validate_request_arg', |
| 243 | 243 | ); |
| 244 | - $params['country_includes'] = array( |
|
| 245 | - 'description' => __( 'Limit response to objects with specfic countries.', 'woocommerce' ), |
|
| 244 | + $params['country_includes'] = array( |
|
| 245 | + 'description' => __('Limit response to objects with specfic countries.', 'woocommerce'), |
|
| 246 | 246 | 'type' => 'string', |
| 247 | 247 | 'validate_callback' => 'rest_validate_request_arg', |
| 248 | 248 | ); |
| 249 | - $params['country_excludes'] = array( |
|
| 250 | - 'description' => __( 'Limit response to objects excluding specfic countries.', 'woocommerce' ), |
|
| 249 | + $params['country_excludes'] = array( |
|
| 250 | + 'description' => __('Limit response to objects excluding specfic countries.', 'woocommerce'), |
|
| 251 | 251 | 'type' => 'string', |
| 252 | 252 | 'validate_callback' => 'rest_validate_request_arg', |
| 253 | 253 | ); |
| 254 | - $params['last_active_before'] = array( |
|
| 255 | - 'description' => __( 'Limit response to objects last active before (or at) a given ISO8601 compliant datetime.', 'woocommerce' ), |
|
| 254 | + $params['last_active_before'] = array( |
|
| 255 | + 'description' => __('Limit response to objects last active before (or at) a given ISO8601 compliant datetime.', 'woocommerce'), |
|
| 256 | 256 | 'type' => 'string', |
| 257 | 257 | 'format' => 'date-time', |
| 258 | 258 | 'validate_callback' => 'rest_validate_request_arg', |
| 259 | 259 | ); |
| 260 | - $params['last_active_after'] = array( |
|
| 261 | - 'description' => __( 'Limit response to objects last active after (or at) a given ISO8601 compliant datetime.', 'woocommerce' ), |
|
| 260 | + $params['last_active_after'] = array( |
|
| 261 | + 'description' => __('Limit response to objects last active after (or at) a given ISO8601 compliant datetime.', 'woocommerce'), |
|
| 262 | 262 | 'type' => 'string', |
| 263 | 263 | 'format' => 'date-time', |
| 264 | 264 | 'validate_callback' => 'rest_validate_request_arg', |
| 265 | 265 | ); |
| 266 | - $params['last_active_between'] = array( |
|
| 267 | - 'description' => __( 'Limit response to objects last active between two given ISO8601 compliant datetime.', 'woocommerce' ), |
|
| 266 | + $params['last_active_between'] = array( |
|
| 267 | + 'description' => __('Limit response to objects last active between two given ISO8601 compliant datetime.', 'woocommerce'), |
|
| 268 | 268 | 'type' => 'array', |
| 269 | - 'validate_callback' => array( 'WC_Admin_Reports_Interval', 'rest_validate_between_date_arg' ), |
|
| 269 | + 'validate_callback' => array('WC_Admin_Reports_Interval', 'rest_validate_between_date_arg'), |
|
| 270 | 270 | ); |
| 271 | - $params['registered_before'] = array( |
|
| 272 | - 'description' => __( 'Limit response to objects registered before (or at) a given ISO8601 compliant datetime.', 'woocommerce' ), |
|
| 271 | + $params['registered_before'] = array( |
|
| 272 | + 'description' => __('Limit response to objects registered before (or at) a given ISO8601 compliant datetime.', 'woocommerce'), |
|
| 273 | 273 | 'type' => 'string', |
| 274 | 274 | 'format' => 'date-time', |
| 275 | 275 | 'validate_callback' => 'rest_validate_request_arg', |
| 276 | 276 | ); |
| 277 | - $params['registered_after'] = array( |
|
| 278 | - 'description' => __( 'Limit response to objects registered after (or at) a given ISO8601 compliant datetime.', 'woocommerce' ), |
|
| 277 | + $params['registered_after'] = array( |
|
| 278 | + 'description' => __('Limit response to objects registered after (or at) a given ISO8601 compliant datetime.', 'woocommerce'), |
|
| 279 | 279 | 'type' => 'string', |
| 280 | 280 | 'format' => 'date-time', |
| 281 | 281 | 'validate_callback' => 'rest_validate_request_arg', |
| 282 | 282 | ); |
| 283 | - $params['registered_between'] = array( |
|
| 284 | - 'description' => __( 'Limit response to objects last active between two given ISO8601 compliant datetime.', 'woocommerce' ), |
|
| 283 | + $params['registered_between'] = array( |
|
| 284 | + 'description' => __('Limit response to objects last active between two given ISO8601 compliant datetime.', 'woocommerce'), |
|
| 285 | 285 | 'type' => 'array', |
| 286 | - 'validate_callback' => array( 'WC_Admin_Reports_Interval', 'rest_validate_between_date_arg' ), |
|
| 286 | + 'validate_callback' => array('WC_Admin_Reports_Interval', 'rest_validate_between_date_arg'), |
|
| 287 | 287 | ); |
| 288 | - $params['orders_count_min'] = array( |
|
| 289 | - 'description' => __( 'Limit response to objects with an order count greater than or equal to given integer.', 'woocommerce' ), |
|
| 288 | + $params['orders_count_min'] = array( |
|
| 289 | + 'description' => __('Limit response to objects with an order count greater than or equal to given integer.', 'woocommerce'), |
|
| 290 | 290 | 'type' => 'integer', |
| 291 | 291 | 'sanitize_callback' => 'absint', |
| 292 | 292 | 'validate_callback' => 'rest_validate_request_arg', |
| 293 | 293 | ); |
| 294 | - $params['orders_count_max'] = array( |
|
| 295 | - 'description' => __( 'Limit response to objects with an order count less than or equal to given integer.', 'woocommerce' ), |
|
| 294 | + $params['orders_count_max'] = array( |
|
| 295 | + 'description' => __('Limit response to objects with an order count less than or equal to given integer.', 'woocommerce'), |
|
| 296 | 296 | 'type' => 'integer', |
| 297 | 297 | 'sanitize_callback' => 'absint', |
| 298 | 298 | 'validate_callback' => 'rest_validate_request_arg', |
| 299 | 299 | ); |
| 300 | - $params['orders_count_between'] = array( |
|
| 301 | - 'description' => __( 'Limit response to objects with an order count between two given integers.', 'woocommerce' ), |
|
| 300 | + $params['orders_count_between'] = array( |
|
| 301 | + 'description' => __('Limit response to objects with an order count between two given integers.', 'woocommerce'), |
|
| 302 | 302 | 'type' => 'array', |
| 303 | - 'validate_callback' => array( 'WC_Admin_Reports_Interval', 'rest_validate_between_numeric_arg' ), |
|
| 303 | + 'validate_callback' => array('WC_Admin_Reports_Interval', 'rest_validate_between_numeric_arg'), |
|
| 304 | 304 | ); |
| 305 | - $params['total_spend_min'] = array( |
|
| 306 | - 'description' => __( 'Limit response to objects with a total order spend greater than or equal to given number.', 'woocommerce' ), |
|
| 305 | + $params['total_spend_min'] = array( |
|
| 306 | + 'description' => __('Limit response to objects with a total order spend greater than or equal to given number.', 'woocommerce'), |
|
| 307 | 307 | 'type' => 'number', |
| 308 | 308 | 'validate_callback' => 'rest_validate_request_arg', |
| 309 | 309 | ); |
| 310 | - $params['total_spend_max'] = array( |
|
| 311 | - 'description' => __( 'Limit response to objects with a total order spend less than or equal to given number.', 'woocommerce' ), |
|
| 310 | + $params['total_spend_max'] = array( |
|
| 311 | + 'description' => __('Limit response to objects with a total order spend less than or equal to given number.', 'woocommerce'), |
|
| 312 | 312 | 'type' => 'number', |
| 313 | 313 | 'validate_callback' => 'rest_validate_request_arg', |
| 314 | 314 | ); |
| 315 | - $params['total_spend_between'] = array( |
|
| 316 | - 'description' => __( 'Limit response to objects with a total order spend between two given numbers.', 'woocommerce' ), |
|
| 315 | + $params['total_spend_between'] = array( |
|
| 316 | + 'description' => __('Limit response to objects with a total order spend between two given numbers.', 'woocommerce'), |
|
| 317 | 317 | 'type' => 'array', |
| 318 | - 'validate_callback' => array( 'WC_Admin_Reports_Interval', 'rest_validate_between_numeric_arg' ), |
|
| 318 | + 'validate_callback' => array('WC_Admin_Reports_Interval', 'rest_validate_between_numeric_arg'), |
|
| 319 | 319 | ); |
| 320 | - $params['avg_order_value_min'] = array( |
|
| 321 | - 'description' => __( 'Limit response to objects with an average order spend greater than or equal to given number.', 'woocommerce' ), |
|
| 320 | + $params['avg_order_value_min'] = array( |
|
| 321 | + 'description' => __('Limit response to objects with an average order spend greater than or equal to given number.', 'woocommerce'), |
|
| 322 | 322 | 'type' => 'number', |
| 323 | 323 | 'validate_callback' => 'rest_validate_request_arg', |
| 324 | 324 | ); |
| 325 | - $params['avg_order_value_max'] = array( |
|
| 326 | - 'description' => __( 'Limit response to objects with an average order spend less than or equal to given number.', 'woocommerce' ), |
|
| 325 | + $params['avg_order_value_max'] = array( |
|
| 326 | + 'description' => __('Limit response to objects with an average order spend less than or equal to given number.', 'woocommerce'), |
|
| 327 | 327 | 'type' => 'number', |
| 328 | 328 | 'validate_callback' => 'rest_validate_request_arg', |
| 329 | 329 | ); |
| 330 | 330 | $params['avg_order_value_between'] = array( |
| 331 | - 'description' => __( 'Limit response to objects with an average order spend between two given numbers.', 'woocommerce' ), |
|
| 331 | + 'description' => __('Limit response to objects with an average order spend between two given numbers.', 'woocommerce'), |
|
| 332 | 332 | 'type' => 'array', |
| 333 | - 'validate_callback' => array( 'WC_Admin_Reports_Interval', 'rest_validate_between_numeric_arg' ), |
|
| 333 | + 'validate_callback' => array('WC_Admin_Reports_Interval', 'rest_validate_between_numeric_arg'), |
|
| 334 | 334 | ); |
| 335 | - $params['last_order_before'] = array( |
|
| 336 | - 'description' => __( 'Limit response to objects with last order before (or at) a given ISO8601 compliant datetime.', 'woocommerce' ), |
|
| 335 | + $params['last_order_before'] = array( |
|
| 336 | + 'description' => __('Limit response to objects with last order before (or at) a given ISO8601 compliant datetime.', 'woocommerce'), |
|
| 337 | 337 | 'type' => 'string', |
| 338 | 338 | 'format' => 'date-time', |
| 339 | 339 | 'validate_callback' => 'rest_validate_request_arg', |
| 340 | 340 | ); |
| 341 | - $params['last_order_after'] = array( |
|
| 342 | - 'description' => __( 'Limit response to objects with last order after (or at) a given ISO8601 compliant datetime.', 'woocommerce' ), |
|
| 341 | + $params['last_order_after'] = array( |
|
| 342 | + 'description' => __('Limit response to objects with last order after (or at) a given ISO8601 compliant datetime.', 'woocommerce'), |
|
| 343 | 343 | 'type' => 'string', |
| 344 | 344 | 'format' => 'date-time', |
| 345 | 345 | 'validate_callback' => 'rest_validate_request_arg', |
| 346 | 346 | ); |
| 347 | - $params['customers'] = array( |
|
| 348 | - 'description' => __( 'Limit result to items with specified customer ids.', 'woocommerce' ), |
|
| 347 | + $params['customers'] = array( |
|
| 348 | + 'description' => __('Limit result to items with specified customer ids.', 'woocommerce'), |
|
| 349 | 349 | 'type' => 'array', |
| 350 | 350 | 'sanitize_callback' => 'wp_parse_id_list', |
| 351 | 351 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | namespace WooCommerce\RestApi\Version4\Controllers\Reports; |
| 11 | 11 | |
| 12 | -defined( 'ABSPATH' ) || exit; |
|
| 12 | +defined('ABSPATH') || exit; |
|
| 13 | 13 | |
| 14 | 14 | use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports; |
| 15 | 15 | |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * @param array $request Request array. |
| 32 | 32 | * @return array |
| 33 | 33 | */ |
| 34 | - protected function prepare_reports_query( $request ) { |
|
| 34 | + protected function prepare_reports_query($request) { |
|
| 35 | 35 | $args = array(); |
| 36 | 36 | $args['registered_before'] = $request['registered_before']; |
| 37 | 37 | $args['registered_after'] = $request['registered_after']; |
@@ -64,11 +64,11 @@ discard block |
||
| 64 | 64 | $args['last_order_after'] = $request['last_order_after']; |
| 65 | 65 | $args['customers'] = $request['customers']; |
| 66 | 66 | |
| 67 | - $between_params_numeric = array( 'orders_count', 'total_spend', 'avg_order_value' ); |
|
| 68 | - $normalized_params_numeric = \WC_Admin_Reports_Interval::normalize_between_params( $request, $between_params_numeric, false ); |
|
| 69 | - $between_params_date = array( 'last_active', 'registered' ); |
|
| 70 | - $normalized_params_date = \WC_Admin_Reports_Interval::normalize_between_params( $request, $between_params_date, true ); |
|
| 71 | - $args = array_merge( $args, $normalized_params_numeric, $normalized_params_date ); |
|
| 67 | + $between_params_numeric = array('orders_count', 'total_spend', 'avg_order_value'); |
|
| 68 | + $normalized_params_numeric = \WC_Admin_Reports_Interval::normalize_between_params($request, $between_params_numeric, false); |
|
| 69 | + $between_params_date = array('last_active', 'registered'); |
|
| 70 | + $normalized_params_date = \WC_Admin_Reports_Interval::normalize_between_params($request, $between_params_date, true); |
|
| 71 | + $args = array_merge($args, $normalized_params_numeric, $normalized_params_date); |
|
| 72 | 72 | |
| 73 | 73 | return $args; |
| 74 | 74 | } |
@@ -79,37 +79,37 @@ discard block |
||
| 79 | 79 | * @param \WP_REST_Request $request Request data. |
| 80 | 80 | * @return array|\WP_Error |
| 81 | 81 | */ |
| 82 | - public function get_items( $request ) { |
|
| 83 | - $query_args = $this->prepare_reports_query( $request ); |
|
| 84 | - $customers_query = new \WC_Admin_Reports_Customers_Query( $query_args ); |
|
| 82 | + public function get_items($request) { |
|
| 83 | + $query_args = $this->prepare_reports_query($request); |
|
| 84 | + $customers_query = new \WC_Admin_Reports_Customers_Query($query_args); |
|
| 85 | 85 | $report_data = $customers_query->get_data(); |
| 86 | 86 | |
| 87 | 87 | $data = array(); |
| 88 | 88 | |
| 89 | - foreach ( $report_data->data as $customer_data ) { |
|
| 90 | - $item = $this->prepare_item_for_response( $customer_data, $request ); |
|
| 91 | - $data[] = $this->prepare_response_for_collection( $item ); |
|
| 89 | + foreach ($report_data->data as $customer_data) { |
|
| 90 | + $item = $this->prepare_item_for_response($customer_data, $request); |
|
| 91 | + $data[] = $this->prepare_response_for_collection($item); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - $response = rest_ensure_response( $data ); |
|
| 95 | - $response->header( 'X-WP-Total', (int) $report_data->total ); |
|
| 96 | - $response->header( 'X-WP-TotalPages', (int) $report_data->pages ); |
|
| 94 | + $response = rest_ensure_response($data); |
|
| 95 | + $response->header('X-WP-Total', (int) $report_data->total); |
|
| 96 | + $response->header('X-WP-TotalPages', (int) $report_data->pages); |
|
| 97 | 97 | |
| 98 | 98 | $page = $report_data->page_no; |
| 99 | 99 | $max_pages = $report_data->pages; |
| 100 | - $base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) ); |
|
| 101 | - if ( $page > 1 ) { |
|
| 100 | + $base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base))); |
|
| 101 | + if ($page > 1) { |
|
| 102 | 102 | $prev_page = $page - 1; |
| 103 | - if ( $prev_page > $max_pages ) { |
|
| 103 | + if ($prev_page > $max_pages) { |
|
| 104 | 104 | $prev_page = $max_pages; |
| 105 | 105 | } |
| 106 | - $prev_link = add_query_arg( 'page', $prev_page, $base ); |
|
| 107 | - $response->link_header( 'prev', $prev_link ); |
|
| 106 | + $prev_link = add_query_arg('page', $prev_page, $base); |
|
| 107 | + $response->link_header('prev', $prev_link); |
|
| 108 | 108 | } |
| 109 | - if ( $max_pages > $page ) { |
|
| 109 | + if ($max_pages > $page) { |
|
| 110 | 110 | $next_page = $page + 1; |
| 111 | - $next_link = add_query_arg( 'page', $next_page, $base ); |
|
| 112 | - $response->link_header( 'next', $next_link ); |
|
| 111 | + $next_link = add_query_arg('page', $next_page, $base); |
|
| 112 | + $response->link_header('next', $next_link); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | return $response; |
@@ -122,18 +122,18 @@ discard block |
||
| 122 | 122 | * @param \WP_REST_Request $request Request object. |
| 123 | 123 | * @return \WP_REST_Response |
| 124 | 124 | */ |
| 125 | - public function prepare_item_for_response( $report, $request ) { |
|
| 126 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 127 | - $data = $this->add_additional_fields_to_object( $report, $request ); |
|
| 128 | - $data['date_registered_gmt'] = wc_rest_prepare_date_response( $data['date_registered'] ); |
|
| 129 | - $data['date_registered'] = wc_rest_prepare_date_response( $data['date_registered'], false ); |
|
| 130 | - $data['date_last_active_gmt'] = wc_rest_prepare_date_response( $data['date_last_active'] ); |
|
| 131 | - $data['date_last_active'] = wc_rest_prepare_date_response( $data['date_last_active'], false ); |
|
| 132 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 125 | + public function prepare_item_for_response($report, $request) { |
|
| 126 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
| 127 | + $data = $this->add_additional_fields_to_object($report, $request); |
|
| 128 | + $data['date_registered_gmt'] = wc_rest_prepare_date_response($data['date_registered']); |
|
| 129 | + $data['date_registered'] = wc_rest_prepare_date_response($data['date_registered'], false); |
|
| 130 | + $data['date_last_active_gmt'] = wc_rest_prepare_date_response($data['date_last_active']); |
|
| 131 | + $data['date_last_active'] = wc_rest_prepare_date_response($data['date_last_active'], false); |
|
| 132 | + $data = $this->filter_response_by_context($data, $context); |
|
| 133 | 133 | |
| 134 | 134 | // Wrap the data in a response object. |
| 135 | - $response = rest_ensure_response( $data ); |
|
| 136 | - $response->add_links( $this->prepare_links( $report ) ); |
|
| 135 | + $response = rest_ensure_response($data); |
|
| 136 | + $response->add_links($this->prepare_links($report)); |
|
| 137 | 137 | /** |
| 138 | 138 | * Filter a report returned from the API. |
| 139 | 139 | * |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | * @param object $report The original report object. |
| 144 | 144 | * @param \WP_REST_Request $request Request used to generate the response. |
| 145 | 145 | */ |
| 146 | - return apply_filters( 'woocommerce_rest_prepare_report_customers', $response, $report, $request ); |
|
| 146 | + return apply_filters('woocommerce_rest_prepare_report_customers', $response, $report, $request); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -152,14 +152,14 @@ discard block |
||
| 152 | 152 | * @param array $object Object data. |
| 153 | 153 | * @return array |
| 154 | 154 | */ |
| 155 | - protected function prepare_links( $object ) { |
|
| 156 | - if ( empty( $object['user_id'] ) ) { |
|
| 155 | + protected function prepare_links($object) { |
|
| 156 | + if (empty($object['user_id'])) { |
|
| 157 | 157 | return array(); |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | return array( |
| 161 | 161 | 'customer' => array( |
| 162 | - 'href' => rest_url( sprintf( '/%s/customers/%d', $this->namespace, $object['user_id'] ) ), |
|
| 162 | + 'href' => rest_url(sprintf('/%s/customers/%d', $this->namespace, $object['user_id'])), |
|
| 163 | 163 | ), |
| 164 | 164 | ); |
| 165 | 165 | } |
@@ -176,92 +176,92 @@ discard block |
||
| 176 | 176 | 'type' => 'object', |
| 177 | 177 | 'properties' => array( |
| 178 | 178 | 'id' => array( |
| 179 | - 'description' => __( 'Customer ID.', 'woocommerce' ), |
|
| 179 | + 'description' => __('Customer ID.', 'woocommerce'), |
|
| 180 | 180 | 'type' => 'integer', |
| 181 | - 'context' => array( 'view', 'edit' ), |
|
| 181 | + 'context' => array('view', 'edit'), |
|
| 182 | 182 | 'readonly' => true, |
| 183 | 183 | ), |
| 184 | 184 | 'user_id' => array( |
| 185 | - 'description' => __( 'User ID.', 'woocommerce' ), |
|
| 185 | + 'description' => __('User ID.', 'woocommerce'), |
|
| 186 | 186 | 'type' => 'integer', |
| 187 | - 'context' => array( 'view', 'edit' ), |
|
| 187 | + 'context' => array('view', 'edit'), |
|
| 188 | 188 | 'readonly' => true, |
| 189 | 189 | ), |
| 190 | 190 | 'name' => array( |
| 191 | - 'description' => __( 'Name.', 'woocommerce' ), |
|
| 191 | + 'description' => __('Name.', 'woocommerce'), |
|
| 192 | 192 | 'type' => 'string', |
| 193 | - 'context' => array( 'view', 'edit' ), |
|
| 193 | + 'context' => array('view', 'edit'), |
|
| 194 | 194 | 'readonly' => true, |
| 195 | 195 | ), |
| 196 | 196 | 'username' => array( |
| 197 | - 'description' => __( 'Username.', 'woocommerce' ), |
|
| 197 | + 'description' => __('Username.', 'woocommerce'), |
|
| 198 | 198 | 'type' => 'string', |
| 199 | - 'context' => array( 'view', 'edit' ), |
|
| 199 | + 'context' => array('view', 'edit'), |
|
| 200 | 200 | 'readonly' => true, |
| 201 | 201 | ), |
| 202 | 202 | 'country' => array( |
| 203 | - 'description' => __( 'Country.', 'woocommerce' ), |
|
| 203 | + 'description' => __('Country.', 'woocommerce'), |
|
| 204 | 204 | 'type' => 'string', |
| 205 | - 'context' => array( 'view', 'edit' ), |
|
| 205 | + 'context' => array('view', 'edit'), |
|
| 206 | 206 | 'readonly' => true, |
| 207 | 207 | ), |
| 208 | 208 | 'city' => array( |
| 209 | - 'description' => __( 'City.', 'woocommerce' ), |
|
| 209 | + 'description' => __('City.', 'woocommerce'), |
|
| 210 | 210 | 'type' => 'string', |
| 211 | - 'context' => array( 'view', 'edit' ), |
|
| 211 | + 'context' => array('view', 'edit'), |
|
| 212 | 212 | 'readonly' => true, |
| 213 | 213 | ), |
| 214 | 214 | 'postcode' => array( |
| 215 | - 'description' => __( 'Postal code.', 'woocommerce' ), |
|
| 215 | + 'description' => __('Postal code.', 'woocommerce'), |
|
| 216 | 216 | 'type' => 'string', |
| 217 | - 'context' => array( 'view', 'edit' ), |
|
| 217 | + 'context' => array('view', 'edit'), |
|
| 218 | 218 | 'readonly' => true, |
| 219 | 219 | ), |
| 220 | 220 | 'date_registered' => array( |
| 221 | - 'description' => __( 'Date registered.', 'woocommerce' ), |
|
| 221 | + 'description' => __('Date registered.', 'woocommerce'), |
|
| 222 | 222 | 'type' => 'date-time', |
| 223 | - 'context' => array( 'view', 'edit' ), |
|
| 223 | + 'context' => array('view', 'edit'), |
|
| 224 | 224 | 'readonly' => true, |
| 225 | 225 | ), |
| 226 | 226 | 'date_registered_gmt' => array( |
| 227 | - 'description' => __( 'Date registered GMT.', 'woocommerce' ), |
|
| 227 | + 'description' => __('Date registered GMT.', 'woocommerce'), |
|
| 228 | 228 | 'type' => 'date-time', |
| 229 | - 'context' => array( 'view', 'edit' ), |
|
| 229 | + 'context' => array('view', 'edit'), |
|
| 230 | 230 | 'readonly' => true, |
| 231 | 231 | ), |
| 232 | 232 | 'date_last_active' => array( |
| 233 | - 'description' => __( 'Date last active.', 'woocommerce' ), |
|
| 233 | + 'description' => __('Date last active.', 'woocommerce'), |
|
| 234 | 234 | 'type' => 'date-time', |
| 235 | - 'context' => array( 'view', 'edit' ), |
|
| 235 | + 'context' => array('view', 'edit'), |
|
| 236 | 236 | 'readonly' => true, |
| 237 | 237 | ), |
| 238 | 238 | 'date_last_active_gmt' => array( |
| 239 | - 'description' => __( 'Date last active GMT.', 'woocommerce' ), |
|
| 239 | + 'description' => __('Date last active GMT.', 'woocommerce'), |
|
| 240 | 240 | 'type' => 'date-time', |
| 241 | - 'context' => array( 'view', 'edit' ), |
|
| 241 | + 'context' => array('view', 'edit'), |
|
| 242 | 242 | 'readonly' => true, |
| 243 | 243 | ), |
| 244 | 244 | 'orders_count' => array( |
| 245 | - 'description' => __( 'Order count.', 'woocommerce' ), |
|
| 245 | + 'description' => __('Order count.', 'woocommerce'), |
|
| 246 | 246 | 'type' => 'integer', |
| 247 | - 'context' => array( 'view', 'edit' ), |
|
| 247 | + 'context' => array('view', 'edit'), |
|
| 248 | 248 | 'readonly' => true, |
| 249 | 249 | ), |
| 250 | 250 | 'total_spend' => array( |
| 251 | - 'description' => __( 'Total spend.', 'woocommerce' ), |
|
| 251 | + 'description' => __('Total spend.', 'woocommerce'), |
|
| 252 | 252 | 'type' => 'number', |
| 253 | - 'context' => array( 'view', 'edit' ), |
|
| 253 | + 'context' => array('view', 'edit'), |
|
| 254 | 254 | 'readonly' => true, |
| 255 | 255 | ), |
| 256 | 256 | 'avg_order_value' => array( |
| 257 | - 'description' => __( 'Avg order value.', 'woocommerce' ), |
|
| 257 | + 'description' => __('Avg order value.', 'woocommerce'), |
|
| 258 | 258 | 'type' => 'number', |
| 259 | - 'context' => array( 'view', 'edit' ), |
|
| 259 | + 'context' => array('view', 'edit'), |
|
| 260 | 260 | 'readonly' => true, |
| 261 | 261 | ), |
| 262 | 262 | ), |
| 263 | 263 | ); |
| 264 | - return $this->add_additional_fields_schema( $schema ); |
|
| 264 | + return $this->add_additional_fields_schema($schema); |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | /** |
@@ -271,41 +271,41 @@ discard block |
||
| 271 | 271 | */ |
| 272 | 272 | public function get_collection_params() { |
| 273 | 273 | $params = array(); |
| 274 | - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); |
|
| 274 | + $params['context'] = $this->get_context_param(array('default' => 'view')); |
|
| 275 | 275 | $params['registered_before'] = array( |
| 276 | - 'description' => __( 'Limit response to objects registered before (or at) a given ISO8601 compliant datetime.', 'woocommerce' ), |
|
| 276 | + 'description' => __('Limit response to objects registered before (or at) a given ISO8601 compliant datetime.', 'woocommerce'), |
|
| 277 | 277 | 'type' => 'string', |
| 278 | 278 | 'format' => 'date-time', |
| 279 | 279 | 'validate_callback' => 'rest_validate_request_arg', |
| 280 | 280 | ); |
| 281 | - $params['registered_after'] = array( |
|
| 282 | - 'description' => __( 'Limit response to objects registered after (or at) a given ISO8601 compliant datetime.', 'woocommerce' ), |
|
| 281 | + $params['registered_after'] = array( |
|
| 282 | + 'description' => __('Limit response to objects registered after (or at) a given ISO8601 compliant datetime.', 'woocommerce'), |
|
| 283 | 283 | 'type' => 'string', |
| 284 | 284 | 'format' => 'date-time', |
| 285 | 285 | 'validate_callback' => 'rest_validate_request_arg', |
| 286 | 286 | ); |
| 287 | - $params['after'] = array( |
|
| 288 | - 'description' => __( 'Limit response to resources with orders published after a given ISO8601 compliant date.', 'woocommerce' ), |
|
| 287 | + $params['after'] = array( |
|
| 288 | + 'description' => __('Limit response to resources with orders published after a given ISO8601 compliant date.', 'woocommerce'), |
|
| 289 | 289 | 'type' => 'string', |
| 290 | 290 | 'format' => 'date-time', |
| 291 | 291 | 'validate_callback' => 'rest_validate_request_arg', |
| 292 | 292 | ); |
| 293 | - $params['before'] = array( |
|
| 294 | - 'description' => __( 'Limit response to resources with orders published before a given ISO8601 compliant date.', 'woocommerce' ), |
|
| 293 | + $params['before'] = array( |
|
| 294 | + 'description' => __('Limit response to resources with orders published before a given ISO8601 compliant date.', 'woocommerce'), |
|
| 295 | 295 | 'type' => 'string', |
| 296 | 296 | 'format' => 'date-time', |
| 297 | 297 | 'validate_callback' => 'rest_validate_request_arg', |
| 298 | 298 | ); |
| 299 | - $params['page'] = array( |
|
| 300 | - 'description' => __( 'Current page of the collection.', 'woocommerce' ), |
|
| 299 | + $params['page'] = array( |
|
| 300 | + 'description' => __('Current page of the collection.', 'woocommerce'), |
|
| 301 | 301 | 'type' => 'integer', |
| 302 | 302 | 'default' => 1, |
| 303 | 303 | 'sanitize_callback' => 'absint', |
| 304 | 304 | 'validate_callback' => 'rest_validate_request_arg', |
| 305 | 305 | 'minimum' => 1, |
| 306 | 306 | ); |
| 307 | - $params['per_page'] = array( |
|
| 308 | - 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ), |
|
| 307 | + $params['per_page'] = array( |
|
| 308 | + 'description' => __('Maximum number of items to be returned in result set.', 'woocommerce'), |
|
| 309 | 309 | 'type' => 'integer', |
| 310 | 310 | 'default' => 10, |
| 311 | 311 | 'minimum' => 1, |
@@ -313,15 +313,15 @@ discard block |
||
| 313 | 313 | 'sanitize_callback' => 'absint', |
| 314 | 314 | 'validate_callback' => 'rest_validate_request_arg', |
| 315 | 315 | ); |
| 316 | - $params['order'] = array( |
|
| 317 | - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), |
|
| 316 | + $params['order'] = array( |
|
| 317 | + 'description' => __('Order sort attribute ascending or descending.', 'woocommerce'), |
|
| 318 | 318 | 'type' => 'string', |
| 319 | 319 | 'default' => 'desc', |
| 320 | - 'enum' => array( 'asc', 'desc' ), |
|
| 320 | + 'enum' => array('asc', 'desc'), |
|
| 321 | 321 | 'validate_callback' => 'rest_validate_request_arg', |
| 322 | 322 | ); |
| 323 | - $params['orderby'] = array( |
|
| 324 | - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), |
|
| 323 | + $params['orderby'] = array( |
|
| 324 | + 'description' => __('Sort collection by object attribute.', 'woocommerce'), |
|
| 325 | 325 | 'type' => 'string', |
| 326 | 326 | 'default' => 'date_registered', |
| 327 | 327 | 'enum' => array( |
@@ -338,8 +338,8 @@ discard block |
||
| 338 | 338 | ), |
| 339 | 339 | 'validate_callback' => 'rest_validate_request_arg', |
| 340 | 340 | ); |
| 341 | - $params['match'] = array( |
|
| 342 | - 'description' => __( 'Indicates whether all the conditions should be true for the resulting set, or if any one of them is sufficient. Match affects the following parameters: status_is, status_is_not, product_includes, product_excludes, coupon_includes, coupon_excludes, customer, categories', 'woocommerce' ), |
|
| 341 | + $params['match'] = array( |
|
| 342 | + 'description' => __('Indicates whether all the conditions should be true for the resulting set, or if any one of them is sufficient. Match affects the following parameters: status_is, status_is_not, product_includes, product_excludes, coupon_includes, coupon_excludes, customer, categories', 'woocommerce'), |
|
| 343 | 343 | 'type' => 'string', |
| 344 | 344 | 'default' => 'all', |
| 345 | 345 | 'enum' => array( |
@@ -348,12 +348,12 @@ discard block |
||
| 348 | 348 | ), |
| 349 | 349 | 'validate_callback' => 'rest_validate_request_arg', |
| 350 | 350 | ); |
| 351 | - $params['search'] = array( |
|
| 352 | - 'description' => __( 'Limit response to objects with a customer field containing the search term. Searches the field provided by `searchby`.', 'woocommerce' ), |
|
| 351 | + $params['search'] = array( |
|
| 352 | + 'description' => __('Limit response to objects with a customer field containing the search term. Searches the field provided by `searchby`.', 'woocommerce'), |
|
| 353 | 353 | 'type' => 'string', |
| 354 | 354 | 'validate_callback' => 'rest_validate_request_arg', |
| 355 | 355 | ); |
| 356 | - $params['searchby'] = array( |
|
| 356 | + $params['searchby'] = array( |
|
| 357 | 357 | 'description' => 'Limit results with `search` and `searchby` to specific fields containing the search term.', |
| 358 | 358 | 'type' => 'string', |
| 359 | 359 | 'default' => 'name', |
@@ -363,141 +363,141 @@ discard block |
||
| 363 | 363 | 'email', |
| 364 | 364 | ), |
| 365 | 365 | ); |
| 366 | - $params['name_includes'] = array( |
|
| 367 | - 'description' => __( 'Limit response to objects with specfic names.', 'woocommerce' ), |
|
| 366 | + $params['name_includes'] = array( |
|
| 367 | + 'description' => __('Limit response to objects with specfic names.', 'woocommerce'), |
|
| 368 | 368 | 'type' => 'string', |
| 369 | 369 | 'validate_callback' => 'rest_validate_request_arg', |
| 370 | 370 | ); |
| 371 | - $params['name_excludes'] = array( |
|
| 372 | - 'description' => __( 'Limit response to objects excluding specfic names.', 'woocommerce' ), |
|
| 371 | + $params['name_excludes'] = array( |
|
| 372 | + 'description' => __('Limit response to objects excluding specfic names.', 'woocommerce'), |
|
| 373 | 373 | 'type' => 'string', |
| 374 | 374 | 'validate_callback' => 'rest_validate_request_arg', |
| 375 | 375 | ); |
| 376 | - $params['username_includes'] = array( |
|
| 377 | - 'description' => __( 'Limit response to objects with specfic usernames.', 'woocommerce' ), |
|
| 376 | + $params['username_includes'] = array( |
|
| 377 | + 'description' => __('Limit response to objects with specfic usernames.', 'woocommerce'), |
|
| 378 | 378 | 'type' => 'string', |
| 379 | 379 | 'validate_callback' => 'rest_validate_request_arg', |
| 380 | 380 | ); |
| 381 | - $params['username_excludes'] = array( |
|
| 382 | - 'description' => __( 'Limit response to objects excluding specfic usernames.', 'woocommerce' ), |
|
| 381 | + $params['username_excludes'] = array( |
|
| 382 | + 'description' => __('Limit response to objects excluding specfic usernames.', 'woocommerce'), |
|
| 383 | 383 | 'type' => 'string', |
| 384 | 384 | 'validate_callback' => 'rest_validate_request_arg', |
| 385 | 385 | ); |
| 386 | - $params['email_includes'] = array( |
|
| 387 | - 'description' => __( 'Limit response to objects including emails.', 'woocommerce' ), |
|
| 386 | + $params['email_includes'] = array( |
|
| 387 | + 'description' => __('Limit response to objects including emails.', 'woocommerce'), |
|
| 388 | 388 | 'type' => 'string', |
| 389 | 389 | 'validate_callback' => 'rest_validate_request_arg', |
| 390 | 390 | ); |
| 391 | - $params['email_excludes'] = array( |
|
| 392 | - 'description' => __( 'Limit response to objects excluding emails.', 'woocommerce' ), |
|
| 391 | + $params['email_excludes'] = array( |
|
| 392 | + 'description' => __('Limit response to objects excluding emails.', 'woocommerce'), |
|
| 393 | 393 | 'type' => 'string', |
| 394 | 394 | 'validate_callback' => 'rest_validate_request_arg', |
| 395 | 395 | ); |
| 396 | - $params['country_includes'] = array( |
|
| 397 | - 'description' => __( 'Limit response to objects with specfic countries.', 'woocommerce' ), |
|
| 396 | + $params['country_includes'] = array( |
|
| 397 | + 'description' => __('Limit response to objects with specfic countries.', 'woocommerce'), |
|
| 398 | 398 | 'type' => 'string', |
| 399 | 399 | 'validate_callback' => 'rest_validate_request_arg', |
| 400 | 400 | ); |
| 401 | - $params['country_excludes'] = array( |
|
| 402 | - 'description' => __( 'Limit response to objects excluding specfic countries.', 'woocommerce' ), |
|
| 401 | + $params['country_excludes'] = array( |
|
| 402 | + 'description' => __('Limit response to objects excluding specfic countries.', 'woocommerce'), |
|
| 403 | 403 | 'type' => 'string', |
| 404 | 404 | 'validate_callback' => 'rest_validate_request_arg', |
| 405 | 405 | ); |
| 406 | - $params['last_active_before'] = array( |
|
| 407 | - 'description' => __( 'Limit response to objects last active before (or at) a given ISO8601 compliant datetime.', 'woocommerce' ), |
|
| 406 | + $params['last_active_before'] = array( |
|
| 407 | + 'description' => __('Limit response to objects last active before (or at) a given ISO8601 compliant datetime.', 'woocommerce'), |
|
| 408 | 408 | 'type' => 'string', |
| 409 | 409 | 'format' => 'date-time', |
| 410 | 410 | 'validate_callback' => 'rest_validate_request_arg', |
| 411 | 411 | ); |
| 412 | - $params['last_active_after'] = array( |
|
| 413 | - 'description' => __( 'Limit response to objects last active after (or at) a given ISO8601 compliant datetime.', 'woocommerce' ), |
|
| 412 | + $params['last_active_after'] = array( |
|
| 413 | + 'description' => __('Limit response to objects last active after (or at) a given ISO8601 compliant datetime.', 'woocommerce'), |
|
| 414 | 414 | 'type' => 'string', |
| 415 | 415 | 'format' => 'date-time', |
| 416 | 416 | 'validate_callback' => 'rest_validate_request_arg', |
| 417 | 417 | ); |
| 418 | - $params['last_active_between'] = array( |
|
| 419 | - 'description' => __( 'Limit response to objects last active between two given ISO8601 compliant datetime.', 'woocommerce' ), |
|
| 418 | + $params['last_active_between'] = array( |
|
| 419 | + 'description' => __('Limit response to objects last active between two given ISO8601 compliant datetime.', 'woocommerce'), |
|
| 420 | 420 | 'type' => 'array', |
| 421 | - 'validate_callback' => array( 'WC_Admin_Reports_Interval', 'rest_validate_between_date_arg' ), |
|
| 421 | + 'validate_callback' => array('WC_Admin_Reports_Interval', 'rest_validate_between_date_arg'), |
|
| 422 | 422 | ); |
| 423 | - $params['registered_before'] = array( |
|
| 424 | - 'description' => __( 'Limit response to objects registered before (or at) a given ISO8601 compliant datetime.', 'woocommerce' ), |
|
| 423 | + $params['registered_before'] = array( |
|
| 424 | + 'description' => __('Limit response to objects registered before (or at) a given ISO8601 compliant datetime.', 'woocommerce'), |
|
| 425 | 425 | 'type' => 'string', |
| 426 | 426 | 'format' => 'date-time', |
| 427 | 427 | 'validate_callback' => 'rest_validate_request_arg', |
| 428 | 428 | ); |
| 429 | - $params['registered_after'] = array( |
|
| 430 | - 'description' => __( 'Limit response to objects registered after (or at) a given ISO8601 compliant datetime.', 'woocommerce' ), |
|
| 429 | + $params['registered_after'] = array( |
|
| 430 | + 'description' => __('Limit response to objects registered after (or at) a given ISO8601 compliant datetime.', 'woocommerce'), |
|
| 431 | 431 | 'type' => 'string', |
| 432 | 432 | 'format' => 'date-time', |
| 433 | 433 | 'validate_callback' => 'rest_validate_request_arg', |
| 434 | 434 | ); |
| 435 | - $params['registered_between'] = array( |
|
| 436 | - 'description' => __( 'Limit response to objects last active between two given ISO8601 compliant datetime.', 'woocommerce' ), |
|
| 435 | + $params['registered_between'] = array( |
|
| 436 | + 'description' => __('Limit response to objects last active between two given ISO8601 compliant datetime.', 'woocommerce'), |
|
| 437 | 437 | 'type' => 'array', |
| 438 | - 'validate_callback' => array( 'WC_Admin_Reports_Interval', 'rest_validate_between_date_arg' ), |
|
| 438 | + 'validate_callback' => array('WC_Admin_Reports_Interval', 'rest_validate_between_date_arg'), |
|
| 439 | 439 | ); |
| 440 | - $params['orders_count_min'] = array( |
|
| 441 | - 'description' => __( 'Limit response to objects with an order count greater than or equal to given integer.', 'woocommerce' ), |
|
| 440 | + $params['orders_count_min'] = array( |
|
| 441 | + 'description' => __('Limit response to objects with an order count greater than or equal to given integer.', 'woocommerce'), |
|
| 442 | 442 | 'type' => 'integer', |
| 443 | 443 | 'sanitize_callback' => 'absint', |
| 444 | 444 | 'validate_callback' => 'rest_validate_request_arg', |
| 445 | 445 | ); |
| 446 | - $params['orders_count_max'] = array( |
|
| 447 | - 'description' => __( 'Limit response to objects with an order count less than or equal to given integer.', 'woocommerce' ), |
|
| 446 | + $params['orders_count_max'] = array( |
|
| 447 | + 'description' => __('Limit response to objects with an order count less than or equal to given integer.', 'woocommerce'), |
|
| 448 | 448 | 'type' => 'integer', |
| 449 | 449 | 'sanitize_callback' => 'absint', |
| 450 | 450 | 'validate_callback' => 'rest_validate_request_arg', |
| 451 | 451 | ); |
| 452 | - $params['orders_count_between'] = array( |
|
| 453 | - 'description' => __( 'Limit response to objects with an order count between two given integers.', 'woocommerce' ), |
|
| 452 | + $params['orders_count_between'] = array( |
|
| 453 | + 'description' => __('Limit response to objects with an order count between two given integers.', 'woocommerce'), |
|
| 454 | 454 | 'type' => 'array', |
| 455 | - 'validate_callback' => array( 'WC_Admin_Reports_Interval', 'rest_validate_between_numeric_arg' ), |
|
| 455 | + 'validate_callback' => array('WC_Admin_Reports_Interval', 'rest_validate_between_numeric_arg'), |
|
| 456 | 456 | ); |
| 457 | - $params['total_spend_min'] = array( |
|
| 458 | - 'description' => __( 'Limit response to objects with a total order spend greater than or equal to given number.', 'woocommerce' ), |
|
| 457 | + $params['total_spend_min'] = array( |
|
| 458 | + 'description' => __('Limit response to objects with a total order spend greater than or equal to given number.', 'woocommerce'), |
|
| 459 | 459 | 'type' => 'number', |
| 460 | 460 | 'validate_callback' => 'rest_validate_request_arg', |
| 461 | 461 | ); |
| 462 | - $params['total_spend_max'] = array( |
|
| 463 | - 'description' => __( 'Limit response to objects with a total order spend less than or equal to given number.', 'woocommerce' ), |
|
| 462 | + $params['total_spend_max'] = array( |
|
| 463 | + 'description' => __('Limit response to objects with a total order spend less than or equal to given number.', 'woocommerce'), |
|
| 464 | 464 | 'type' => 'number', |
| 465 | 465 | 'validate_callback' => 'rest_validate_request_arg', |
| 466 | 466 | ); |
| 467 | - $params['total_spend_between'] = array( |
|
| 468 | - 'description' => __( 'Limit response to objects with a total order spend between two given numbers.', 'woocommerce' ), |
|
| 467 | + $params['total_spend_between'] = array( |
|
| 468 | + 'description' => __('Limit response to objects with a total order spend between two given numbers.', 'woocommerce'), |
|
| 469 | 469 | 'type' => 'array', |
| 470 | - 'validate_callback' => array( 'WC_Admin_Reports_Interval', 'rest_validate_between_numeric_arg' ), |
|
| 470 | + 'validate_callback' => array('WC_Admin_Reports_Interval', 'rest_validate_between_numeric_arg'), |
|
| 471 | 471 | ); |
| 472 | - $params['avg_order_value_min'] = array( |
|
| 473 | - 'description' => __( 'Limit response to objects with an average order spend greater than or equal to given number.', 'woocommerce' ), |
|
| 472 | + $params['avg_order_value_min'] = array( |
|
| 473 | + 'description' => __('Limit response to objects with an average order spend greater than or equal to given number.', 'woocommerce'), |
|
| 474 | 474 | 'type' => 'number', |
| 475 | 475 | 'validate_callback' => 'rest_validate_request_arg', |
| 476 | 476 | ); |
| 477 | - $params['avg_order_value_max'] = array( |
|
| 478 | - 'description' => __( 'Limit response to objects with an average order spend less than or equal to given number.', 'woocommerce' ), |
|
| 477 | + $params['avg_order_value_max'] = array( |
|
| 478 | + 'description' => __('Limit response to objects with an average order spend less than or equal to given number.', 'woocommerce'), |
|
| 479 | 479 | 'type' => 'number', |
| 480 | 480 | 'validate_callback' => 'rest_validate_request_arg', |
| 481 | 481 | ); |
| 482 | 482 | $params['avg_order_value_between'] = array( |
| 483 | - 'description' => __( 'Limit response to objects with an average order spend between two given numbers.', 'woocommerce' ), |
|
| 483 | + 'description' => __('Limit response to objects with an average order spend between two given numbers.', 'woocommerce'), |
|
| 484 | 484 | 'type' => 'array', |
| 485 | - 'validate_callback' => array( 'WC_Admin_Reports_Interval', 'rest_validate_between_numeric_arg' ), |
|
| 485 | + 'validate_callback' => array('WC_Admin_Reports_Interval', 'rest_validate_between_numeric_arg'), |
|
| 486 | 486 | ); |
| 487 | - $params['last_order_before'] = array( |
|
| 488 | - 'description' => __( 'Limit response to objects with last order before (or at) a given ISO8601 compliant datetime.', 'woocommerce' ), |
|
| 487 | + $params['last_order_before'] = array( |
|
| 488 | + 'description' => __('Limit response to objects with last order before (or at) a given ISO8601 compliant datetime.', 'woocommerce'), |
|
| 489 | 489 | 'type' => 'string', |
| 490 | 490 | 'format' => 'date-time', |
| 491 | 491 | 'validate_callback' => 'rest_validate_request_arg', |
| 492 | 492 | ); |
| 493 | - $params['last_order_after'] = array( |
|
| 494 | - 'description' => __( 'Limit response to objects with last order after (or at) a given ISO8601 compliant datetime.', 'woocommerce' ), |
|
| 493 | + $params['last_order_after'] = array( |
|
| 494 | + 'description' => __('Limit response to objects with last order after (or at) a given ISO8601 compliant datetime.', 'woocommerce'), |
|
| 495 | 495 | 'type' => 'string', |
| 496 | 496 | 'format' => 'date-time', |
| 497 | 497 | 'validate_callback' => 'rest_validate_request_arg', |
| 498 | 498 | ); |
| 499 | - $params['customers'] = array( |
|
| 500 | - 'description' => __( 'Limit result to items with specified customer ids.', 'woocommerce' ), |
|
| 499 | + $params['customers'] = array( |
|
| 500 | + 'description' => __('Limit result to items with specified customer ids.', 'woocommerce'), |
|
| 501 | 501 | 'type' => 'array', |
| 502 | 502 | 'sanitize_callback' => 'wp_parse_id_list', |
| 503 | 503 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | namespace WooCommerce\RestApi\Version4\Controllers\Reports; |
| 11 | 11 | |
| 12 | -defined( 'ABSPATH' ) || exit; |
|
| 12 | +defined('ABSPATH') || exit; |
|
| 13 | 13 | |
| 14 | 14 | use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports; |
| 15 | 15 | |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * Constructor. |
| 30 | 30 | */ |
| 31 | 31 | public function __construct() { |
| 32 | - add_filter( 'woocommerce_reports_taxes_stats_select_query', array( $this, 'set_default_report_data' ) ); |
|
| 32 | + add_filter('woocommerce_reports_taxes_stats_select_query', array($this, 'set_default_report_data')); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -38,8 +38,8 @@ discard block |
||
| 38 | 38 | * @param Mixed $results Report data. |
| 39 | 39 | * @return object |
| 40 | 40 | */ |
| 41 | - public function set_default_report_data( $results ) { |
|
| 42 | - if ( empty( $results ) ) { |
|
| 41 | + public function set_default_report_data($results) { |
|
| 42 | + if (empty($results)) { |
|
| 43 | 43 | $results = new \stdClass(); |
| 44 | 44 | $results->total = 0; |
| 45 | 45 | $results->totals = new \stdClass(); |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * @param array $request Request array. |
| 62 | 62 | * @return array |
| 63 | 63 | */ |
| 64 | - protected function prepare_reports_query( $request ) { |
|
| 64 | + protected function prepare_reports_query($request) { |
|
| 65 | 65 | $args = array(); |
| 66 | 66 | $args['before'] = $request['before']; |
| 67 | 67 | $args['after'] = $request['after']; |
@@ -82,40 +82,40 @@ discard block |
||
| 82 | 82 | * @param \WP_REST_Request $request Request data. |
| 83 | 83 | * @return array|\WP_Error |
| 84 | 84 | */ |
| 85 | - public function get_items( $request ) { |
|
| 86 | - $query_args = $this->prepare_reports_query( $request ); |
|
| 87 | - $taxes_query = new \WC_Admin_Reports_Taxes_Stats_Query( $query_args ); |
|
| 85 | + public function get_items($request) { |
|
| 86 | + $query_args = $this->prepare_reports_query($request); |
|
| 87 | + $taxes_query = new \WC_Admin_Reports_Taxes_Stats_Query($query_args); |
|
| 88 | 88 | $report_data = $taxes_query->get_data(); |
| 89 | 89 | |
| 90 | 90 | $out_data = array( |
| 91 | - 'totals' => get_object_vars( $report_data->totals ), |
|
| 91 | + 'totals' => get_object_vars($report_data->totals), |
|
| 92 | 92 | 'intervals' => array(), |
| 93 | 93 | ); |
| 94 | 94 | |
| 95 | - foreach ( $report_data->intervals as $interval_data ) { |
|
| 96 | - $item = $this->prepare_item_for_response( (object) $interval_data, $request ); |
|
| 97 | - $out_data['intervals'][] = $this->prepare_response_for_collection( $item ); |
|
| 95 | + foreach ($report_data->intervals as $interval_data) { |
|
| 96 | + $item = $this->prepare_item_for_response((object) $interval_data, $request); |
|
| 97 | + $out_data['intervals'][] = $this->prepare_response_for_collection($item); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - $response = rest_ensure_response( $out_data ); |
|
| 101 | - $response->header( 'X-WP-Total', (int) $report_data->total ); |
|
| 102 | - $response->header( 'X-WP-TotalPages', (int) $report_data->pages ); |
|
| 100 | + $response = rest_ensure_response($out_data); |
|
| 101 | + $response->header('X-WP-Total', (int) $report_data->total); |
|
| 102 | + $response->header('X-WP-TotalPages', (int) $report_data->pages); |
|
| 103 | 103 | |
| 104 | 104 | $page = $report_data->page_no; |
| 105 | 105 | $max_pages = $report_data->pages; |
| 106 | - $base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) ); |
|
| 107 | - if ( $page > 1 ) { |
|
| 106 | + $base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base))); |
|
| 107 | + if ($page > 1) { |
|
| 108 | 108 | $prev_page = $page - 1; |
| 109 | - if ( $prev_page > $max_pages ) { |
|
| 109 | + if ($prev_page > $max_pages) { |
|
| 110 | 110 | $prev_page = $max_pages; |
| 111 | 111 | } |
| 112 | - $prev_link = add_query_arg( 'page', $prev_page, $base ); |
|
| 113 | - $response->link_header( 'prev', $prev_link ); |
|
| 112 | + $prev_link = add_query_arg('page', $prev_page, $base); |
|
| 113 | + $response->link_header('prev', $prev_link); |
|
| 114 | 114 | } |
| 115 | - if ( $max_pages > $page ) { |
|
| 115 | + if ($max_pages > $page) { |
|
| 116 | 116 | $next_page = $page + 1; |
| 117 | - $next_link = add_query_arg( 'page', $next_page, $base ); |
|
| 118 | - $response->link_header( 'next', $next_link ); |
|
| 117 | + $next_link = add_query_arg('page', $next_page, $base); |
|
| 118 | + $response->link_header('next', $next_link); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | return $response; |
@@ -128,15 +128,15 @@ discard block |
||
| 128 | 128 | * @param \WP_REST_Request $request Request object. |
| 129 | 129 | * @return \WP_REST_Response |
| 130 | 130 | */ |
| 131 | - public function prepare_item_for_response( $report, $request ) { |
|
| 132 | - $data = get_object_vars( $report ); |
|
| 131 | + public function prepare_item_for_response($report, $request) { |
|
| 132 | + $data = get_object_vars($report); |
|
| 133 | 133 | |
| 134 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 135 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
| 136 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 134 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
| 135 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
| 136 | + $data = $this->filter_response_by_context($data, $context); |
|
| 137 | 137 | |
| 138 | 138 | // Wrap the data in a response object. |
| 139 | - $response = rest_ensure_response( $data ); |
|
| 139 | + $response = rest_ensure_response($data); |
|
| 140 | 140 | |
| 141 | 141 | /** |
| 142 | 142 | * Filter a report returned from the API. |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | * @param object $report The original report object. |
| 148 | 148 | * @param \WP_REST_Request $request Request used to generate the response. |
| 149 | 149 | */ |
| 150 | - return apply_filters( 'woocommerce_rest_prepare_report_taxes_stats', $response, $report, $request ); |
|
| 150 | + return apply_filters('woocommerce_rest_prepare_report_taxes_stats', $response, $report, $request); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | /** |
@@ -158,62 +158,62 @@ discard block |
||
| 158 | 158 | public function get_item_schema() { |
| 159 | 159 | $data_values = array( |
| 160 | 160 | 'total_tax' => array( |
| 161 | - 'description' => __( 'Total tax.', 'woocommerce' ), |
|
| 161 | + 'description' => __('Total tax.', 'woocommerce'), |
|
| 162 | 162 | 'type' => 'number', |
| 163 | - 'context' => array( 'view', 'edit' ), |
|
| 163 | + 'context' => array('view', 'edit'), |
|
| 164 | 164 | 'readonly' => true, |
| 165 | 165 | 'indicator' => true, |
| 166 | 166 | 'format' => 'currency', |
| 167 | 167 | ), |
| 168 | 168 | 'order_tax' => array( |
| 169 | - 'description' => __( 'Order tax.', 'woocommerce' ), |
|
| 169 | + 'description' => __('Order tax.', 'woocommerce'), |
|
| 170 | 170 | 'type' => 'number', |
| 171 | - 'context' => array( 'view', 'edit' ), |
|
| 171 | + 'context' => array('view', 'edit'), |
|
| 172 | 172 | 'readonly' => true, |
| 173 | 173 | 'indicator' => true, |
| 174 | 174 | 'format' => 'currency', |
| 175 | 175 | ), |
| 176 | 176 | 'shipping_tax' => array( |
| 177 | - 'description' => __( 'Shipping tax.', 'woocommerce' ), |
|
| 177 | + 'description' => __('Shipping tax.', 'woocommerce'), |
|
| 178 | 178 | 'type' => 'number', |
| 179 | - 'context' => array( 'view', 'edit' ), |
|
| 179 | + 'context' => array('view', 'edit'), |
|
| 180 | 180 | 'readonly' => true, |
| 181 | 181 | 'indicator' => true, |
| 182 | 182 | 'format' => 'currency', |
| 183 | 183 | ), |
| 184 | 184 | 'orders_count' => array( |
| 185 | - 'description' => __( 'Amount of orders.', 'woocommerce' ), |
|
| 185 | + 'description' => __('Amount of orders.', 'woocommerce'), |
|
| 186 | 186 | 'type' => 'integer', |
| 187 | - 'context' => array( 'view', 'edit' ), |
|
| 187 | + 'context' => array('view', 'edit'), |
|
| 188 | 188 | 'readonly' => true, |
| 189 | 189 | ), |
| 190 | 190 | 'tax_codes' => array( |
| 191 | - 'description' => __( 'Amount of tax codes.', 'woocommerce' ), |
|
| 191 | + 'description' => __('Amount of tax codes.', 'woocommerce'), |
|
| 192 | 192 | 'type' => 'integer', |
| 193 | - 'context' => array( 'view', 'edit' ), |
|
| 193 | + 'context' => array('view', 'edit'), |
|
| 194 | 194 | 'readonly' => true, |
| 195 | 195 | ), |
| 196 | 196 | ); |
| 197 | 197 | |
| 198 | 198 | $segments = array( |
| 199 | 199 | 'segments' => array( |
| 200 | - 'description' => __( 'Reports data grouped by segment condition.', 'woocommerce' ), |
|
| 200 | + 'description' => __('Reports data grouped by segment condition.', 'woocommerce'), |
|
| 201 | 201 | 'type' => 'array', |
| 202 | - 'context' => array( 'view', 'edit' ), |
|
| 202 | + 'context' => array('view', 'edit'), |
|
| 203 | 203 | 'readonly' => true, |
| 204 | 204 | 'items' => array( |
| 205 | 205 | 'type' => 'object', |
| 206 | 206 | 'properties' => array( |
| 207 | 207 | 'segment_id' => array( |
| 208 | - 'description' => __( 'Segment identificator.', 'woocommerce' ), |
|
| 208 | + 'description' => __('Segment identificator.', 'woocommerce'), |
|
| 209 | 209 | 'type' => 'integer', |
| 210 | - 'context' => array( 'view', 'edit' ), |
|
| 210 | + 'context' => array('view', 'edit'), |
|
| 211 | 211 | 'readonly' => true, |
| 212 | 212 | ), |
| 213 | 213 | 'subtotals' => array( |
| 214 | - 'description' => __( 'Interval subtotals.', 'woocommerce' ), |
|
| 214 | + 'description' => __('Interval subtotals.', 'woocommerce'), |
|
| 215 | 215 | 'type' => 'object', |
| 216 | - 'context' => array( 'view', 'edit' ), |
|
| 216 | + 'context' => array('view', 'edit'), |
|
| 217 | 217 | 'readonly' => true, |
| 218 | 218 | 'properties' => $data_values, |
| 219 | 219 | ), |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | ), |
| 223 | 223 | ); |
| 224 | 224 | |
| 225 | - $totals = array_merge( $data_values, $segments ); |
|
| 225 | + $totals = array_merge($data_values, $segments); |
|
| 226 | 226 | |
| 227 | 227 | $schema = array( |
| 228 | 228 | '$schema' => 'http://json-schema.org/draft-04/schema#', |
@@ -230,55 +230,55 @@ discard block |
||
| 230 | 230 | 'type' => 'object', |
| 231 | 231 | 'properties' => array( |
| 232 | 232 | 'totals' => array( |
| 233 | - 'description' => __( 'Totals data.', 'woocommerce' ), |
|
| 233 | + 'description' => __('Totals data.', 'woocommerce'), |
|
| 234 | 234 | 'type' => 'object', |
| 235 | - 'context' => array( 'view', 'edit' ), |
|
| 235 | + 'context' => array('view', 'edit'), |
|
| 236 | 236 | 'readonly' => true, |
| 237 | 237 | 'properties' => $totals, |
| 238 | 238 | ), |
| 239 | 239 | 'intervals' => array( |
| 240 | - 'description' => __( 'Reports data grouped by intervals.', 'woocommerce' ), |
|
| 240 | + 'description' => __('Reports data grouped by intervals.', 'woocommerce'), |
|
| 241 | 241 | 'type' => 'array', |
| 242 | - 'context' => array( 'view', 'edit' ), |
|
| 242 | + 'context' => array('view', 'edit'), |
|
| 243 | 243 | 'readonly' => true, |
| 244 | 244 | 'items' => array( |
| 245 | 245 | 'type' => 'object', |
| 246 | 246 | 'properties' => array( |
| 247 | 247 | 'interval' => array( |
| 248 | - 'description' => __( 'Type of interval.', 'woocommerce' ), |
|
| 248 | + 'description' => __('Type of interval.', 'woocommerce'), |
|
| 249 | 249 | 'type' => 'string', |
| 250 | - 'context' => array( 'view', 'edit' ), |
|
| 250 | + 'context' => array('view', 'edit'), |
|
| 251 | 251 | 'readonly' => true, |
| 252 | - 'enum' => array( 'day', 'week', 'month', 'year' ), |
|
| 252 | + 'enum' => array('day', 'week', 'month', 'year'), |
|
| 253 | 253 | ), |
| 254 | 254 | 'date_start' => array( |
| 255 | - 'description' => __( "The date the report start, in the site's timezone.", 'woocommerce' ), |
|
| 255 | + 'description' => __("The date the report start, in the site's timezone.", 'woocommerce'), |
|
| 256 | 256 | 'type' => 'date-time', |
| 257 | - 'context' => array( 'view', 'edit' ), |
|
| 257 | + 'context' => array('view', 'edit'), |
|
| 258 | 258 | 'readonly' => true, |
| 259 | 259 | ), |
| 260 | 260 | 'date_start_gmt' => array( |
| 261 | - 'description' => __( 'The date the report start, as GMT.', 'woocommerce' ), |
|
| 261 | + 'description' => __('The date the report start, as GMT.', 'woocommerce'), |
|
| 262 | 262 | 'type' => 'date-time', |
| 263 | - 'context' => array( 'view', 'edit' ), |
|
| 263 | + 'context' => array('view', 'edit'), |
|
| 264 | 264 | 'readonly' => true, |
| 265 | 265 | ), |
| 266 | 266 | 'date_end' => array( |
| 267 | - 'description' => __( "The date the report end, in the site's timezone.", 'woocommerce' ), |
|
| 267 | + 'description' => __("The date the report end, in the site's timezone.", 'woocommerce'), |
|
| 268 | 268 | 'type' => 'date-time', |
| 269 | - 'context' => array( 'view', 'edit' ), |
|
| 269 | + 'context' => array('view', 'edit'), |
|
| 270 | 270 | 'readonly' => true, |
| 271 | 271 | ), |
| 272 | 272 | 'date_end_gmt' => array( |
| 273 | - 'description' => __( 'The date the report end, as GMT.', 'woocommerce' ), |
|
| 273 | + 'description' => __('The date the report end, as GMT.', 'woocommerce'), |
|
| 274 | 274 | 'type' => 'date-time', |
| 275 | - 'context' => array( 'view', 'edit' ), |
|
| 275 | + 'context' => array('view', 'edit'), |
|
| 276 | 276 | 'readonly' => true, |
| 277 | 277 | ), |
| 278 | 278 | 'subtotals' => array( |
| 279 | - 'description' => __( 'Interval subtotals.', 'woocommerce' ), |
|
| 279 | + 'description' => __('Interval subtotals.', 'woocommerce'), |
|
| 280 | 280 | 'type' => 'object', |
| 281 | - 'context' => array( 'view', 'edit' ), |
|
| 281 | + 'context' => array('view', 'edit'), |
|
| 282 | 282 | 'readonly' => true, |
| 283 | 283 | 'properties' => $totals, |
| 284 | 284 | ), |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | ), |
| 289 | 289 | ); |
| 290 | 290 | |
| 291 | - return $this->add_additional_fields_schema( $schema ); |
|
| 291 | + return $this->add_additional_fields_schema($schema); |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | /** |
@@ -298,17 +298,17 @@ discard block |
||
| 298 | 298 | */ |
| 299 | 299 | public function get_collection_params() { |
| 300 | 300 | $params = array(); |
| 301 | - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); |
|
| 301 | + $params['context'] = $this->get_context_param(array('default' => 'view')); |
|
| 302 | 302 | $params['page'] = array( |
| 303 | - 'description' => __( 'Current page of the collection.', 'woocommerce' ), |
|
| 303 | + 'description' => __('Current page of the collection.', 'woocommerce'), |
|
| 304 | 304 | 'type' => 'integer', |
| 305 | 305 | 'default' => 1, |
| 306 | 306 | 'sanitize_callback' => 'absint', |
| 307 | 307 | 'validate_callback' => 'rest_validate_request_arg', |
| 308 | 308 | 'minimum' => 1, |
| 309 | 309 | ); |
| 310 | - $params['per_page'] = array( |
|
| 311 | - 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ), |
|
| 310 | + $params['per_page'] = array( |
|
| 311 | + 'description' => __('Maximum number of items to be returned in result set.', 'woocommerce'), |
|
| 312 | 312 | 'type' => 'integer', |
| 313 | 313 | 'default' => 10, |
| 314 | 314 | 'minimum' => 1, |
@@ -316,27 +316,27 @@ discard block |
||
| 316 | 316 | 'sanitize_callback' => 'absint', |
| 317 | 317 | 'validate_callback' => 'rest_validate_request_arg', |
| 318 | 318 | ); |
| 319 | - $params['after'] = array( |
|
| 320 | - 'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ), |
|
| 319 | + $params['after'] = array( |
|
| 320 | + 'description' => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'), |
|
| 321 | 321 | 'type' => 'string', |
| 322 | 322 | 'format' => 'date-time', |
| 323 | 323 | 'validate_callback' => 'rest_validate_request_arg', |
| 324 | 324 | ); |
| 325 | - $params['before'] = array( |
|
| 326 | - 'description' => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ), |
|
| 325 | + $params['before'] = array( |
|
| 326 | + 'description' => __('Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce'), |
|
| 327 | 327 | 'type' => 'string', |
| 328 | 328 | 'format' => 'date-time', |
| 329 | 329 | 'validate_callback' => 'rest_validate_request_arg', |
| 330 | 330 | ); |
| 331 | - $params['order'] = array( |
|
| 332 | - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), |
|
| 331 | + $params['order'] = array( |
|
| 332 | + 'description' => __('Order sort attribute ascending or descending.', 'woocommerce'), |
|
| 333 | 333 | 'type' => 'string', |
| 334 | 334 | 'default' => 'desc', |
| 335 | - 'enum' => array( 'asc', 'desc' ), |
|
| 335 | + 'enum' => array('asc', 'desc'), |
|
| 336 | 336 | 'validate_callback' => 'rest_validate_request_arg', |
| 337 | 337 | ); |
| 338 | - $params['orderby'] = array( |
|
| 339 | - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), |
|
| 338 | + $params['orderby'] = array( |
|
| 339 | + 'description' => __('Sort collection by object attribute.', 'woocommerce'), |
|
| 340 | 340 | 'type' => 'string', |
| 341 | 341 | 'default' => 'date', |
| 342 | 342 | 'enum' => array( |
@@ -348,8 +348,8 @@ discard block |
||
| 348 | 348 | ), |
| 349 | 349 | 'validate_callback' => 'rest_validate_request_arg', |
| 350 | 350 | ); |
| 351 | - $params['interval'] = array( |
|
| 352 | - 'description' => __( 'Time interval to use for buckets in the returned data.', 'woocommerce' ), |
|
| 351 | + $params['interval'] = array( |
|
| 352 | + 'description' => __('Time interval to use for buckets in the returned data.', 'woocommerce'), |
|
| 353 | 353 | 'type' => 'string', |
| 354 | 354 | 'default' => 'week', |
| 355 | 355 | 'enum' => array( |
@@ -362,8 +362,8 @@ discard block |
||
| 362 | 362 | ), |
| 363 | 363 | 'validate_callback' => 'rest_validate_request_arg', |
| 364 | 364 | ); |
| 365 | - $params['taxes'] = array( |
|
| 366 | - 'description' => __( 'Limit result set to all items that have the specified term assigned in the taxes taxonomy.', 'woocommerce' ), |
|
| 365 | + $params['taxes'] = array( |
|
| 366 | + 'description' => __('Limit result set to all items that have the specified term assigned in the taxes taxonomy.', 'woocommerce'), |
|
| 367 | 367 | 'type' => 'array', |
| 368 | 368 | 'sanitize_callback' => 'wp_parse_id_list', |
| 369 | 369 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -372,7 +372,7 @@ discard block |
||
| 372 | 372 | ), |
| 373 | 373 | ); |
| 374 | 374 | $params['segmentby'] = array( |
| 375 | - 'description' => __( 'Segment the response by additional constraint.', 'woocommerce' ), |
|
| 375 | + 'description' => __('Segment the response by additional constraint.', 'woocommerce'), |
|
| 376 | 376 | 'type' => 'string', |
| 377 | 377 | 'enum' => array( |
| 378 | 378 | 'tax_rate_id', |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | namespace WooCommerce\RestApi\Version4\Controllers\Reports; |
| 11 | 11 | |
| 12 | -defined( 'ABSPATH' ) || exit; |
|
| 12 | +defined('ABSPATH') || exit; |
|
| 13 | 13 | |
| 14 | 14 | use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports; |
| 15 | 15 | |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * @param \WP_REST_Request $request Request array. |
| 32 | 32 | * @return array |
| 33 | 33 | */ |
| 34 | - protected function prepare_reports_query( $request ) { |
|
| 34 | + protected function prepare_reports_query($request) { |
|
| 35 | 35 | $args = array(); |
| 36 | 36 | $args['offset'] = $request['offset']; |
| 37 | 37 | $args['order'] = $request['order']; |
@@ -43,9 +43,9 @@ discard block |
||
| 43 | 43 | $args['post_parent__in'] = $request['parent']; |
| 44 | 44 | $args['post_parent__not_in'] = $request['parent_exclude']; |
| 45 | 45 | |
| 46 | - if ( 'date' === $args['orderby'] ) { |
|
| 46 | + if ('date' === $args['orderby']) { |
|
| 47 | 47 | $args['orderby'] = 'date ID'; |
| 48 | - } elseif ( 'stock_status' === $args['orderby'] ) { |
|
| 48 | + } elseif ('stock_status' === $args['orderby']) { |
|
| 49 | 49 | $args['meta_query'] = array( // WPCS: slow query ok. |
| 50 | 50 | 'relation' => 'AND', |
| 51 | 51 | '_stock_status' => array( |
@@ -58,27 +58,27 @@ discard block |
||
| 58 | 58 | 'type' => 'NUMERIC', |
| 59 | 59 | ), |
| 60 | 60 | ); |
| 61 | - $args['orderby'] = array( |
|
| 61 | + $args['orderby'] = array( |
|
| 62 | 62 | '_stock_status' => $args['order'], |
| 63 | 63 | '_stock' => 'desc' === $args['order'] ? 'asc' : 'desc', |
| 64 | 64 | ); |
| 65 | - } elseif ( 'stock_quantity' === $args['orderby'] ) { |
|
| 65 | + } elseif ('stock_quantity' === $args['orderby']) { |
|
| 66 | 66 | $args['meta_key'] = '_stock'; // WPCS: slow query ok. |
| 67 | 67 | $args['orderby'] = 'meta_value_num'; |
| 68 | - } elseif ( 'include' === $args['orderby'] ) { |
|
| 68 | + } elseif ('include' === $args['orderby']) { |
|
| 69 | 69 | $args['orderby'] = 'post__in'; |
| 70 | - } elseif ( 'id' === $args['orderby'] ) { |
|
| 70 | + } elseif ('id' === $args['orderby']) { |
|
| 71 | 71 | $args['orderby'] = 'ID'; // ID must be capitalized. |
| 72 | - } elseif ( 'sku' === $args['orderby'] ) { |
|
| 72 | + } elseif ('sku' === $args['orderby']) { |
|
| 73 | 73 | $args['meta_key'] = '_sku'; // WPCS: slow query ok. |
| 74 | 74 | $args['orderby'] = 'meta_value'; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - $args['post_type'] = array( 'product', 'product_variation' ); |
|
| 77 | + $args['post_type'] = array('product', 'product_variation'); |
|
| 78 | 78 | |
| 79 | - if ( 'lowstock' === $request['type'] ) { |
|
| 80 | - $low_stock = absint( max( get_option( 'woocommerce_notify_low_stock_amount' ), 1 ) ); |
|
| 81 | - $no_stock = absint( max( get_option( 'woocommerce_notify_no_stock_amount' ), 0 ) ); |
|
| 79 | + if ('lowstock' === $request['type']) { |
|
| 80 | + $low_stock = absint(max(get_option('woocommerce_notify_low_stock_amount'), 1)); |
|
| 81 | + $no_stock = absint(max(get_option('woocommerce_notify_no_stock_amount'), 0)); |
|
| 82 | 82 | |
| 83 | 83 | $args['meta_query'] = array( // WPCS: slow query ok. |
| 84 | 84 | array( |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | ), |
| 88 | 88 | array( |
| 89 | 89 | 'key' => '_stock', |
| 90 | - 'value' => array( $no_stock, $low_stock ), |
|
| 90 | + 'value' => array($no_stock, $low_stock), |
|
| 91 | 91 | 'compare' => 'BETWEEN', |
| 92 | 92 | 'type' => 'NUMERIC', |
| 93 | 93 | ), |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | 'value' => 'instock', |
| 97 | 97 | ), |
| 98 | 98 | ); |
| 99 | - } elseif ( in_array( $request['type'], array_keys( wc_get_product_stock_status_options() ), true ) ) { |
|
| 99 | + } elseif (in_array($request['type'], array_keys(wc_get_product_stock_status_options()), true)) { |
|
| 100 | 100 | $args['meta_query'] = array( // WPCS: slow query ok. |
| 101 | 101 | array( |
| 102 | 102 | 'key' => '_stock_status', |
@@ -116,23 +116,23 @@ discard block |
||
| 116 | 116 | * @param array $query_args Query args. |
| 117 | 117 | * @return array |
| 118 | 118 | */ |
| 119 | - protected function get_products( $query_args ) { |
|
| 119 | + protected function get_products($query_args) { |
|
| 120 | 120 | $query = new \WP_Query(); |
| 121 | - $result = $query->query( $query_args ); |
|
| 121 | + $result = $query->query($query_args); |
|
| 122 | 122 | |
| 123 | 123 | $total_posts = $query->found_posts; |
| 124 | - if ( $total_posts < 1 ) { |
|
| 124 | + if ($total_posts < 1) { |
|
| 125 | 125 | // Out-of-bounds, run the query again without LIMIT for total count. |
| 126 | - unset( $query_args['paged'] ); |
|
| 126 | + unset($query_args['paged']); |
|
| 127 | 127 | $count_query = new \WP_Query(); |
| 128 | - $count_query->query( $query_args ); |
|
| 128 | + $count_query->query($query_args); |
|
| 129 | 129 | $total_posts = $count_query->found_posts; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | return array( |
| 133 | - 'objects' => array_map( 'wc_get_product', $result ), |
|
| 133 | + 'objects' => array_map('wc_get_product', $result), |
|
| 134 | 134 | 'total' => (int) $total_posts, |
| 135 | - 'pages' => (int) ceil( $total_posts / (int) $query->query_vars['posts_per_page'] ), |
|
| 135 | + 'pages' => (int) ceil($total_posts / (int) $query->query_vars['posts_per_page']), |
|
| 136 | 136 | ); |
| 137 | 137 | } |
| 138 | 138 | |
@@ -142,37 +142,37 @@ discard block |
||
| 142 | 142 | * @param \WP_REST_Request $request Request data. |
| 143 | 143 | * @return array|\WP_Error |
| 144 | 144 | */ |
| 145 | - public function get_items( $request ) { |
|
| 146 | - $query_args = $this->prepare_reports_query( $request ); |
|
| 147 | - $query_results = $this->get_products( $query_args ); |
|
| 145 | + public function get_items($request) { |
|
| 146 | + $query_args = $this->prepare_reports_query($request); |
|
| 147 | + $query_results = $this->get_products($query_args); |
|
| 148 | 148 | |
| 149 | 149 | $objects = array(); |
| 150 | - foreach ( $query_results['objects'] as $object ) { |
|
| 151 | - $data = $this->prepare_item_for_response( $object, $request ); |
|
| 152 | - $objects[] = $this->prepare_response_for_collection( $data ); |
|
| 150 | + foreach ($query_results['objects'] as $object) { |
|
| 151 | + $data = $this->prepare_item_for_response($object, $request); |
|
| 152 | + $objects[] = $this->prepare_response_for_collection($data); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | $page = (int) $query_args['paged']; |
| 156 | 156 | $max_pages = $query_results['pages']; |
| 157 | 157 | |
| 158 | - $response = rest_ensure_response( $objects ); |
|
| 159 | - $response->header( 'X-WP-Total', $query_results['total'] ); |
|
| 160 | - $response->header( 'X-WP-TotalPages', (int) $max_pages ); |
|
| 158 | + $response = rest_ensure_response($objects); |
|
| 159 | + $response->header('X-WP-Total', $query_results['total']); |
|
| 160 | + $response->header('X-WP-TotalPages', (int) $max_pages); |
|
| 161 | 161 | |
| 162 | - $base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) ); |
|
| 162 | + $base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base))); |
|
| 163 | 163 | |
| 164 | - if ( $page > 1 ) { |
|
| 164 | + if ($page > 1) { |
|
| 165 | 165 | $prev_page = $page - 1; |
| 166 | - if ( $prev_page > $max_pages ) { |
|
| 166 | + if ($prev_page > $max_pages) { |
|
| 167 | 167 | $prev_page = $max_pages; |
| 168 | 168 | } |
| 169 | - $prev_link = add_query_arg( 'page', $prev_page, $base ); |
|
| 170 | - $response->link_header( 'prev', $prev_link ); |
|
| 169 | + $prev_link = add_query_arg('page', $prev_page, $base); |
|
| 170 | + $response->link_header('prev', $prev_link); |
|
| 171 | 171 | } |
| 172 | - if ( $max_pages > $page ) { |
|
| 172 | + if ($max_pages > $page) { |
|
| 173 | 173 | $next_page = $page + 1; |
| 174 | - $next_link = add_query_arg( 'page', $next_page, $base ); |
|
| 175 | - $response->link_header( 'next', $next_link ); |
|
| 174 | + $next_link = add_query_arg('page', $next_page, $base); |
|
| 175 | + $response->link_header('next', $next_link); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | return $response; |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | * @param \WP_REST_Request $request Request object. |
| 186 | 186 | * @return \WP_REST_Response |
| 187 | 187 | */ |
| 188 | - public function prepare_item_for_response( $product, $request ) { |
|
| 188 | + public function prepare_item_for_response($product, $request) { |
|
| 189 | 189 | $data = array( |
| 190 | 190 | 'id' => $product->get_id(), |
| 191 | 191 | 'parent_id' => $product->get_parent_id(), |
@@ -196,13 +196,13 @@ discard block |
||
| 196 | 196 | 'manage_stock' => $product->get_manage_stock(), |
| 197 | 197 | ); |
| 198 | 198 | |
| 199 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 200 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
| 201 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 199 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
| 200 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
| 201 | + $data = $this->filter_response_by_context($data, $context); |
|
| 202 | 202 | |
| 203 | 203 | // Wrap the data in a response object. |
| 204 | - $response = rest_ensure_response( $data ); |
|
| 205 | - $response->add_links( $this->prepare_links( $product ) ); |
|
| 204 | + $response = rest_ensure_response($data); |
|
| 205 | + $response->add_links($this->prepare_links($product)); |
|
| 206 | 206 | |
| 207 | 207 | /** |
| 208 | 208 | * Filter a report returned from the API. |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | * @param WC_Product $product The original product object. |
| 214 | 214 | * @param \WP_REST_Request $request Request used to generate the response. |
| 215 | 215 | */ |
| 216 | - return apply_filters( 'woocommerce_rest_prepare_report_stock', $response, $product, $request ); |
|
| 216 | + return apply_filters('woocommerce_rest_prepare_report_stock', $response, $product, $request); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
@@ -222,29 +222,29 @@ discard block |
||
| 222 | 222 | * @param WC_Product $product Object data. |
| 223 | 223 | * @return array |
| 224 | 224 | */ |
| 225 | - protected function prepare_links( $product ) { |
|
| 226 | - if ( $product->is_type( 'variation' ) ) { |
|
| 225 | + protected function prepare_links($product) { |
|
| 226 | + if ($product->is_type('variation')) { |
|
| 227 | 227 | $links = array( |
| 228 | 228 | 'product' => array( |
| 229 | - 'href' => rest_url( sprintf( '/%s/products/%d/variations/%d', $this->namespace, $product->get_parent_id(), $product->get_id() ) ), |
|
| 229 | + 'href' => rest_url(sprintf('/%s/products/%d/variations/%d', $this->namespace, $product->get_parent_id(), $product->get_id())), |
|
| 230 | 230 | ), |
| 231 | 231 | 'parent' => array( |
| 232 | - 'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $product->get_parent_id() ) ), |
|
| 232 | + 'href' => rest_url(sprintf('/%s/products/%d', $this->namespace, $product->get_parent_id())), |
|
| 233 | 233 | ), |
| 234 | 234 | ); |
| 235 | - } elseif ( $product->get_parent_id() ) { |
|
| 235 | + } elseif ($product->get_parent_id()) { |
|
| 236 | 236 | $links = array( |
| 237 | 237 | 'product' => array( |
| 238 | - 'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $product->get_id() ) ), |
|
| 238 | + 'href' => rest_url(sprintf('/%s/products/%d', $this->namespace, $product->get_id())), |
|
| 239 | 239 | ), |
| 240 | 240 | 'parent' => array( |
| 241 | - 'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $product->get_parent_id() ) ), |
|
| 241 | + 'href' => rest_url(sprintf('/%s/products/%d', $this->namespace, $product->get_parent_id())), |
|
| 242 | 242 | ), |
| 243 | 243 | ); |
| 244 | 244 | } else { |
| 245 | 245 | $links = array( |
| 246 | 246 | 'product' => array( |
| 247 | - 'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $product->get_id() ) ), |
|
| 247 | + 'href' => rest_url(sprintf('/%s/products/%d', $this->namespace, $product->get_id())), |
|
| 248 | 248 | ), |
| 249 | 249 | ); |
| 250 | 250 | } |
@@ -264,52 +264,52 @@ discard block |
||
| 264 | 264 | 'type' => 'object', |
| 265 | 265 | 'properties' => array( |
| 266 | 266 | 'id' => array( |
| 267 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
| 267 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
| 268 | 268 | 'type' => 'integer', |
| 269 | - 'context' => array( 'view', 'edit' ), |
|
| 269 | + 'context' => array('view', 'edit'), |
|
| 270 | 270 | 'readonly' => true, |
| 271 | 271 | ), |
| 272 | 272 | 'parent_id' => array( |
| 273 | - 'description' => __( 'Product parent ID.', 'woocommerce' ), |
|
| 273 | + 'description' => __('Product parent ID.', 'woocommerce'), |
|
| 274 | 274 | 'type' => 'integer', |
| 275 | - 'context' => array( 'view', 'edit' ), |
|
| 275 | + 'context' => array('view', 'edit'), |
|
| 276 | 276 | 'readonly' => true, |
| 277 | 277 | ), |
| 278 | 278 | 'name' => array( |
| 279 | - 'description' => __( 'Product name.', 'woocommerce' ), |
|
| 279 | + 'description' => __('Product name.', 'woocommerce'), |
|
| 280 | 280 | 'type' => 'string', |
| 281 | - 'context' => array( 'view', 'edit' ), |
|
| 281 | + 'context' => array('view', 'edit'), |
|
| 282 | 282 | 'readonly' => true, |
| 283 | 283 | ), |
| 284 | 284 | 'sku' => array( |
| 285 | - 'description' => __( 'Unique identifier.', 'woocommerce' ), |
|
| 285 | + 'description' => __('Unique identifier.', 'woocommerce'), |
|
| 286 | 286 | 'type' => 'string', |
| 287 | - 'context' => array( 'view', 'edit' ), |
|
| 287 | + 'context' => array('view', 'edit'), |
|
| 288 | 288 | 'readonly' => true, |
| 289 | 289 | ), |
| 290 | 290 | 'stock_status' => array( |
| 291 | - 'description' => __( 'Stock status.', 'woocommerce' ), |
|
| 291 | + 'description' => __('Stock status.', 'woocommerce'), |
|
| 292 | 292 | 'type' => 'string', |
| 293 | - 'enum' => array_keys( wc_get_product_stock_status_options() ), |
|
| 294 | - 'context' => array( 'view', 'edit' ), |
|
| 293 | + 'enum' => array_keys(wc_get_product_stock_status_options()), |
|
| 294 | + 'context' => array('view', 'edit'), |
|
| 295 | 295 | 'readonly' => true, |
| 296 | 296 | ), |
| 297 | 297 | 'stock_quantity' => array( |
| 298 | - 'description' => __( 'Stock quantity.', 'woocommerce' ), |
|
| 298 | + 'description' => __('Stock quantity.', 'woocommerce'), |
|
| 299 | 299 | 'type' => 'integer', |
| 300 | - 'context' => array( 'view', 'edit' ), |
|
| 300 | + 'context' => array('view', 'edit'), |
|
| 301 | 301 | 'readonly' => true, |
| 302 | 302 | ), |
| 303 | 303 | 'manage_stock' => array( |
| 304 | - 'description' => __( 'Manage stock.', 'woocommerce' ), |
|
| 304 | + 'description' => __('Manage stock.', 'woocommerce'), |
|
| 305 | 305 | 'type' => 'boolean', |
| 306 | - 'context' => array( 'view', 'edit' ), |
|
| 306 | + 'context' => array('view', 'edit'), |
|
| 307 | 307 | 'readonly' => true, |
| 308 | 308 | ), |
| 309 | 309 | ), |
| 310 | 310 | ); |
| 311 | 311 | |
| 312 | - return $this->add_additional_fields_schema( $schema ); |
|
| 312 | + return $this->add_additional_fields_schema($schema); |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | /** |
@@ -319,17 +319,17 @@ discard block |
||
| 319 | 319 | */ |
| 320 | 320 | public function get_collection_params() { |
| 321 | 321 | $params = array(); |
| 322 | - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); |
|
| 322 | + $params['context'] = $this->get_context_param(array('default' => 'view')); |
|
| 323 | 323 | $params['page'] = array( |
| 324 | - 'description' => __( 'Current page of the collection.', 'woocommerce' ), |
|
| 324 | + 'description' => __('Current page of the collection.', 'woocommerce'), |
|
| 325 | 325 | 'type' => 'integer', |
| 326 | 326 | 'default' => 1, |
| 327 | 327 | 'sanitize_callback' => 'absint', |
| 328 | 328 | 'validate_callback' => 'rest_validate_request_arg', |
| 329 | 329 | 'minimum' => 1, |
| 330 | 330 | ); |
| 331 | - $params['per_page'] = array( |
|
| 332 | - 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ), |
|
| 331 | + $params['per_page'] = array( |
|
| 332 | + 'description' => __('Maximum number of items to be returned in result set.', 'woocommerce'), |
|
| 333 | 333 | 'type' => 'integer', |
| 334 | 334 | 'default' => 10, |
| 335 | 335 | 'minimum' => 1, |
@@ -337,8 +337,8 @@ discard block |
||
| 337 | 337 | 'sanitize_callback' => 'absint', |
| 338 | 338 | 'validate_callback' => 'rest_validate_request_arg', |
| 339 | 339 | ); |
| 340 | - $params['exclude'] = array( |
|
| 341 | - 'description' => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ), |
|
| 340 | + $params['exclude'] = array( |
|
| 341 | + 'description' => __('Ensure result set excludes specific IDs.', 'woocommerce'), |
|
| 342 | 342 | 'type' => 'array', |
| 343 | 343 | 'items' => array( |
| 344 | 344 | 'type' => 'integer', |
@@ -346,8 +346,8 @@ discard block |
||
| 346 | 346 | 'default' => array(), |
| 347 | 347 | 'sanitize_callback' => 'wp_parse_id_list', |
| 348 | 348 | ); |
| 349 | - $params['include'] = array( |
|
| 350 | - 'description' => __( 'Limit result set to specific ids.', 'woocommerce' ), |
|
| 349 | + $params['include'] = array( |
|
| 350 | + 'description' => __('Limit result set to specific ids.', 'woocommerce'), |
|
| 351 | 351 | 'type' => 'array', |
| 352 | 352 | 'items' => array( |
| 353 | 353 | 'type' => 'integer', |
@@ -355,21 +355,21 @@ discard block |
||
| 355 | 355 | 'default' => array(), |
| 356 | 356 | 'sanitize_callback' => 'wp_parse_id_list', |
| 357 | 357 | ); |
| 358 | - $params['offset'] = array( |
|
| 359 | - 'description' => __( 'Offset the result set by a specific number of items.', 'woocommerce' ), |
|
| 358 | + $params['offset'] = array( |
|
| 359 | + 'description' => __('Offset the result set by a specific number of items.', 'woocommerce'), |
|
| 360 | 360 | 'type' => 'integer', |
| 361 | 361 | 'sanitize_callback' => 'absint', |
| 362 | 362 | 'validate_callback' => 'rest_validate_request_arg', |
| 363 | 363 | ); |
| 364 | - $params['order'] = array( |
|
| 365 | - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), |
|
| 364 | + $params['order'] = array( |
|
| 365 | + 'description' => __('Order sort attribute ascending or descending.', 'woocommerce'), |
|
| 366 | 366 | 'type' => 'string', |
| 367 | 367 | 'default' => 'asc', |
| 368 | - 'enum' => array( 'asc', 'desc' ), |
|
| 368 | + 'enum' => array('asc', 'desc'), |
|
| 369 | 369 | 'validate_callback' => 'rest_validate_request_arg', |
| 370 | 370 | ); |
| 371 | - $params['orderby'] = array( |
|
| 372 | - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), |
|
| 371 | + $params['orderby'] = array( |
|
| 372 | + 'description' => __('Sort collection by object attribute.', 'woocommerce'), |
|
| 373 | 373 | 'type' => 'string', |
| 374 | 374 | 'default' => 'stock_status', |
| 375 | 375 | 'enum' => array( |
@@ -383,8 +383,8 @@ discard block |
||
| 383 | 383 | ), |
| 384 | 384 | 'validate_callback' => 'rest_validate_request_arg', |
| 385 | 385 | ); |
| 386 | - $params['parent'] = array( |
|
| 387 | - 'description' => __( 'Limit result set to those of particular parent IDs.', 'woocommerce' ), |
|
| 386 | + $params['parent'] = array( |
|
| 387 | + 'description' => __('Limit result set to those of particular parent IDs.', 'woocommerce'), |
|
| 388 | 388 | 'type' => 'array', |
| 389 | 389 | 'items' => array( |
| 390 | 390 | 'type' => 'integer', |
@@ -393,7 +393,7 @@ discard block |
||
| 393 | 393 | 'default' => array(), |
| 394 | 394 | ); |
| 395 | 395 | $params['parent_exclude'] = array( |
| 396 | - 'description' => __( 'Limit result set to all items except those of a particular parent ID.', 'woocommerce' ), |
|
| 396 | + 'description' => __('Limit result set to all items except those of a particular parent ID.', 'woocommerce'), |
|
| 397 | 397 | 'type' => 'array', |
| 398 | 398 | 'items' => array( |
| 399 | 399 | 'type' => 'integer', |
@@ -401,11 +401,11 @@ discard block |
||
| 401 | 401 | 'sanitize_callback' => 'wp_parse_id_list', |
| 402 | 402 | 'default' => array(), |
| 403 | 403 | ); |
| 404 | - $params['type'] = array( |
|
| 405 | - 'description' => __( 'Limit result set to items assigned a stock report type.', 'woocommerce' ), |
|
| 404 | + $params['type'] = array( |
|
| 405 | + 'description' => __('Limit result set to items assigned a stock report type.', 'woocommerce'), |
|
| 406 | 406 | 'type' => 'string', |
| 407 | 407 | 'default' => 'all', |
| 408 | - 'enum' => array_merge( array( 'all', 'lowstock' ), array_keys( wc_get_product_stock_status_options() ) ), |
|
| 408 | + 'enum' => array_merge(array('all', 'lowstock'), array_keys(wc_get_product_stock_status_options())), |
|
| 409 | 409 | ); |
| 410 | 410 | |
| 411 | 411 | return $params; |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | namespace WooCommerce\RestApi\Version4\Controllers\Reports; |
| 11 | 11 | |
| 12 | -defined( 'ABSPATH' ) || exit; |
|
| 12 | +defined('ABSPATH') || exit; |
|
| 13 | 13 | |
| 14 | 14 | use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports; |
| 15 | 15 | |
@@ -41,48 +41,48 @@ discard block |
||
| 41 | 41 | * |
| 42 | 42 | * @return array|\WP_Error |
| 43 | 43 | */ |
| 44 | - public function get_items( $request ) { |
|
| 44 | + public function get_items($request) { |
|
| 45 | 45 | $args = array(); |
| 46 | - $registered = array_keys( $this->get_collection_params() ); |
|
| 47 | - foreach ( $registered as $param_name ) { |
|
| 48 | - if ( isset( $request[ $param_name ] ) ) { |
|
| 49 | - if ( isset( $this->param_mapping[ $param_name ] ) ) { |
|
| 50 | - $args[ $this->param_mapping[ $param_name ] ] = $request[ $param_name ]; |
|
| 46 | + $registered = array_keys($this->get_collection_params()); |
|
| 47 | + foreach ($registered as $param_name) { |
|
| 48 | + if (isset($request[$param_name])) { |
|
| 49 | + if (isset($this->param_mapping[$param_name])) { |
|
| 50 | + $args[$this->param_mapping[$param_name]] = $request[$param_name]; |
|
| 51 | 51 | } else { |
| 52 | - $args[ $param_name ] = $request[ $param_name ]; |
|
| 52 | + $args[$param_name] = $request[$param_name]; |
|
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - $reports = new \WC_Admin_Reports_Products_Query( $args ); |
|
| 57 | + $reports = new \WC_Admin_Reports_Products_Query($args); |
|
| 58 | 58 | $products_data = $reports->get_data(); |
| 59 | 59 | |
| 60 | 60 | $data = array(); |
| 61 | 61 | |
| 62 | - foreach ( $products_data->data as $product_data ) { |
|
| 63 | - $item = $this->prepare_item_for_response( $product_data, $request ); |
|
| 64 | - $data[] = $this->prepare_response_for_collection( $item ); |
|
| 62 | + foreach ($products_data->data as $product_data) { |
|
| 63 | + $item = $this->prepare_item_for_response($product_data, $request); |
|
| 64 | + $data[] = $this->prepare_response_for_collection($item); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - $response = rest_ensure_response( $data ); |
|
| 68 | - $response->header( 'X-WP-Total', (int) $products_data->total ); |
|
| 69 | - $response->header( 'X-WP-TotalPages', (int) $products_data->pages ); |
|
| 67 | + $response = rest_ensure_response($data); |
|
| 68 | + $response->header('X-WP-Total', (int) $products_data->total); |
|
| 69 | + $response->header('X-WP-TotalPages', (int) $products_data->pages); |
|
| 70 | 70 | |
| 71 | 71 | $page = $products_data->page_no; |
| 72 | 72 | $max_pages = $products_data->pages; |
| 73 | - $base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) ); |
|
| 74 | - if ( $page > 1 ) { |
|
| 73 | + $base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base))); |
|
| 74 | + if ($page > 1) { |
|
| 75 | 75 | $prev_page = $page - 1; |
| 76 | - if ( $prev_page > $max_pages ) { |
|
| 76 | + if ($prev_page > $max_pages) { |
|
| 77 | 77 | $prev_page = $max_pages; |
| 78 | 78 | } |
| 79 | - $prev_link = add_query_arg( 'page', $prev_page, $base ); |
|
| 80 | - $response->link_header( 'prev', $prev_link ); |
|
| 79 | + $prev_link = add_query_arg('page', $prev_page, $base); |
|
| 80 | + $response->link_header('prev', $prev_link); |
|
| 81 | 81 | } |
| 82 | - if ( $max_pages > $page ) { |
|
| 82 | + if ($max_pages > $page) { |
|
| 83 | 83 | $next_page = $page + 1; |
| 84 | - $next_link = add_query_arg( 'page', $next_page, $base ); |
|
| 85 | - $response->link_header( 'next', $next_link ); |
|
| 84 | + $next_link = add_query_arg('page', $next_page, $base); |
|
| 85 | + $response->link_header('next', $next_link); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | return $response; |
@@ -95,16 +95,16 @@ discard block |
||
| 95 | 95 | * @param \WP_REST_Request $request Request object. |
| 96 | 96 | * @return \WP_REST_Response |
| 97 | 97 | */ |
| 98 | - public function prepare_item_for_response( $report, $request ) { |
|
| 98 | + public function prepare_item_for_response($report, $request) { |
|
| 99 | 99 | $data = $report; |
| 100 | 100 | |
| 101 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 102 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
| 103 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 101 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
| 102 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
| 103 | + $data = $this->filter_response_by_context($data, $context); |
|
| 104 | 104 | |
| 105 | 105 | // Wrap the data in a response object. |
| 106 | - $response = rest_ensure_response( $data ); |
|
| 107 | - $response->add_links( $this->prepare_links( $report ) ); |
|
| 106 | + $response = rest_ensure_response($data); |
|
| 107 | + $response->add_links($this->prepare_links($report)); |
|
| 108 | 108 | |
| 109 | 109 | /** |
| 110 | 110 | * Filter a report returned from the API. |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | * @param object $report The original report object. |
| 116 | 116 | * @param \WP_REST_Request $request Request used to generate the response. |
| 117 | 117 | */ |
| 118 | - return apply_filters( 'woocommerce_rest_prepare_report_products', $response, $report, $request ); |
|
| 118 | + return apply_filters('woocommerce_rest_prepare_report_products', $response, $report, $request); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -124,10 +124,10 @@ discard block |
||
| 124 | 124 | * @param Array $object Object data. |
| 125 | 125 | * @return array Links for the given post. |
| 126 | 126 | */ |
| 127 | - protected function prepare_links( $object ) { |
|
| 127 | + protected function prepare_links($object) { |
|
| 128 | 128 | $links = array( |
| 129 | 129 | 'product' => array( |
| 130 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, 'products', $object['product_id'] ) ), |
|
| 130 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, 'products', $object['product_id'])), |
|
| 131 | 131 | ), |
| 132 | 132 | ); |
| 133 | 133 | |
@@ -148,93 +148,93 @@ discard block |
||
| 148 | 148 | 'product_id' => array( |
| 149 | 149 | 'type' => 'integer', |
| 150 | 150 | 'readonly' => true, |
| 151 | - 'context' => array( 'view', 'edit' ), |
|
| 152 | - 'description' => __( 'Product ID.', 'woocommerce' ), |
|
| 151 | + 'context' => array('view', 'edit'), |
|
| 152 | + 'description' => __('Product ID.', 'woocommerce'), |
|
| 153 | 153 | ), |
| 154 | 154 | 'items_sold' => array( |
| 155 | 155 | 'type' => 'integer', |
| 156 | 156 | 'readonly' => true, |
| 157 | - 'context' => array( 'view', 'edit' ), |
|
| 158 | - 'description' => __( 'Number of items sold.', 'woocommerce' ), |
|
| 157 | + 'context' => array('view', 'edit'), |
|
| 158 | + 'description' => __('Number of items sold.', 'woocommerce'), |
|
| 159 | 159 | ), |
| 160 | 160 | 'net_revenue' => array( |
| 161 | 161 | 'type' => 'number', |
| 162 | 162 | 'readonly' => true, |
| 163 | - 'context' => array( 'view', 'edit' ), |
|
| 164 | - 'description' => __( 'Total net revenue of all items sold.', 'woocommerce' ), |
|
| 163 | + 'context' => array('view', 'edit'), |
|
| 164 | + 'description' => __('Total net revenue of all items sold.', 'woocommerce'), |
|
| 165 | 165 | ), |
| 166 | 166 | 'orders_count' => array( |
| 167 | 167 | 'type' => 'integer', |
| 168 | 168 | 'readonly' => true, |
| 169 | - 'context' => array( 'view', 'edit' ), |
|
| 170 | - 'description' => __( 'Number of orders product appeared in.', 'woocommerce' ), |
|
| 169 | + 'context' => array('view', 'edit'), |
|
| 170 | + 'description' => __('Number of orders product appeared in.', 'woocommerce'), |
|
| 171 | 171 | ), |
| 172 | 172 | 'extended_info' => array( |
| 173 | 173 | 'name' => array( |
| 174 | 174 | 'type' => 'string', |
| 175 | 175 | 'readonly' => true, |
| 176 | - 'context' => array( 'view', 'edit' ), |
|
| 177 | - 'description' => __( 'Product name.', 'woocommerce' ), |
|
| 176 | + 'context' => array('view', 'edit'), |
|
| 177 | + 'description' => __('Product name.', 'woocommerce'), |
|
| 178 | 178 | ), |
| 179 | 179 | 'price' => array( |
| 180 | 180 | 'type' => 'number', |
| 181 | 181 | 'readonly' => true, |
| 182 | - 'context' => array( 'view', 'edit' ), |
|
| 183 | - 'description' => __( 'Product price.', 'woocommerce' ), |
|
| 182 | + 'context' => array('view', 'edit'), |
|
| 183 | + 'description' => __('Product price.', 'woocommerce'), |
|
| 184 | 184 | ), |
| 185 | 185 | 'image' => array( |
| 186 | 186 | 'type' => 'string', |
| 187 | 187 | 'readonly' => true, |
| 188 | - 'context' => array( 'view', 'edit' ), |
|
| 189 | - 'description' => __( 'Product image.', 'woocommerce' ), |
|
| 188 | + 'context' => array('view', 'edit'), |
|
| 189 | + 'description' => __('Product image.', 'woocommerce'), |
|
| 190 | 190 | ), |
| 191 | 191 | 'permalink' => array( |
| 192 | 192 | 'type' => 'string', |
| 193 | 193 | 'readonly' => true, |
| 194 | - 'context' => array( 'view', 'edit' ), |
|
| 195 | - 'description' => __( 'Product link.', 'woocommerce' ), |
|
| 194 | + 'context' => array('view', 'edit'), |
|
| 195 | + 'description' => __('Product link.', 'woocommerce'), |
|
| 196 | 196 | ), |
| 197 | 197 | 'attributes' => array( |
| 198 | 198 | 'type' => 'array', |
| 199 | 199 | 'readonly' => true, |
| 200 | - 'context' => array( 'view', 'edit' ), |
|
| 201 | - 'description' => __( 'Product attributes.', 'woocommerce' ), |
|
| 200 | + 'context' => array('view', 'edit'), |
|
| 201 | + 'description' => __('Product attributes.', 'woocommerce'), |
|
| 202 | 202 | ), |
| 203 | 203 | 'stock_status' => array( |
| 204 | 204 | 'type' => 'string', |
| 205 | 205 | 'readonly' => true, |
| 206 | - 'context' => array( 'view', 'edit' ), |
|
| 207 | - 'description' => __( 'Product inventory status.', 'woocommerce' ), |
|
| 206 | + 'context' => array('view', 'edit'), |
|
| 207 | + 'description' => __('Product inventory status.', 'woocommerce'), |
|
| 208 | 208 | ), |
| 209 | 209 | 'stock_quantity' => array( |
| 210 | 210 | 'type' => 'integer', |
| 211 | 211 | 'readonly' => true, |
| 212 | - 'context' => array( 'view', 'edit' ), |
|
| 213 | - 'description' => __( 'Product inventory quantity.', 'woocommerce' ), |
|
| 212 | + 'context' => array('view', 'edit'), |
|
| 213 | + 'description' => __('Product inventory quantity.', 'woocommerce'), |
|
| 214 | 214 | ), |
| 215 | 215 | 'low_stock_amount' => array( |
| 216 | 216 | 'type' => 'integer', |
| 217 | 217 | 'readonly' => true, |
| 218 | - 'context' => array( 'view', 'edit' ), |
|
| 219 | - 'description' => __( 'Product inventory threshold for low stock.', 'woocommerce' ), |
|
| 218 | + 'context' => array('view', 'edit'), |
|
| 219 | + 'description' => __('Product inventory threshold for low stock.', 'woocommerce'), |
|
| 220 | 220 | ), |
| 221 | 221 | 'variations' => array( |
| 222 | 222 | 'type' => 'array', |
| 223 | 223 | 'readonly' => true, |
| 224 | - 'context' => array( 'view', 'edit' ), |
|
| 225 | - 'description' => __( 'Product variations IDs.', 'woocommerce' ), |
|
| 224 | + 'context' => array('view', 'edit'), |
|
| 225 | + 'description' => __('Product variations IDs.', 'woocommerce'), |
|
| 226 | 226 | ), |
| 227 | 227 | 'sku' => array( |
| 228 | 228 | 'type' => 'string', |
| 229 | 229 | 'readonly' => true, |
| 230 | - 'context' => array( 'view', 'edit' ), |
|
| 231 | - 'description' => __( 'Product SKU.', 'woocommerce' ), |
|
| 230 | + 'context' => array('view', 'edit'), |
|
| 231 | + 'description' => __('Product SKU.', 'woocommerce'), |
|
| 232 | 232 | ), |
| 233 | 233 | ), |
| 234 | 234 | ), |
| 235 | 235 | ); |
| 236 | 236 | |
| 237 | - return $this->add_additional_fields_schema( $schema ); |
|
| 237 | + return $this->add_additional_fields_schema($schema); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | /** |
@@ -244,17 +244,17 @@ discard block |
||
| 244 | 244 | */ |
| 245 | 245 | public function get_collection_params() { |
| 246 | 246 | $params = array(); |
| 247 | - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); |
|
| 247 | + $params['context'] = $this->get_context_param(array('default' => 'view')); |
|
| 248 | 248 | $params['page'] = array( |
| 249 | - 'description' => __( 'Current page of the collection.', 'woocommerce' ), |
|
| 249 | + 'description' => __('Current page of the collection.', 'woocommerce'), |
|
| 250 | 250 | 'type' => 'integer', |
| 251 | 251 | 'default' => 1, |
| 252 | 252 | 'sanitize_callback' => 'absint', |
| 253 | 253 | 'validate_callback' => 'rest_validate_request_arg', |
| 254 | 254 | 'minimum' => 1, |
| 255 | 255 | ); |
| 256 | - $params['per_page'] = array( |
|
| 257 | - 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ), |
|
| 256 | + $params['per_page'] = array( |
|
| 257 | + 'description' => __('Maximum number of items to be returned in result set.', 'woocommerce'), |
|
| 258 | 258 | 'type' => 'integer', |
| 259 | 259 | 'default' => 10, |
| 260 | 260 | 'minimum' => 1, |
@@ -262,27 +262,27 @@ discard block |
||
| 262 | 262 | 'sanitize_callback' => 'absint', |
| 263 | 263 | 'validate_callback' => 'rest_validate_request_arg', |
| 264 | 264 | ); |
| 265 | - $params['after'] = array( |
|
| 266 | - 'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ), |
|
| 265 | + $params['after'] = array( |
|
| 266 | + 'description' => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'), |
|
| 267 | 267 | 'type' => 'string', |
| 268 | 268 | 'format' => 'date-time', |
| 269 | 269 | 'validate_callback' => 'rest_validate_request_arg', |
| 270 | 270 | ); |
| 271 | - $params['before'] = array( |
|
| 272 | - 'description' => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ), |
|
| 271 | + $params['before'] = array( |
|
| 272 | + 'description' => __('Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce'), |
|
| 273 | 273 | 'type' => 'string', |
| 274 | 274 | 'format' => 'date-time', |
| 275 | 275 | 'validate_callback' => 'rest_validate_request_arg', |
| 276 | 276 | ); |
| 277 | - $params['order'] = array( |
|
| 278 | - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), |
|
| 277 | + $params['order'] = array( |
|
| 278 | + 'description' => __('Order sort attribute ascending or descending.', 'woocommerce'), |
|
| 279 | 279 | 'type' => 'string', |
| 280 | 280 | 'default' => 'desc', |
| 281 | - 'enum' => array( 'asc', 'desc' ), |
|
| 281 | + 'enum' => array('asc', 'desc'), |
|
| 282 | 282 | 'validate_callback' => 'rest_validate_request_arg', |
| 283 | 283 | ); |
| 284 | - $params['orderby'] = array( |
|
| 285 | - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), |
|
| 284 | + $params['orderby'] = array( |
|
| 285 | + 'description' => __('Sort collection by object attribute.', 'woocommerce'), |
|
| 286 | 286 | 'type' => 'string', |
| 287 | 287 | 'default' => 'date', |
| 288 | 288 | 'enum' => array( |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | 'validate_callback' => 'rest_validate_request_arg', |
| 298 | 298 | ); |
| 299 | 299 | $params['categories'] = array( |
| 300 | - 'description' => __( 'Limit result to items from the specified categories.', 'woocommerce' ), |
|
| 300 | + 'description' => __('Limit result to items from the specified categories.', 'woocommerce'), |
|
| 301 | 301 | 'type' => 'array', |
| 302 | 302 | 'sanitize_callback' => 'wp_parse_id_list', |
| 303 | 303 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -305,8 +305,8 @@ discard block |
||
| 305 | 305 | 'type' => 'integer', |
| 306 | 306 | ), |
| 307 | 307 | ); |
| 308 | - $params['match'] = array( |
|
| 309 | - 'description' => __( 'Indicates whether all the conditions should be true for the resulting set, or if any one of them is sufficient. Match affects the following parameters: status_is, status_is_not, product_includes, product_excludes, coupon_includes, coupon_excludes, customer, categories', 'woocommerce' ), |
|
| 308 | + $params['match'] = array( |
|
| 309 | + 'description' => __('Indicates whether all the conditions should be true for the resulting set, or if any one of them is sufficient. Match affects the following parameters: status_is, status_is_not, product_includes, product_excludes, coupon_includes, coupon_excludes, customer, categories', 'woocommerce'), |
|
| 310 | 310 | 'type' => 'string', |
| 311 | 311 | 'default' => 'all', |
| 312 | 312 | 'enum' => array( |
@@ -315,8 +315,8 @@ discard block |
||
| 315 | 315 | ), |
| 316 | 316 | 'validate_callback' => 'rest_validate_request_arg', |
| 317 | 317 | ); |
| 318 | - $params['products'] = array( |
|
| 319 | - 'description' => __( 'Limit result to items with specified product ids.', 'woocommerce' ), |
|
| 318 | + $params['products'] = array( |
|
| 319 | + 'description' => __('Limit result to items with specified product ids.', 'woocommerce'), |
|
| 320 | 320 | 'type' => 'array', |
| 321 | 321 | 'sanitize_callback' => 'wp_parse_id_list', |
| 322 | 322 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | |
| 327 | 327 | ); |
| 328 | 328 | $params['extended_info'] = array( |
| 329 | - 'description' => __( 'Add additional piece of info about each product to the report.', 'woocommerce' ), |
|
| 329 | + 'description' => __('Add additional piece of info about each product to the report.', 'woocommerce'), |
|
| 330 | 330 | 'type' => 'boolean', |
| 331 | 331 | 'default' => false, |
| 332 | 332 | 'sanitize_callback' => 'wc_string_to_bool', |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | namespace WooCommerce\RestApi\Version4\Controllers\Reports; |
| 11 | 11 | |
| 12 | -defined( 'ABSPATH' ) || exit; |
|
| 12 | +defined('ABSPATH') || exit; |
|
| 13 | 13 | |
| 14 | 14 | use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports; |
| 15 | 15 | |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * @param array $request Request array. |
| 32 | 32 | * @return array |
| 33 | 33 | */ |
| 34 | - protected function prepare_reports_query( $request ) { |
|
| 34 | + protected function prepare_reports_query($request) { |
|
| 35 | 35 | $args = array(); |
| 36 | 36 | $args['before'] = $request['before']; |
| 37 | 37 | $args['after'] = $request['after']; |
@@ -54,45 +54,45 @@ discard block |
||
| 54 | 54 | * @param \WP_REST_Request $request Request data. |
| 55 | 55 | * @return array|\WP_Error |
| 56 | 56 | */ |
| 57 | - public function get_items( $request ) { |
|
| 58 | - $query_args = $this->prepare_reports_query( $request ); |
|
| 59 | - $categories_query = new \WC_Admin_Reports_Categories_Query( $query_args ); |
|
| 57 | + public function get_items($request) { |
|
| 58 | + $query_args = $this->prepare_reports_query($request); |
|
| 59 | + $categories_query = new \WC_Admin_Reports_Categories_Query($query_args); |
|
| 60 | 60 | $report_data = $categories_query->get_data(); |
| 61 | 61 | |
| 62 | - if ( is_wp_error( $report_data ) ) { |
|
| 62 | + if (is_wp_error($report_data)) { |
|
| 63 | 63 | return $report_data; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - if ( ! isset( $report_data->data ) || ! isset( $report_data->page_no ) || ! isset( $report_data->pages ) ) { |
|
| 67 | - return new \WP_Error( 'woocommerce_rest_reports_categories_invalid_response', __( 'Invalid response from data store.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
| 66 | + if ( ! isset($report_data->data) || ! isset($report_data->page_no) || ! isset($report_data->pages)) { |
|
| 67 | + return new \WP_Error('woocommerce_rest_reports_categories_invalid_response', __('Invalid response from data store.', 'woocommerce'), array('status' => 500)); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | $out_data = array(); |
| 71 | 71 | |
| 72 | - foreach ( $report_data->data as $datum ) { |
|
| 73 | - $item = $this->prepare_item_for_response( $datum, $request ); |
|
| 74 | - $out_data[] = $this->prepare_response_for_collection( $item ); |
|
| 72 | + foreach ($report_data->data as $datum) { |
|
| 73 | + $item = $this->prepare_item_for_response($datum, $request); |
|
| 74 | + $out_data[] = $this->prepare_response_for_collection($item); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - $response = rest_ensure_response( $out_data ); |
|
| 78 | - $response->header( 'X-WP-Total', (int) $report_data->total ); |
|
| 79 | - $response->header( 'X-WP-TotalPages', (int) $report_data->pages ); |
|
| 77 | + $response = rest_ensure_response($out_data); |
|
| 78 | + $response->header('X-WP-Total', (int) $report_data->total); |
|
| 79 | + $response->header('X-WP-TotalPages', (int) $report_data->pages); |
|
| 80 | 80 | |
| 81 | 81 | $page = $report_data->page_no; |
| 82 | 82 | $max_pages = $report_data->pages; |
| 83 | - $base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) ); |
|
| 84 | - if ( $page > 1 ) { |
|
| 83 | + $base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base))); |
|
| 84 | + if ($page > 1) { |
|
| 85 | 85 | $prev_page = $page - 1; |
| 86 | - if ( $prev_page > $max_pages ) { |
|
| 86 | + if ($prev_page > $max_pages) { |
|
| 87 | 87 | $prev_page = $max_pages; |
| 88 | 88 | } |
| 89 | - $prev_link = add_query_arg( 'page', $prev_page, $base ); |
|
| 90 | - $response->link_header( 'prev', $prev_link ); |
|
| 89 | + $prev_link = add_query_arg('page', $prev_page, $base); |
|
| 90 | + $response->link_header('prev', $prev_link); |
|
| 91 | 91 | } |
| 92 | - if ( $max_pages > $page ) { |
|
| 92 | + if ($max_pages > $page) { |
|
| 93 | 93 | $next_page = $page + 1; |
| 94 | - $next_link = add_query_arg( 'page', $next_page, $base ); |
|
| 95 | - $response->link_header( 'next', $next_link ); |
|
| 94 | + $next_link = add_query_arg('page', $next_page, $base); |
|
| 95 | + $response->link_header('next', $next_link); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | return $response; |
@@ -105,16 +105,16 @@ discard block |
||
| 105 | 105 | * @param \WP_REST_Request $request Request object. |
| 106 | 106 | * @return \WP_REST_Response |
| 107 | 107 | */ |
| 108 | - public function prepare_item_for_response( $report, $request ) { |
|
| 108 | + public function prepare_item_for_response($report, $request) { |
|
| 109 | 109 | $data = $report; |
| 110 | 110 | |
| 111 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 112 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
| 113 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 111 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
| 112 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
| 113 | + $data = $this->filter_response_by_context($data, $context); |
|
| 114 | 114 | |
| 115 | 115 | // Wrap the data in a response object. |
| 116 | - $response = rest_ensure_response( $data ); |
|
| 117 | - $response->add_links( $this->prepare_links( $report ) ); |
|
| 116 | + $response = rest_ensure_response($data); |
|
| 117 | + $response->add_links($this->prepare_links($report)); |
|
| 118 | 118 | |
| 119 | 119 | /** |
| 120 | 120 | * Filter a report returned from the API. |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | * @param object $report The original report object. |
| 126 | 126 | * @param \WP_REST_Request $request Request used to generate the response. |
| 127 | 127 | */ |
| 128 | - return apply_filters( 'woocommerce_rest_prepare_report_categories', $response, $report, $request ); |
|
| 128 | + return apply_filters('woocommerce_rest_prepare_report_categories', $response, $report, $request); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
@@ -134,10 +134,10 @@ discard block |
||
| 134 | 134 | * @param WC_Admin_Reports_Query $object Object data. |
| 135 | 135 | * @return array |
| 136 | 136 | */ |
| 137 | - protected function prepare_links( $object ) { |
|
| 137 | + protected function prepare_links($object) { |
|
| 138 | 138 | $links = array( |
| 139 | 139 | 'category' => array( |
| 140 | - 'href' => rest_url( sprintf( '/%s/products/categories/%d', $this->namespace, $object['category_id'] ) ), |
|
| 140 | + 'href' => rest_url(sprintf('/%s/products/categories/%d', $this->namespace, $object['category_id'])), |
|
| 141 | 141 | ), |
| 142 | 142 | ); |
| 143 | 143 | |
@@ -156,47 +156,47 @@ discard block |
||
| 156 | 156 | 'type' => 'object', |
| 157 | 157 | 'properties' => array( |
| 158 | 158 | 'category_id' => array( |
| 159 | - 'description' => __( 'Category ID.', 'woocommerce' ), |
|
| 159 | + 'description' => __('Category ID.', 'woocommerce'), |
|
| 160 | 160 | 'type' => 'integer', |
| 161 | - 'context' => array( 'view', 'edit' ), |
|
| 161 | + 'context' => array('view', 'edit'), |
|
| 162 | 162 | 'readonly' => true, |
| 163 | 163 | ), |
| 164 | 164 | 'items_sold' => array( |
| 165 | - 'description' => __( 'Amount of items sold.', 'woocommerce' ), |
|
| 165 | + 'description' => __('Amount of items sold.', 'woocommerce'), |
|
| 166 | 166 | 'type' => 'integer', |
| 167 | - 'context' => array( 'view', 'edit' ), |
|
| 167 | + 'context' => array('view', 'edit'), |
|
| 168 | 168 | 'readonly' => true, |
| 169 | 169 | ), |
| 170 | 170 | 'net_revenue' => array( |
| 171 | - 'description' => __( 'Gross revenue.', 'woocommerce' ), |
|
| 171 | + 'description' => __('Gross revenue.', 'woocommerce'), |
|
| 172 | 172 | 'type' => 'number', |
| 173 | - 'context' => array( 'view', 'edit' ), |
|
| 173 | + 'context' => array('view', 'edit'), |
|
| 174 | 174 | 'readonly' => true, |
| 175 | 175 | ), |
| 176 | 176 | 'orders_count' => array( |
| 177 | - 'description' => __( 'Amount of orders.', 'woocommerce' ), |
|
| 177 | + 'description' => __('Amount of orders.', 'woocommerce'), |
|
| 178 | 178 | 'type' => 'integer', |
| 179 | - 'context' => array( 'view', 'edit' ), |
|
| 179 | + 'context' => array('view', 'edit'), |
|
| 180 | 180 | 'readonly' => true, |
| 181 | 181 | ), |
| 182 | 182 | 'products_count' => array( |
| 183 | - 'description' => __( 'Amount of products.', 'woocommerce' ), |
|
| 183 | + 'description' => __('Amount of products.', 'woocommerce'), |
|
| 184 | 184 | 'type' => 'integer', |
| 185 | - 'context' => array( 'view', 'edit' ), |
|
| 185 | + 'context' => array('view', 'edit'), |
|
| 186 | 186 | 'readonly' => true, |
| 187 | 187 | ), |
| 188 | 188 | 'extended_info' => array( |
| 189 | 189 | 'name' => array( |
| 190 | 190 | 'type' => 'string', |
| 191 | 191 | 'readonly' => true, |
| 192 | - 'context' => array( 'view', 'edit' ), |
|
| 193 | - 'description' => __( 'Category name.', 'woocommerce' ), |
|
| 192 | + 'context' => array('view', 'edit'), |
|
| 193 | + 'description' => __('Category name.', 'woocommerce'), |
|
| 194 | 194 | ), |
| 195 | 195 | ), |
| 196 | 196 | ), |
| 197 | 197 | ); |
| 198 | 198 | |
| 199 | - return $this->add_additional_fields_schema( $schema ); |
|
| 199 | + return $this->add_additional_fields_schema($schema); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | /** |
@@ -206,17 +206,17 @@ discard block |
||
| 206 | 206 | */ |
| 207 | 207 | public function get_collection_params() { |
| 208 | 208 | $params = array(); |
| 209 | - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); |
|
| 209 | + $params['context'] = $this->get_context_param(array('default' => 'view')); |
|
| 210 | 210 | $params['page'] = array( |
| 211 | - 'description' => __( 'Current page of the collection.', 'woocommerce' ), |
|
| 211 | + 'description' => __('Current page of the collection.', 'woocommerce'), |
|
| 212 | 212 | 'type' => 'integer', |
| 213 | 213 | 'default' => 1, |
| 214 | 214 | 'sanitize_callback' => 'absint', |
| 215 | 215 | 'validate_callback' => 'rest_validate_request_arg', |
| 216 | 216 | 'minimum' => 1, |
| 217 | 217 | ); |
| 218 | - $params['per_page'] = array( |
|
| 219 | - 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ), |
|
| 218 | + $params['per_page'] = array( |
|
| 219 | + 'description' => __('Maximum number of items to be returned in result set.', 'woocommerce'), |
|
| 220 | 220 | 'type' => 'integer', |
| 221 | 221 | 'default' => 10, |
| 222 | 222 | 'minimum' => 1, |
@@ -224,27 +224,27 @@ discard block |
||
| 224 | 224 | 'sanitize_callback' => 'absint', |
| 225 | 225 | 'validate_callback' => 'rest_validate_request_arg', |
| 226 | 226 | ); |
| 227 | - $params['after'] = array( |
|
| 228 | - 'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ), |
|
| 227 | + $params['after'] = array( |
|
| 228 | + 'description' => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'), |
|
| 229 | 229 | 'type' => 'string', |
| 230 | 230 | 'format' => 'date-time', |
| 231 | 231 | 'validate_callback' => 'rest_validate_request_arg', |
| 232 | 232 | ); |
| 233 | - $params['before'] = array( |
|
| 234 | - 'description' => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ), |
|
| 233 | + $params['before'] = array( |
|
| 234 | + 'description' => __('Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce'), |
|
| 235 | 235 | 'type' => 'string', |
| 236 | 236 | 'format' => 'date-time', |
| 237 | 237 | 'validate_callback' => 'rest_validate_request_arg', |
| 238 | 238 | ); |
| 239 | - $params['order'] = array( |
|
| 240 | - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), |
|
| 239 | + $params['order'] = array( |
|
| 240 | + 'description' => __('Order sort attribute ascending or descending.', 'woocommerce'), |
|
| 241 | 241 | 'type' => 'string', |
| 242 | 242 | 'default' => 'desc', |
| 243 | - 'enum' => array( 'asc', 'desc' ), |
|
| 243 | + 'enum' => array('asc', 'desc'), |
|
| 244 | 244 | 'validate_callback' => 'rest_validate_request_arg', |
| 245 | 245 | ); |
| 246 | - $params['orderby'] = array( |
|
| 247 | - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), |
|
| 246 | + $params['orderby'] = array( |
|
| 247 | + 'description' => __('Sort collection by object attribute.', 'woocommerce'), |
|
| 248 | 248 | 'type' => 'string', |
| 249 | 249 | 'default' => 'category_id', |
| 250 | 250 | 'enum' => array( |
@@ -257,8 +257,8 @@ discard block |
||
| 257 | 257 | ), |
| 258 | 258 | 'validate_callback' => 'rest_validate_request_arg', |
| 259 | 259 | ); |
| 260 | - $params['interval'] = array( |
|
| 261 | - 'description' => __( 'Time interval to use for buckets in the returned data.', 'woocommerce' ), |
|
| 260 | + $params['interval'] = array( |
|
| 261 | + 'description' => __('Time interval to use for buckets in the returned data.', 'woocommerce'), |
|
| 262 | 262 | 'type' => 'string', |
| 263 | 263 | 'default' => 'week', |
| 264 | 264 | 'enum' => array( |
@@ -271,8 +271,8 @@ discard block |
||
| 271 | 271 | ), |
| 272 | 272 | 'validate_callback' => 'rest_validate_request_arg', |
| 273 | 273 | ); |
| 274 | - $params['status_is'] = array( |
|
| 275 | - 'description' => __( 'Limit result set to items that have the specified order status.', 'woocommerce' ), |
|
| 274 | + $params['status_is'] = array( |
|
| 275 | + 'description' => __('Limit result set to items that have the specified order status.', 'woocommerce'), |
|
| 276 | 276 | 'type' => 'array', |
| 277 | 277 | 'sanitize_callback' => 'wp_parse_slug_list', |
| 278 | 278 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | ), |
| 283 | 283 | ); |
| 284 | 284 | $params['status_is_not'] = array( |
| 285 | - 'description' => __( 'Limit result set to items that don\'t have the specified order status.', 'woocommerce' ), |
|
| 285 | + 'description' => __('Limit result set to items that don\'t have the specified order status.', 'woocommerce'), |
|
| 286 | 286 | 'type' => 'array', |
| 287 | 287 | 'sanitize_callback' => 'wp_parse_slug_list', |
| 288 | 288 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -291,8 +291,8 @@ discard block |
||
| 291 | 291 | 'type' => 'string', |
| 292 | 292 | ), |
| 293 | 293 | ); |
| 294 | - $params['categories'] = array( |
|
| 295 | - 'description' => __( 'Limit result set to all items that have the specified term assigned in the categories taxonomy.', 'woocommerce' ), |
|
| 294 | + $params['categories'] = array( |
|
| 295 | + 'description' => __('Limit result set to all items that have the specified term assigned in the categories taxonomy.', 'woocommerce'), |
|
| 296 | 296 | 'type' => 'array', |
| 297 | 297 | 'sanitize_callback' => 'wp_parse_id_list', |
| 298 | 298 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | ), |
| 302 | 302 | ); |
| 303 | 303 | $params['extended_info'] = array( |
| 304 | - 'description' => __( 'Add additional piece of info about each category to the report.', 'woocommerce' ), |
|
| 304 | + 'description' => __('Add additional piece of info about each category to the report.', 'woocommerce'), |
|
| 305 | 305 | 'type' => 'boolean', |
| 306 | 306 | 'default' => false, |
| 307 | 307 | 'sanitize_callback' => 'wc_string_to_bool', |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | namespace WooCommerce\RestApi\Version4\Controllers\Reports; |
| 11 | 11 | |
| 12 | -defined( 'ABSPATH' ) || exit; |
|
| 12 | +defined('ABSPATH') || exit; |
|
| 13 | 13 | |
| 14 | 14 | use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports; |
| 15 | 15 | |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * @param array $request Request array. |
| 32 | 32 | * @return array |
| 33 | 33 | */ |
| 34 | - protected function prepare_reports_query( $request ) { |
|
| 34 | + protected function prepare_reports_query($request) { |
|
| 35 | 35 | $args = array(); |
| 36 | 36 | $args['before'] = $request['before']; |
| 37 | 37 | $args['after'] = $request['after']; |
@@ -59,40 +59,40 @@ discard block |
||
| 59 | 59 | * @param \WP_REST_Request $request Request data. |
| 60 | 60 | * @return array|\WP_Error |
| 61 | 61 | */ |
| 62 | - public function get_items( $request ) { |
|
| 63 | - $query_args = $this->prepare_reports_query( $request ); |
|
| 64 | - $downloads_query = new \WC_Admin_Reports_Downloads_Stats_Query( $query_args ); |
|
| 62 | + public function get_items($request) { |
|
| 63 | + $query_args = $this->prepare_reports_query($request); |
|
| 64 | + $downloads_query = new \WC_Admin_Reports_Downloads_Stats_Query($query_args); |
|
| 65 | 65 | $report_data = $downloads_query->get_data(); |
| 66 | 66 | |
| 67 | 67 | $out_data = array( |
| 68 | - 'totals' => get_object_vars( $report_data->totals ), |
|
| 68 | + 'totals' => get_object_vars($report_data->totals), |
|
| 69 | 69 | 'intervals' => array(), |
| 70 | 70 | ); |
| 71 | 71 | |
| 72 | - foreach ( $report_data->intervals as $interval_data ) { |
|
| 73 | - $item = $this->prepare_item_for_response( $interval_data, $request ); |
|
| 74 | - $out_data['intervals'][] = $this->prepare_response_for_collection( $item ); |
|
| 72 | + foreach ($report_data->intervals as $interval_data) { |
|
| 73 | + $item = $this->prepare_item_for_response($interval_data, $request); |
|
| 74 | + $out_data['intervals'][] = $this->prepare_response_for_collection($item); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - $response = rest_ensure_response( $out_data ); |
|
| 78 | - $response->header( 'X-WP-Total', (int) $report_data->total ); |
|
| 79 | - $response->header( 'X-WP-TotalPages', (int) $report_data->pages ); |
|
| 77 | + $response = rest_ensure_response($out_data); |
|
| 78 | + $response->header('X-WP-Total', (int) $report_data->total); |
|
| 79 | + $response->header('X-WP-TotalPages', (int) $report_data->pages); |
|
| 80 | 80 | |
| 81 | 81 | $page = $report_data->page_no; |
| 82 | 82 | $max_pages = $report_data->pages; |
| 83 | - $base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) ); |
|
| 84 | - if ( $page > 1 ) { |
|
| 83 | + $base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base))); |
|
| 84 | + if ($page > 1) { |
|
| 85 | 85 | $prev_page = $page - 1; |
| 86 | - if ( $prev_page > $max_pages ) { |
|
| 86 | + if ($prev_page > $max_pages) { |
|
| 87 | 87 | $prev_page = $max_pages; |
| 88 | 88 | } |
| 89 | - $prev_link = add_query_arg( 'page', $prev_page, $base ); |
|
| 90 | - $response->link_header( 'prev', $prev_link ); |
|
| 89 | + $prev_link = add_query_arg('page', $prev_page, $base); |
|
| 90 | + $response->link_header('prev', $prev_link); |
|
| 91 | 91 | } |
| 92 | - if ( $max_pages > $page ) { |
|
| 92 | + if ($max_pages > $page) { |
|
| 93 | 93 | $next_page = $page + 1; |
| 94 | - $next_link = add_query_arg( 'page', $next_page, $base ); |
|
| 95 | - $response->link_header( 'next', $next_link ); |
|
| 94 | + $next_link = add_query_arg('page', $next_page, $base); |
|
| 95 | + $response->link_header('next', $next_link); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | return $response; |
@@ -105,15 +105,15 @@ discard block |
||
| 105 | 105 | * @param \WP_REST_Request $request Request object. |
| 106 | 106 | * @return \WP_REST_Response |
| 107 | 107 | */ |
| 108 | - public function prepare_item_for_response( $report, $request ) { |
|
| 108 | + public function prepare_item_for_response($report, $request) { |
|
| 109 | 109 | $data = $report; |
| 110 | 110 | |
| 111 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 112 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
| 113 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 111 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
| 112 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
| 113 | + $data = $this->filter_response_by_context($data, $context); |
|
| 114 | 114 | |
| 115 | 115 | // Wrap the data in a response object. |
| 116 | - $response = rest_ensure_response( $data ); |
|
| 116 | + $response = rest_ensure_response($data); |
|
| 117 | 117 | |
| 118 | 118 | /** |
| 119 | 119 | * Filter a report returned from the API. |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | * @param object $report The original report object. |
| 125 | 125 | * @param \WP_REST_Request $request Request used to generate the response. |
| 126 | 126 | */ |
| 127 | - return apply_filters( 'woocommerce_rest_prepare_report_downloads_stats', $response, $report, $request ); |
|
| 127 | + return apply_filters('woocommerce_rest_prepare_report_downloads_stats', $response, $report, $request); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /** |
@@ -135,9 +135,9 @@ discard block |
||
| 135 | 135 | public function get_item_schema() { |
| 136 | 136 | $totals = array( |
| 137 | 137 | 'download_count' => array( |
| 138 | - 'description' => __( 'Number of downloads.', 'woocommerce' ), |
|
| 138 | + 'description' => __('Number of downloads.', 'woocommerce'), |
|
| 139 | 139 | 'type' => 'number', |
| 140 | - 'context' => array( 'view', 'edit' ), |
|
| 140 | + 'context' => array('view', 'edit'), |
|
| 141 | 141 | 'readonly' => true, |
| 142 | 142 | 'indicator' => true, |
| 143 | 143 | ), |
@@ -149,55 +149,55 @@ discard block |
||
| 149 | 149 | 'type' => 'object', |
| 150 | 150 | 'properties' => array( |
| 151 | 151 | 'totals' => array( |
| 152 | - 'description' => __( 'Totals data.', 'woocommerce' ), |
|
| 152 | + 'description' => __('Totals data.', 'woocommerce'), |
|
| 153 | 153 | 'type' => 'object', |
| 154 | - 'context' => array( 'view', 'edit' ), |
|
| 154 | + 'context' => array('view', 'edit'), |
|
| 155 | 155 | 'readonly' => true, |
| 156 | 156 | 'properties' => $totals, |
| 157 | 157 | ), |
| 158 | 158 | 'intervals' => array( |
| 159 | - 'description' => __( 'Reports data grouped by intervals.', 'woocommerce' ), |
|
| 159 | + 'description' => __('Reports data grouped by intervals.', 'woocommerce'), |
|
| 160 | 160 | 'type' => 'array', |
| 161 | - 'context' => array( 'view', 'edit' ), |
|
| 161 | + 'context' => array('view', 'edit'), |
|
| 162 | 162 | 'readonly' => true, |
| 163 | 163 | 'items' => array( |
| 164 | 164 | 'type' => 'object', |
| 165 | 165 | 'properties' => array( |
| 166 | 166 | 'interval' => array( |
| 167 | - 'description' => __( 'Type of interval.', 'woocommerce' ), |
|
| 167 | + 'description' => __('Type of interval.', 'woocommerce'), |
|
| 168 | 168 | 'type' => 'string', |
| 169 | - 'context' => array( 'view', 'edit' ), |
|
| 169 | + 'context' => array('view', 'edit'), |
|
| 170 | 170 | 'readonly' => true, |
| 171 | - 'enum' => array( 'day', 'week', 'month', 'year' ), |
|
| 171 | + 'enum' => array('day', 'week', 'month', 'year'), |
|
| 172 | 172 | ), |
| 173 | 173 | 'date_start' => array( |
| 174 | - 'description' => __( "The date the report start, in the site's timezone.", 'woocommerce' ), |
|
| 174 | + 'description' => __("The date the report start, in the site's timezone.", 'woocommerce'), |
|
| 175 | 175 | 'type' => 'date-time', |
| 176 | - 'context' => array( 'view', 'edit' ), |
|
| 176 | + 'context' => array('view', 'edit'), |
|
| 177 | 177 | 'readonly' => true, |
| 178 | 178 | ), |
| 179 | 179 | 'date_start_gmt' => array( |
| 180 | - 'description' => __( 'The date the report start, as GMT.', 'woocommerce' ), |
|
| 180 | + 'description' => __('The date the report start, as GMT.', 'woocommerce'), |
|
| 181 | 181 | 'type' => 'date-time', |
| 182 | - 'context' => array( 'view', 'edit' ), |
|
| 182 | + 'context' => array('view', 'edit'), |
|
| 183 | 183 | 'readonly' => true, |
| 184 | 184 | ), |
| 185 | 185 | 'date_end' => array( |
| 186 | - 'description' => __( "The date the report end, in the site's timezone.", 'woocommerce' ), |
|
| 186 | + 'description' => __("The date the report end, in the site's timezone.", 'woocommerce'), |
|
| 187 | 187 | 'type' => 'date-time', |
| 188 | - 'context' => array( 'view', 'edit' ), |
|
| 188 | + 'context' => array('view', 'edit'), |
|
| 189 | 189 | 'readonly' => true, |
| 190 | 190 | ), |
| 191 | 191 | 'date_end_gmt' => array( |
| 192 | - 'description' => __( 'The date the report end, as GMT.', 'woocommerce' ), |
|
| 192 | + 'description' => __('The date the report end, as GMT.', 'woocommerce'), |
|
| 193 | 193 | 'type' => 'date-time', |
| 194 | - 'context' => array( 'view', 'edit' ), |
|
| 194 | + 'context' => array('view', 'edit'), |
|
| 195 | 195 | 'readonly' => true, |
| 196 | 196 | ), |
| 197 | 197 | 'subtotals' => array( |
| 198 | - 'description' => __( 'Interval subtotals.', 'woocommerce' ), |
|
| 198 | + 'description' => __('Interval subtotals.', 'woocommerce'), |
|
| 199 | 199 | 'type' => 'object', |
| 200 | - 'context' => array( 'view', 'edit' ), |
|
| 200 | + 'context' => array('view', 'edit'), |
|
| 201 | 201 | 'readonly' => true, |
| 202 | 202 | 'properties' => $totals, |
| 203 | 203 | ), |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | ), |
| 208 | 208 | ); |
| 209 | 209 | |
| 210 | - return $this->add_additional_fields_schema( $schema ); |
|
| 210 | + return $this->add_additional_fields_schema($schema); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | /** |
@@ -217,17 +217,17 @@ discard block |
||
| 217 | 217 | */ |
| 218 | 218 | public function get_collection_params() { |
| 219 | 219 | $params = array(); |
| 220 | - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); |
|
| 220 | + $params['context'] = $this->get_context_param(array('default' => 'view')); |
|
| 221 | 221 | $params['page'] = array( |
| 222 | - 'description' => __( 'Current page of the collection.', 'woocommerce' ), |
|
| 222 | + 'description' => __('Current page of the collection.', 'woocommerce'), |
|
| 223 | 223 | 'type' => 'integer', |
| 224 | 224 | 'default' => 1, |
| 225 | 225 | 'sanitize_callback' => 'absint', |
| 226 | 226 | 'validate_callback' => 'rest_validate_request_arg', |
| 227 | 227 | 'minimum' => 1, |
| 228 | 228 | ); |
| 229 | - $params['per_page'] = array( |
|
| 230 | - 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ), |
|
| 229 | + $params['per_page'] = array( |
|
| 230 | + 'description' => __('Maximum number of items to be returned in result set.', 'woocommerce'), |
|
| 231 | 231 | 'type' => 'integer', |
| 232 | 232 | 'default' => 10, |
| 233 | 233 | 'minimum' => 1, |
@@ -235,27 +235,27 @@ discard block |
||
| 235 | 235 | 'sanitize_callback' => 'absint', |
| 236 | 236 | 'validate_callback' => 'rest_validate_request_arg', |
| 237 | 237 | ); |
| 238 | - $params['after'] = array( |
|
| 239 | - 'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ), |
|
| 238 | + $params['after'] = array( |
|
| 239 | + 'description' => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'), |
|
| 240 | 240 | 'type' => 'string', |
| 241 | 241 | 'format' => 'date-time', |
| 242 | 242 | 'validate_callback' => 'rest_validate_request_arg', |
| 243 | 243 | ); |
| 244 | - $params['before'] = array( |
|
| 245 | - 'description' => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ), |
|
| 244 | + $params['before'] = array( |
|
| 245 | + 'description' => __('Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce'), |
|
| 246 | 246 | 'type' => 'string', |
| 247 | 247 | 'format' => 'date-time', |
| 248 | 248 | 'validate_callback' => 'rest_validate_request_arg', |
| 249 | 249 | ); |
| 250 | - $params['order'] = array( |
|
| 251 | - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), |
|
| 250 | + $params['order'] = array( |
|
| 251 | + 'description' => __('Order sort attribute ascending or descending.', 'woocommerce'), |
|
| 252 | 252 | 'type' => 'string', |
| 253 | 253 | 'default' => 'desc', |
| 254 | - 'enum' => array( 'asc', 'desc' ), |
|
| 254 | + 'enum' => array('asc', 'desc'), |
|
| 255 | 255 | 'validate_callback' => 'rest_validate_request_arg', |
| 256 | 256 | ); |
| 257 | - $params['orderby'] = array( |
|
| 258 | - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), |
|
| 257 | + $params['orderby'] = array( |
|
| 258 | + 'description' => __('Sort collection by object attribute.', 'woocommerce'), |
|
| 259 | 259 | 'type' => 'string', |
| 260 | 260 | 'default' => 'date', |
| 261 | 261 | 'enum' => array( |
@@ -264,8 +264,8 @@ discard block |
||
| 264 | 264 | ), |
| 265 | 265 | 'validate_callback' => 'rest_validate_request_arg', |
| 266 | 266 | ); |
| 267 | - $params['interval'] = array( |
|
| 268 | - 'description' => __( 'Time interval to use for buckets in the returned data.', 'woocommerce' ), |
|
| 267 | + $params['interval'] = array( |
|
| 268 | + 'description' => __('Time interval to use for buckets in the returned data.', 'woocommerce'), |
|
| 269 | 269 | 'type' => 'string', |
| 270 | 270 | 'default' => 'week', |
| 271 | 271 | 'enum' => array( |
@@ -278,8 +278,8 @@ discard block |
||
| 278 | 278 | ), |
| 279 | 279 | 'validate_callback' => 'rest_validate_request_arg', |
| 280 | 280 | ); |
| 281 | - $params['match'] = array( |
|
| 282 | - 'description' => __( 'Indicates whether all the conditions should be true for the resulting set, or if any one of them is sufficient. Match affects the following parameters: status_is, status_is_not, product_includes, product_excludes, coupon_includes, coupon_excludes, customer, categories', 'woocommerce' ), |
|
| 281 | + $params['match'] = array( |
|
| 282 | + 'description' => __('Indicates whether all the conditions should be true for the resulting set, or if any one of them is sufficient. Match affects the following parameters: status_is, status_is_not, product_includes, product_excludes, coupon_includes, coupon_excludes, customer, categories', 'woocommerce'), |
|
| 283 | 283 | 'type' => 'string', |
| 284 | 284 | 'default' => 'all', |
| 285 | 285 | 'enum' => array( |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | 'validate_callback' => 'rest_validate_request_arg', |
| 290 | 290 | ); |
| 291 | 291 | $params['product_includes'] = array( |
| 292 | - 'description' => __( 'Limit result set to items that have the specified product(s) assigned.', 'woocommerce' ), |
|
| 292 | + 'description' => __('Limit result set to items that have the specified product(s) assigned.', 'woocommerce'), |
|
| 293 | 293 | 'type' => 'array', |
| 294 | 294 | 'items' => array( |
| 295 | 295 | 'type' => 'integer', |
@@ -298,8 +298,8 @@ discard block |
||
| 298 | 298 | 'sanitize_callback' => 'wp_parse_id_list', |
| 299 | 299 | |
| 300 | 300 | ); |
| 301 | - $params['product_excludes'] = array( |
|
| 302 | - 'description' => __( 'Limit result set to items that don\'t have the specified product(s) assigned.', 'woocommerce' ), |
|
| 301 | + $params['product_excludes'] = array( |
|
| 302 | + 'description' => __('Limit result set to items that don\'t have the specified product(s) assigned.', 'woocommerce'), |
|
| 303 | 303 | 'type' => 'array', |
| 304 | 304 | 'items' => array( |
| 305 | 305 | 'type' => 'integer', |
@@ -307,8 +307,8 @@ discard block |
||
| 307 | 307 | 'default' => array(), |
| 308 | 308 | 'sanitize_callback' => 'wp_parse_id_list', |
| 309 | 309 | ); |
| 310 | - $params['order_includes'] = array( |
|
| 311 | - 'description' => __( 'Limit result set to items that have the specified order ids.', 'woocommerce' ), |
|
| 310 | + $params['order_includes'] = array( |
|
| 311 | + 'description' => __('Limit result set to items that have the specified order ids.', 'woocommerce'), |
|
| 312 | 312 | 'type' => 'array', |
| 313 | 313 | 'sanitize_callback' => 'wp_parse_id_list', |
| 314 | 314 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -316,8 +316,8 @@ discard block |
||
| 316 | 316 | 'type' => 'integer', |
| 317 | 317 | ), |
| 318 | 318 | ); |
| 319 | - $params['order_excludes'] = array( |
|
| 320 | - 'description' => __( 'Limit result set to items that don\'t have the specified order ids.', 'woocommerce' ), |
|
| 319 | + $params['order_excludes'] = array( |
|
| 320 | + 'description' => __('Limit result set to items that don\'t have the specified order ids.', 'woocommerce'), |
|
| 321 | 321 | 'type' => 'array', |
| 322 | 322 | 'sanitize_callback' => 'wp_parse_id_list', |
| 323 | 323 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -325,8 +325,8 @@ discard block |
||
| 325 | 325 | 'type' => 'integer', |
| 326 | 326 | ), |
| 327 | 327 | ); |
| 328 | - $params['customer_includes'] = array( |
|
| 329 | - 'description' => __( 'Limit response to objects that have the specified customer ids.', 'woocommerce' ), |
|
| 328 | + $params['customer_includes'] = array( |
|
| 329 | + 'description' => __('Limit response to objects that have the specified customer ids.', 'woocommerce'), |
|
| 330 | 330 | 'type' => 'array', |
| 331 | 331 | 'sanitize_callback' => 'wp_parse_id_list', |
| 332 | 332 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -334,8 +334,8 @@ discard block |
||
| 334 | 334 | 'type' => 'integer', |
| 335 | 335 | ), |
| 336 | 336 | ); |
| 337 | - $params['customer_excludes'] = array( |
|
| 338 | - 'description' => __( 'Limit response to objects that don\'t have the specified customer ids.', 'woocommerce' ), |
|
| 337 | + $params['customer_excludes'] = array( |
|
| 338 | + 'description' => __('Limit response to objects that don\'t have the specified customer ids.', 'woocommerce'), |
|
| 339 | 339 | 'type' => 'array', |
| 340 | 340 | 'sanitize_callback' => 'wp_parse_id_list', |
| 341 | 341 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | ), |
| 345 | 345 | ); |
| 346 | 346 | $params['ip_address_includes'] = array( |
| 347 | - 'description' => __( 'Limit response to objects that have a specified ip address.', 'woocommerce' ), |
|
| 347 | + 'description' => __('Limit response to objects that have a specified ip address.', 'woocommerce'), |
|
| 348 | 348 | 'type' => 'array', |
| 349 | 349 | 'validate_callback' => 'rest_validate_request_arg', |
| 350 | 350 | 'items' => array( |
@@ -353,7 +353,7 @@ discard block |
||
| 353 | 353 | ); |
| 354 | 354 | |
| 355 | 355 | $params['ip_address_excludes'] = array( |
| 356 | - 'description' => __( 'Limit response to objects that don\'t have a specified ip address.', 'woocommerce' ), |
|
| 356 | + 'description' => __('Limit response to objects that don\'t have a specified ip address.', 'woocommerce'), |
|
| 357 | 357 | 'type' => 'array', |
| 358 | 358 | 'validate_callback' => 'rest_validate_request_arg', |
| 359 | 359 | 'items' => array( |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | namespace WooCommerce\RestApi\Version4\Controllers\Reports; |
| 11 | 11 | |
| 12 | -defined( 'ABSPATH' ) || exit; |
|
| 12 | +defined('ABSPATH') || exit; |
|
| 13 | 13 | |
| 14 | 14 | use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports; |
| 15 | 15 | |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * @param array $request Request array. |
| 32 | 32 | * @return array |
| 33 | 33 | */ |
| 34 | - protected function prepare_reports_query( $request ) { |
|
| 34 | + protected function prepare_reports_query($request) { |
|
| 35 | 35 | $args = array(); |
| 36 | 36 | $args['before'] = $request['before']; |
| 37 | 37 | $args['after'] = $request['after']; |
@@ -52,44 +52,44 @@ discard block |
||
| 52 | 52 | * @param \WP_REST_Request $request Request data. |
| 53 | 53 | * @return array|\WP_Error |
| 54 | 54 | */ |
| 55 | - public function get_items( $request ) { |
|
| 56 | - $query_args = $this->prepare_reports_query( $request ); |
|
| 57 | - $coupons_query = new \WC_Admin_Reports_Coupons_Stats_Query( $query_args ); |
|
| 55 | + public function get_items($request) { |
|
| 56 | + $query_args = $this->prepare_reports_query($request); |
|
| 57 | + $coupons_query = new \WC_Admin_Reports_Coupons_Stats_Query($query_args); |
|
| 58 | 58 | try { |
| 59 | 59 | $report_data = $coupons_query->get_data(); |
| 60 | - } catch ( \WC_Admin_Reports_Parameter_Exception $e ) { |
|
| 61 | - return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
|
| 60 | + } catch (\WC_Admin_Reports_Parameter_Exception $e) { |
|
| 61 | + return new \WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode())); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | $out_data = array( |
| 65 | - 'totals' => get_object_vars( $report_data->totals ), |
|
| 65 | + 'totals' => get_object_vars($report_data->totals), |
|
| 66 | 66 | 'intervals' => array(), |
| 67 | 67 | ); |
| 68 | 68 | |
| 69 | - foreach ( $report_data->intervals as $interval_data ) { |
|
| 70 | - $item = $this->prepare_item_for_response( (object) $interval_data, $request ); |
|
| 71 | - $out_data['intervals'][] = $this->prepare_response_for_collection( $item ); |
|
| 69 | + foreach ($report_data->intervals as $interval_data) { |
|
| 70 | + $item = $this->prepare_item_for_response((object) $interval_data, $request); |
|
| 71 | + $out_data['intervals'][] = $this->prepare_response_for_collection($item); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - $response = rest_ensure_response( $out_data ); |
|
| 75 | - $response->header( 'X-WP-Total', (int) $report_data->total ); |
|
| 76 | - $response->header( 'X-WP-TotalPages', (int) $report_data->pages ); |
|
| 74 | + $response = rest_ensure_response($out_data); |
|
| 75 | + $response->header('X-WP-Total', (int) $report_data->total); |
|
| 76 | + $response->header('X-WP-TotalPages', (int) $report_data->pages); |
|
| 77 | 77 | |
| 78 | 78 | $page = $report_data->page_no; |
| 79 | 79 | $max_pages = $report_data->pages; |
| 80 | - $base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) ); |
|
| 81 | - if ( $page > 1 ) { |
|
| 80 | + $base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base))); |
|
| 81 | + if ($page > 1) { |
|
| 82 | 82 | $prev_page = $page - 1; |
| 83 | - if ( $prev_page > $max_pages ) { |
|
| 83 | + if ($prev_page > $max_pages) { |
|
| 84 | 84 | $prev_page = $max_pages; |
| 85 | 85 | } |
| 86 | - $prev_link = add_query_arg( 'page', $prev_page, $base ); |
|
| 87 | - $response->link_header( 'prev', $prev_link ); |
|
| 86 | + $prev_link = add_query_arg('page', $prev_page, $base); |
|
| 87 | + $response->link_header('prev', $prev_link); |
|
| 88 | 88 | } |
| 89 | - if ( $max_pages > $page ) { |
|
| 89 | + if ($max_pages > $page) { |
|
| 90 | 90 | $next_page = $page + 1; |
| 91 | - $next_link = add_query_arg( 'page', $next_page, $base ); |
|
| 92 | - $response->link_header( 'next', $next_link ); |
|
| 91 | + $next_link = add_query_arg('page', $next_page, $base); |
|
| 92 | + $response->link_header('next', $next_link); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | return $response; |
@@ -102,15 +102,15 @@ discard block |
||
| 102 | 102 | * @param \WP_REST_Request $request Request object. |
| 103 | 103 | * @return \WP_REST_Response |
| 104 | 104 | */ |
| 105 | - public function prepare_item_for_response( $report, $request ) { |
|
| 106 | - $data = get_object_vars( $report ); |
|
| 105 | + public function prepare_item_for_response($report, $request) { |
|
| 106 | + $data = get_object_vars($report); |
|
| 107 | 107 | |
| 108 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 109 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
| 110 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 108 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
| 109 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
| 110 | + $data = $this->filter_response_by_context($data, $context); |
|
| 111 | 111 | |
| 112 | 112 | // Wrap the data in a response object. |
| 113 | - $response = rest_ensure_response( $data ); |
|
| 113 | + $response = rest_ensure_response($data); |
|
| 114 | 114 | |
| 115 | 115 | /** |
| 116 | 116 | * Filter a report returned from the API. |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | * @param object $report The original report object. |
| 122 | 122 | * @param \WP_REST_Request $request Request used to generate the response. |
| 123 | 123 | */ |
| 124 | - return apply_filters( 'woocommerce_rest_prepare_report_coupons_stats', $response, $report, $request ); |
|
| 124 | + return apply_filters('woocommerce_rest_prepare_report_coupons_stats', $response, $report, $request); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -132,23 +132,23 @@ discard block |
||
| 132 | 132 | public function get_item_schema() { |
| 133 | 133 | $data_values = array( |
| 134 | 134 | 'amount' => array( |
| 135 | - 'description' => __( 'Net discount amount.', 'woocommerce' ), |
|
| 135 | + 'description' => __('Net discount amount.', 'woocommerce'), |
|
| 136 | 136 | 'type' => 'number', |
| 137 | - 'context' => array( 'view', 'edit' ), |
|
| 137 | + 'context' => array('view', 'edit'), |
|
| 138 | 138 | 'readonly' => true, |
| 139 | 139 | 'indicator' => true, |
| 140 | 140 | 'format' => 'currency', |
| 141 | 141 | ), |
| 142 | 142 | 'coupons_count' => array( |
| 143 | - 'description' => __( 'Amount of coupons.', 'woocommerce' ), |
|
| 143 | + 'description' => __('Amount of coupons.', 'woocommerce'), |
|
| 144 | 144 | 'type' => 'integer', |
| 145 | - 'context' => array( 'view', 'edit' ), |
|
| 145 | + 'context' => array('view', 'edit'), |
|
| 146 | 146 | 'readonly' => true, |
| 147 | 147 | ), |
| 148 | 148 | 'orders_count' => array( |
| 149 | - 'description' => __( 'Amount of discounted orders.', 'woocommerce' ), |
|
| 149 | + 'description' => __('Amount of discounted orders.', 'woocommerce'), |
|
| 150 | 150 | 'type' => 'integer', |
| 151 | - 'context' => array( 'view', 'edit' ), |
|
| 151 | + 'context' => array('view', 'edit'), |
|
| 152 | 152 | 'readonly' => true, |
| 153 | 153 | 'indicator' => true, |
| 154 | 154 | ), |
@@ -156,23 +156,23 @@ discard block |
||
| 156 | 156 | |
| 157 | 157 | $segments = array( |
| 158 | 158 | 'segments' => array( |
| 159 | - 'description' => __( 'Reports data grouped by segment condition.', 'woocommerce' ), |
|
| 159 | + 'description' => __('Reports data grouped by segment condition.', 'woocommerce'), |
|
| 160 | 160 | 'type' => 'array', |
| 161 | - 'context' => array( 'view', 'edit' ), |
|
| 161 | + 'context' => array('view', 'edit'), |
|
| 162 | 162 | 'readonly' => true, |
| 163 | 163 | 'items' => array( |
| 164 | 164 | 'type' => 'object', |
| 165 | 165 | 'properties' => array( |
| 166 | 166 | 'segment_id' => array( |
| 167 | - 'description' => __( 'Segment identificator.', 'woocommerce' ), |
|
| 167 | + 'description' => __('Segment identificator.', 'woocommerce'), |
|
| 168 | 168 | 'type' => 'integer', |
| 169 | - 'context' => array( 'view', 'edit' ), |
|
| 169 | + 'context' => array('view', 'edit'), |
|
| 170 | 170 | 'readonly' => true, |
| 171 | 171 | ), |
| 172 | 172 | 'subtotals' => array( |
| 173 | - 'description' => __( 'Interval subtotals.', 'woocommerce' ), |
|
| 173 | + 'description' => __('Interval subtotals.', 'woocommerce'), |
|
| 174 | 174 | 'type' => 'object', |
| 175 | - 'context' => array( 'view', 'edit' ), |
|
| 175 | + 'context' => array('view', 'edit'), |
|
| 176 | 176 | 'readonly' => true, |
| 177 | 177 | 'properties' => $data_values, |
| 178 | 178 | ), |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | ), |
| 182 | 182 | ); |
| 183 | 183 | |
| 184 | - $totals = array_merge( $data_values, $segments ); |
|
| 184 | + $totals = array_merge($data_values, $segments); |
|
| 185 | 185 | |
| 186 | 186 | $schema = array( |
| 187 | 187 | '$schema' => 'http://json-schema.org/draft-04/schema#', |
@@ -189,55 +189,55 @@ discard block |
||
| 189 | 189 | 'type' => 'object', |
| 190 | 190 | 'properties' => array( |
| 191 | 191 | 'totals' => array( |
| 192 | - 'description' => __( 'Totals data.', 'woocommerce' ), |
|
| 192 | + 'description' => __('Totals data.', 'woocommerce'), |
|
| 193 | 193 | 'type' => 'object', |
| 194 | - 'context' => array( 'view', 'edit' ), |
|
| 194 | + 'context' => array('view', 'edit'), |
|
| 195 | 195 | 'readonly' => true, |
| 196 | 196 | 'properties' => $totals, |
| 197 | 197 | ), |
| 198 | 198 | 'intervals' => array( |
| 199 | - 'description' => __( 'Reports data grouped by intervals.', 'woocommerce' ), |
|
| 199 | + 'description' => __('Reports data grouped by intervals.', 'woocommerce'), |
|
| 200 | 200 | 'type' => 'array', |
| 201 | - 'context' => array( 'view', 'edit' ), |
|
| 201 | + 'context' => array('view', 'edit'), |
|
| 202 | 202 | 'readonly' => true, |
| 203 | 203 | 'items' => array( |
| 204 | 204 | 'type' => 'object', |
| 205 | 205 | 'properties' => array( |
| 206 | 206 | 'interval' => array( |
| 207 | - 'description' => __( 'Type of interval.', 'woocommerce' ), |
|
| 207 | + 'description' => __('Type of interval.', 'woocommerce'), |
|
| 208 | 208 | 'type' => 'string', |
| 209 | - 'context' => array( 'view', 'edit' ), |
|
| 209 | + 'context' => array('view', 'edit'), |
|
| 210 | 210 | 'readonly' => true, |
| 211 | - 'enum' => array( 'day', 'week', 'month', 'year' ), |
|
| 211 | + 'enum' => array('day', 'week', 'month', 'year'), |
|
| 212 | 212 | ), |
| 213 | 213 | 'date_start' => array( |
| 214 | - 'description' => __( "The date the report start, in the site's timezone.", 'woocommerce' ), |
|
| 214 | + 'description' => __("The date the report start, in the site's timezone.", 'woocommerce'), |
|
| 215 | 215 | 'type' => 'date-time', |
| 216 | - 'context' => array( 'view', 'edit' ), |
|
| 216 | + 'context' => array('view', 'edit'), |
|
| 217 | 217 | 'readonly' => true, |
| 218 | 218 | ), |
| 219 | 219 | 'date_start_gmt' => array( |
| 220 | - 'description' => __( 'The date the report start, as GMT.', 'woocommerce' ), |
|
| 220 | + 'description' => __('The date the report start, as GMT.', 'woocommerce'), |
|
| 221 | 221 | 'type' => 'date-time', |
| 222 | - 'context' => array( 'view', 'edit' ), |
|
| 222 | + 'context' => array('view', 'edit'), |
|
| 223 | 223 | 'readonly' => true, |
| 224 | 224 | ), |
| 225 | 225 | 'date_end' => array( |
| 226 | - 'description' => __( "The date the report end, in the site's timezone.", 'woocommerce' ), |
|
| 226 | + 'description' => __("The date the report end, in the site's timezone.", 'woocommerce'), |
|
| 227 | 227 | 'type' => 'date-time', |
| 228 | - 'context' => array( 'view', 'edit' ), |
|
| 228 | + 'context' => array('view', 'edit'), |
|
| 229 | 229 | 'readonly' => true, |
| 230 | 230 | ), |
| 231 | 231 | 'date_end_gmt' => array( |
| 232 | - 'description' => __( 'The date the report end, as GMT.', 'woocommerce' ), |
|
| 232 | + 'description' => __('The date the report end, as GMT.', 'woocommerce'), |
|
| 233 | 233 | 'type' => 'date-time', |
| 234 | - 'context' => array( 'view', 'edit' ), |
|
| 234 | + 'context' => array('view', 'edit'), |
|
| 235 | 235 | 'readonly' => true, |
| 236 | 236 | ), |
| 237 | 237 | 'subtotals' => array( |
| 238 | - 'description' => __( 'Interval subtotals.', 'woocommerce' ), |
|
| 238 | + 'description' => __('Interval subtotals.', 'woocommerce'), |
|
| 239 | 239 | 'type' => 'object', |
| 240 | - 'context' => array( 'view', 'edit' ), |
|
| 240 | + 'context' => array('view', 'edit'), |
|
| 241 | 241 | 'readonly' => true, |
| 242 | 242 | 'properties' => $totals, |
| 243 | 243 | ), |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | ), |
| 248 | 248 | ); |
| 249 | 249 | |
| 250 | - return $this->add_additional_fields_schema( $schema ); |
|
| 250 | + return $this->add_additional_fields_schema($schema); |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
@@ -257,17 +257,17 @@ discard block |
||
| 257 | 257 | */ |
| 258 | 258 | public function get_collection_params() { |
| 259 | 259 | $params = array(); |
| 260 | - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); |
|
| 260 | + $params['context'] = $this->get_context_param(array('default' => 'view')); |
|
| 261 | 261 | $params['page'] = array( |
| 262 | - 'description' => __( 'Current page of the collection.', 'woocommerce' ), |
|
| 262 | + 'description' => __('Current page of the collection.', 'woocommerce'), |
|
| 263 | 263 | 'type' => 'integer', |
| 264 | 264 | 'default' => 1, |
| 265 | 265 | 'sanitize_callback' => 'absint', |
| 266 | 266 | 'validate_callback' => 'rest_validate_request_arg', |
| 267 | 267 | 'minimum' => 1, |
| 268 | 268 | ); |
| 269 | - $params['per_page'] = array( |
|
| 270 | - 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ), |
|
| 269 | + $params['per_page'] = array( |
|
| 270 | + 'description' => __('Maximum number of items to be returned in result set.', 'woocommerce'), |
|
| 271 | 271 | 'type' => 'integer', |
| 272 | 272 | 'default' => 10, |
| 273 | 273 | 'minimum' => 1, |
@@ -275,27 +275,27 @@ discard block |
||
| 275 | 275 | 'sanitize_callback' => 'absint', |
| 276 | 276 | 'validate_callback' => 'rest_validate_request_arg', |
| 277 | 277 | ); |
| 278 | - $params['after'] = array( |
|
| 279 | - 'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ), |
|
| 278 | + $params['after'] = array( |
|
| 279 | + 'description' => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'), |
|
| 280 | 280 | 'type' => 'string', |
| 281 | 281 | 'format' => 'date-time', |
| 282 | 282 | 'validate_callback' => 'rest_validate_request_arg', |
| 283 | 283 | ); |
| 284 | - $params['before'] = array( |
|
| 285 | - 'description' => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ), |
|
| 284 | + $params['before'] = array( |
|
| 285 | + 'description' => __('Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce'), |
|
| 286 | 286 | 'type' => 'string', |
| 287 | 287 | 'format' => 'date-time', |
| 288 | 288 | 'validate_callback' => 'rest_validate_request_arg', |
| 289 | 289 | ); |
| 290 | - $params['order'] = array( |
|
| 291 | - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), |
|
| 290 | + $params['order'] = array( |
|
| 291 | + 'description' => __('Order sort attribute ascending or descending.', 'woocommerce'), |
|
| 292 | 292 | 'type' => 'string', |
| 293 | 293 | 'default' => 'desc', |
| 294 | - 'enum' => array( 'asc', 'desc' ), |
|
| 294 | + 'enum' => array('asc', 'desc'), |
|
| 295 | 295 | 'validate_callback' => 'rest_validate_request_arg', |
| 296 | 296 | ); |
| 297 | - $params['orderby'] = array( |
|
| 298 | - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), |
|
| 297 | + $params['orderby'] = array( |
|
| 298 | + 'description' => __('Sort collection by object attribute.', 'woocommerce'), |
|
| 299 | 299 | 'type' => 'string', |
| 300 | 300 | 'default' => 'date', |
| 301 | 301 | 'enum' => array( |
@@ -306,8 +306,8 @@ discard block |
||
| 306 | 306 | ), |
| 307 | 307 | 'validate_callback' => 'rest_validate_request_arg', |
| 308 | 308 | ); |
| 309 | - $params['interval'] = array( |
|
| 310 | - 'description' => __( 'Time interval to use for buckets in the returned data.', 'woocommerce' ), |
|
| 309 | + $params['interval'] = array( |
|
| 310 | + 'description' => __('Time interval to use for buckets in the returned data.', 'woocommerce'), |
|
| 311 | 311 | 'type' => 'string', |
| 312 | 312 | 'default' => 'week', |
| 313 | 313 | 'enum' => array( |
@@ -320,8 +320,8 @@ discard block |
||
| 320 | 320 | ), |
| 321 | 321 | 'validate_callback' => 'rest_validate_request_arg', |
| 322 | 322 | ); |
| 323 | - $params['coupons'] = array( |
|
| 324 | - 'description' => __( 'Limit result set to coupons assigned specific coupon IDs.', 'woocommerce' ), |
|
| 323 | + $params['coupons'] = array( |
|
| 324 | + 'description' => __('Limit result set to coupons assigned specific coupon IDs.', 'woocommerce'), |
|
| 325 | 325 | 'type' => 'array', |
| 326 | 326 | 'sanitize_callback' => 'wp_parse_id_list', |
| 327 | 327 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -330,7 +330,7 @@ discard block |
||
| 330 | 330 | ), |
| 331 | 331 | ); |
| 332 | 332 | $params['segmentby'] = array( |
| 333 | - 'description' => __( 'Segment the response by additional constraint.', 'woocommerce' ), |
|
| 333 | + 'description' => __('Segment the response by additional constraint.', 'woocommerce'), |
|
| 334 | 334 | 'type' => 'string', |
| 335 | 335 | 'enum' => array( |
| 336 | 336 | 'product', |