Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update : support filter & pagination in product REST API v2 #2496

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions includes/REST/ProductControllerV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
[
'methods' => WP_REST_Server::READABLE,
'callback' => [ $this, 'get_items' ],
'args' => $this->get_product_collection_params(),
'permission_callback' => [ $this, 'get_product_permissions_check' ],
],
'schema' => [ $this, 'get_item_schema' ],
Expand Down Expand Up @@ -119,7 +118,7 @@
*
* @return array Query parameters.
*/
public function get_product_collection_params() {
public function get_collection_params() {
$params = parent::get_collection_params();

$params['author'] = array(
Expand Down Expand Up @@ -177,6 +176,24 @@
'validate_callback' => 'rest_validate_request_arg',
'required' => false,
);
$params['include'] = array(
'description' => __( 'Limit result set to specific ids.', 'dokan-lite' ),
'type' => 'array',
'items' => array(
'type' => 'integer',
),
'default' => array(),
'sanitize_callback' => 'wp_parse_id_list',
);
$params['exclude'] = array(
'description' => __( 'Ensure result set excludes specific IDs.', 'dokan-lite' ),
'type' => 'array',
'items' => array(
'type' => 'integer',
),
'default' => array(),
'sanitize_callback' => 'wp_parse_id_list',
);

return $params;
}
Expand Down Expand Up @@ -214,13 +231,13 @@
protected function prepare_objects_query( $request ) {
$args = parent::prepare_objects_query( $request );

$args = array_merge(
$args = array_merge(

Check warning on line 234 in includes/REST/ProductControllerV2.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found precision alignment of 1 spaces.

Check failure on line 234 in includes/REST/ProductControllerV2.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Opening statement of multi-line function call not indented correctly; expected 8 spaces but found 9
$args,

Check failure on line 235 in includes/REST/ProductControllerV2.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Multi-line function call not indented correctly; expected 13 spaces but found 12
array(

Check failure on line 236 in includes/REST/ProductControllerV2.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Multi-line function call not indented correctly; expected 13 spaces but found 12
'posts_per_page' => 10,
'paged' => 1,
'posts_per_page' => isset( $request['per_page'] ) ? $request['per_page'] : 10,
'paged' => isset( $request['page'] ) ? $request['page'] : 1,
'author' => dokan_get_current_user_id(),
'orderby' => 'post_date',
'orderby' => isset( $request['orderby'] ) ? $request['orderby'] : 'date',
'post_type' => 'product',
'date_query' => [],
'tax_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
Expand All @@ -231,8 +248,8 @@
'operator' => 'NOT IN',
),
),
)

Check failure on line 251 in includes/REST/ProductControllerV2.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Multi-line function call not indented correctly; expected 13 spaces but found 12
);

Check failure on line 252 in includes/REST/ProductControllerV2.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Multi-line function call not indented correctly; expected 9 spaces but found 8

$stock_statuses = apply_filters( 'dokan_product_stock_statuses', [ 'instock', 'outofstock' ] );
$product_types = apply_filters( 'dokan_product_types', [ 'simple' => __( 'Simple', 'dokan-lite' ) ] );
Expand Down
Loading