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.
This commit is contained in:
vedanshujain 2020-06-02 19:21:32 +05:30
parent d560e73fce
commit 24baf27570
1 changed files with 19 additions and 0 deletions

View File

@ -217,6 +217,25 @@ class WC_REST_Products_Controller extends WC_REST_Products_V2_Controller {
return $args; 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. * Set product images.
* *