From 24baf2757042e6a773b9da58b1c56016e199d58c Mon Sep 17 00:00:00 2001 From: vedanshujain Date: Tue, 2 Jun 2020 19:21:32 +0530 Subject: [PATCH] Use core so that any future improvements need to be done in one place. Right now controller creates and executes its own query, whereas core already has a way to execute this. So it makes sense to use so that we would have to do any future improvement in one place. --- .../class-wc-rest-products-controller.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/includes/rest-api/Controllers/Version3/class-wc-rest-products-controller.php b/includes/rest-api/Controllers/Version3/class-wc-rest-products-controller.php index cd603447639..691024ba947 100644 --- a/includes/rest-api/Controllers/Version3/class-wc-rest-products-controller.php +++ b/includes/rest-api/Controllers/Version3/class-wc-rest-products-controller.php @@ -217,6 +217,25 @@ class WC_REST_Products_Controller extends WC_REST_Products_V2_Controller { return $args; } + /** + * Get products. + * + * @param array $query_args Query args. + * + * @return array Products. + */ + protected function get_objects( $query_args ) { + $query_args['paginate'] = true; + $query_args['return'] = 'objects'; + $results = wc_get_products( $query_args ); + + return array( + 'objects' => $results->products, + 'total' => $results->total, + 'pages' => $results->max_num_pages, + ); + } + /** * Set product images. *