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rc.2 3.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / src / StoreApi / Routes / V1 / Products.php
woocommerce / src / StoreApi / Routes / V1 Last commit date
AI 1 year ago Agentic 4 months ago AbstractCartRoute.php 4 months ago AbstractRoute.php 3 months ago AbstractTermsRoute.php 4 months ago Batch.php 4 months ago Cart.php 1 year ago CartAddItem.php 4 months ago CartApplyCoupon.php 1 year ago CartCoupons.php 3 months ago CartCouponsByCode.php 1 year ago CartExtensions.php 2 years ago CartItems.php 2 years ago CartItemsByKey.php 2 years ago CartRemoveCoupon.php 1 year ago CartRemoveItem.php 4 months ago CartSelectShippingRate.php 5 months ago CartUpdateCustomer.php 4 months ago CartUpdateItem.php 4 months ago Checkout.php 1 month ago CheckoutOrder.php 1 year ago Order.php 7 months ago Patterns.php 1 year ago ProductAttributeTerms.php 1 month ago ProductAttributes.php 1 year ago ProductAttributesById.php 1 year ago ProductBrands.php 1 year ago ProductBrandsById.php 1 year ago ProductCategories.php 1 year ago ProductCategoriesById.php 1 year ago ProductCollectionData.php 11 months ago ProductReviews.php 4 months ago ProductTags.php 1 year ago Products.php 3 months ago ProductsById.php 3 months ago ProductsBySlug.php 3 months ago ShopperListItems.php 1 month ago ShopperListItemsByKey.php 1 month ago ShopperLists.php 1 month ago ShopperListsBySlug.php 1 month ago ShopperListsNonceCheck.php 1 month ago
Products.php
451 lines
1 <?php
2 declare( strict_types = 1 );
3
4 namespace Automattic\WooCommerce\StoreApi\Routes\V1;
5
6 use Automattic\WooCommerce\Enums\ProductType;
7 use Automattic\WooCommerce\Enums\CatalogVisibility;
8 use Automattic\WooCommerce\StoreApi\Utilities\Pagination;
9 use Automattic\WooCommerce\StoreApi\Utilities\ProductQuery;
10 use Automattic\WooCommerce\StoreApi\Utilities\ProductLinksTrait;
11
12 /**
13 * Products class.
14 */
15 class Products extends AbstractRoute {
16 use ProductLinksTrait;
17
18 /**
19 * The route identifier.
20 *
21 * @var string
22 */
23 const IDENTIFIER = 'products';
24
25 /**
26 * The routes schema.
27 *
28 * @var string
29 */
30 const SCHEMA_TYPE = 'product';
31
32 /**
33 * Get the path of this REST route.
34 *
35 * @return string
36 */
37 public function get_path() {
38 return self::get_path_regex();
39 }
40
41 /**
42 * Get the path of this rest route.
43 *
44 * @return string
45 */
46 public static function get_path_regex() {
47 return '/products';
48 }
49
50 /**
51 * Get method arguments for this REST route.
52 *
53 * @return array An array of endpoints.
54 */
55 public function get_args() {
56 return [
57 [
58 'methods' => \WP_REST_Server::READABLE,
59 'callback' => [ $this, 'get_response' ],
60 'permission_callback' => '__return_true',
61 'args' => $this->get_collection_params(),
62 'allow_batch' => [ 'v1' => true ],
63 ],
64 'schema' => [ $this->schema, 'get_public_item_schema' ],
65 ];
66 }
67
68 /**
69 * Get a collection of posts and add the post title filter option to \WP_Query.
70 *
71 * @param \WP_REST_Request $request Request object.
72 * @return \WP_REST_Response
73 */
74 protected function get_route_response( \WP_REST_Request $request ) {
75 $response = new \WP_REST_Response();
76 $product_query = new ProductQuery();
77
78 // Only get objects during GET requests.
79 if ( \WP_REST_Server::READABLE === $request->get_method() ) {
80 $query_results = $product_query->get_objects( $request );
81 $response_objects = [];
82
83 foreach ( $query_results['objects'] as $object ) {
84 $data = $this->prepare_item_for_response( $object, $request );
85 $response_objects[] = $this->prepare_response_for_collection( $data );
86 }
87
88 $response->set_data( $response_objects );
89 } else {
90 $query_results = $product_query->get_results( $request );
91 }
92
93 $response = ( new Pagination() )->add_headers( $response, $request, $query_results['total'], $query_results['pages'] );
94 $last_modified = $product_query->get_last_modified();
95 if ( $last_modified ) {
96 $response->header( 'Last-Modified', $last_modified );
97 }
98
99 return $response;
100 }
101
102 /**
103 * Get the query params for collections of products.
104 *
105 * @return array
106 */
107 public function get_collection_params() {
108 $params = [];
109 $params['context'] = $this->get_context_param();
110 $params['context']['default'] = 'view';
111
112 $params['page'] = array(
113 'description' => __( 'Current page of the collection.', 'woocommerce' ),
114 'type' => 'integer',
115 'default' => 1,
116 'sanitize_callback' => 'absint',
117 'validate_callback' => 'rest_validate_request_arg',
118 'minimum' => 1,
119 );
120
121 $params['per_page'] = array(
122 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ),
123 'type' => 'integer',
124 'default' => 10,
125 'minimum' => 1,
126 'maximum' => 100,
127 'sanitize_callback' => 'absint',
128 'validate_callback' => 'rest_validate_request_arg',
129 );
130
131 $params['search'] = array(
132 'description' => __( 'Limit results to those matching a string.', 'woocommerce' ),
133 'type' => 'string',
134 'sanitize_callback' => 'sanitize_text_field',
135 'validate_callback' => 'rest_validate_request_arg',
136 );
137
138 $params['slug'] = array(
139 'description' => __( 'Limit result set to products with specific slug(s). Use commas to separate.', 'woocommerce' ),
140 'type' => 'string',
141 'sanitize_callback' => 'sanitize_text_field',
142 'validate_callback' => 'rest_validate_request_arg',
143 );
144
145 $params['after'] = array(
146 'description' => __( 'Limit response to resources created after a given ISO8601 compliant date.', 'woocommerce' ),
147 'type' => 'string',
148 'format' => 'date-time',
149 'validate_callback' => 'rest_validate_request_arg',
150 );
151
152 $params['before'] = array(
153 'description' => __( 'Limit response to resources created before a given ISO8601 compliant date.', 'woocommerce' ),
154 'type' => 'string',
155 'format' => 'date-time',
156 'validate_callback' => 'rest_validate_request_arg',
157 );
158
159 $params['date_column'] = array(
160 'description' => __( 'When limiting response using after/before, which date column to compare against.', 'woocommerce' ),
161 'type' => 'string',
162 'default' => 'date',
163 'enum' => array(
164 'date',
165 'date_gmt',
166 'modified',
167 'modified_gmt',
168 ),
169 'validate_callback' => 'rest_validate_request_arg',
170 );
171
172 $params['exclude'] = array(
173 'description' => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ),
174 'type' => 'array',
175 'items' => array(
176 'type' => 'integer',
177 ),
178 'default' => [],
179 'sanitize_callback' => 'wp_parse_id_list',
180 );
181
182 $params['include'] = array(
183 'description' => __( 'Limit result set to specific ids.', 'woocommerce' ),
184 'type' => 'array',
185 'items' => array(
186 'type' => 'integer',
187 ),
188 'default' => [],
189 'sanitize_callback' => 'wp_parse_id_list',
190 );
191
192 $params['offset'] = array(
193 'description' => __( 'Offset the result set by a specific number of items.', 'woocommerce' ),
194 'type' => 'integer',
195 'sanitize_callback' => 'absint',
196 'validate_callback' => 'rest_validate_request_arg',
197 );
198
199 $params['order'] = array(
200 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ),
201 'type' => 'string',
202 'default' => 'desc',
203 'enum' => array( 'asc', 'desc' ),
204 'validate_callback' => 'rest_validate_request_arg',
205 );
206
207 $params['orderby'] = array(
208 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ),
209 'type' => 'string',
210 'default' => 'date',
211 'enum' => array(
212 'date',
213 'modified',
214 'id',
215 'include',
216 'title',
217 'slug',
218 'price',
219 'popularity',
220 'rating',
221 'menu_order',
222 'comment_count',
223 ),
224 'validate_callback' => 'rest_validate_request_arg',
225 );
226
227 $params['parent'] = array(
228 'description' => __( 'Limit result set to those of particular parent IDs.', 'woocommerce' ),
229 'type' => 'array',
230 'items' => array(
231 'type' => 'integer',
232 ),
233 'default' => [],
234 'sanitize_callback' => 'wp_parse_id_list',
235 );
236
237 $params['parent_exclude'] = array(
238 'description' => __( 'Limit result set to all items except those of a particular parent ID.', 'woocommerce' ),
239 'type' => 'array',
240 'items' => array(
241 'type' => 'integer',
242 ),
243 'sanitize_callback' => 'wp_parse_id_list',
244 'default' => [],
245 );
246
247 $params['type'] = array(
248 'description' => __( 'Limit result set to products assigned a specific type.', 'woocommerce' ),
249 'type' => 'string',
250 'enum' => array_merge( array_keys( wc_get_product_types() ), [ ProductType::VARIATION ] ),
251 'sanitize_callback' => 'sanitize_key',
252 'validate_callback' => 'rest_validate_request_arg',
253 );
254
255 $params['sku'] = array(
256 'description' => __( 'Limit result set to products with specific SKU(s). Use commas to separate.', 'woocommerce' ),
257 'type' => 'string',
258 'sanitize_callback' => 'sanitize_text_field',
259 'validate_callback' => 'rest_validate_request_arg',
260 );
261
262 $params['featured'] = array(
263 'description' => __( 'Limit result set to featured products.', 'woocommerce' ),
264 'type' => 'boolean',
265 'sanitize_callback' => 'wc_string_to_bool',
266 'validate_callback' => 'rest_validate_request_arg',
267 );
268
269 $params['category'] = array(
270 'description' => __( 'Limit result set to products assigned a set of category IDs or slugs, separated by commas.', 'woocommerce' ),
271 'type' => 'string',
272 'sanitize_callback' => 'wp_parse_list',
273 'validate_callback' => 'rest_validate_request_arg',
274 );
275
276 $params['category_operator'] = array(
277 'description' => __( 'Operator to compare product category terms.', 'woocommerce' ),
278 'type' => 'string',
279 'enum' => [ 'in', 'not_in', 'and' ],
280 'default' => 'in',
281 'sanitize_callback' => 'sanitize_key',
282 'validate_callback' => 'rest_validate_request_arg',
283 );
284
285 $params['brand'] = array(
286 'description' => __( 'Limit result set to products assigned a set of brand IDs or slugs, separated by commas.', 'woocommerce' ),
287 'type' => 'string',
288 'sanitize_callback' => 'wp_parse_list',
289 'validate_callback' => 'rest_validate_request_arg',
290 );
291
292 $params['brand_operator'] = array(
293 'description' => __( 'Operator to compare product brand terms.', 'woocommerce' ),
294 'type' => 'string',
295 'enum' => [ 'in', 'not_in', 'and' ],
296 'default' => 'in',
297 'sanitize_callback' => 'sanitize_key',
298 'validate_callback' => 'rest_validate_request_arg',
299 );
300
301 // If the $_REQUEST contains a taxonomy query, add it to the params and sanitize it.
302 foreach ( $_REQUEST as $param => $value ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
303 if ( ! is_string( $param ) ) {
304 continue;
305 }
306
307 if ( str_starts_with( $param, '_unstable_tax_' ) && ! str_ends_with( $param, '_operator' ) ) {
308 $params[ $param ] = array(
309 'description' => __( 'Limit result set to products assigned a set of taxonomies IDs or slugs, separated by commas.', 'woocommerce' ),
310 'type' => 'string',
311 'sanitize_callback' => 'wp_parse_list',
312 'validate_callback' => 'rest_validate_request_arg',
313 );
314 }
315 if ( str_starts_with( $param, '_unstable_tax_' ) && str_ends_with( $param, '_operator' ) ) {
316 $params[ $param ] = array(
317 'description' => __( 'Operator to compare product taxonomies terms.', 'woocommerce' ),
318 'type' => 'string',
319 'enum' => [ 'in', 'not_in', 'and' ],
320 'default' => 'in',
321 'sanitize_callback' => 'sanitize_key',
322 'validate_callback' => 'rest_validate_request_arg',
323 );
324 }
325 }
326
327 $params['tag'] = array(
328 'description' => __( 'Limit result set to products assigned a set of tag IDs or slugs, separated by commas.', 'woocommerce' ),
329 'type' => 'string',
330 'sanitize_callback' => 'wp_parse_list',
331 'validate_callback' => 'rest_validate_request_arg',
332 );
333
334 $params['tag_operator'] = array(
335 'description' => __( 'Operator to compare product tags.', 'woocommerce' ),
336 'type' => 'string',
337 'enum' => [ 'in', 'not_in', 'and' ],
338 'default' => 'in',
339 'sanitize_callback' => 'sanitize_key',
340 'validate_callback' => 'rest_validate_request_arg',
341 );
342
343 $params['on_sale'] = array(
344 'description' => __( 'Limit result set to products on sale.', 'woocommerce' ),
345 'type' => 'boolean',
346 'sanitize_callback' => 'wc_string_to_bool',
347 'validate_callback' => 'rest_validate_request_arg',
348 );
349
350 $params['min_price'] = array(
351 'description' => __( 'Limit result set to products based on a minimum price, provided using the smallest unit of the currency.', 'woocommerce' ),
352 'type' => 'string',
353 'sanitize_callback' => 'sanitize_text_field',
354 'validate_callback' => 'rest_validate_request_arg',
355 );
356
357 $params['max_price'] = array(
358 'description' => __( 'Limit result set to products based on a maximum price, provided using the smallest unit of the currency.', 'woocommerce' ),
359 'type' => 'string',
360 'sanitize_callback' => 'sanitize_text_field',
361 'validate_callback' => 'rest_validate_request_arg',
362 );
363
364 $params['stock_status'] = array(
365 'description' => __( 'Limit result set to products with specified stock status.', 'woocommerce' ),
366 'type' => 'array',
367 'items' => array(
368 'type' => 'string',
369 'enum' => array_keys( wc_get_product_stock_status_options() ),
370 'sanitize_callback' => 'sanitize_text_field',
371 'validate_callback' => 'rest_validate_request_arg',
372 ),
373 'default' => [],
374 );
375
376 $params['attributes'] = array(
377 'description' => __( 'Limit result set to products with selected global attributes.', 'woocommerce' ),
378 'type' => 'array',
379 'items' => array(
380 'type' => 'object',
381 'properties' => array(
382 'attribute' => array(
383 'description' => __( 'Attribute taxonomy name.', 'woocommerce' ),
384 'type' => 'string',
385 'sanitize_callback' => 'wc_sanitize_taxonomy_name',
386 ),
387 'term_id' => array(
388 'description' => __( 'List of attribute term IDs.', 'woocommerce' ),
389 'type' => 'array',
390 'items' => [
391 'type' => 'integer',
392 ],
393 'sanitize_callback' => 'wp_parse_id_list',
394 ),
395 'slug' => array(
396 'description' => __( 'List of attribute slug(s). If a term ID is provided, this will be ignored.', 'woocommerce' ),
397 'type' => 'array',
398 'items' => [
399 'type' => 'string',
400 ],
401 'sanitize_callback' => 'wp_parse_slug_list',
402 ),
403 'operator' => array(
404 'description' => __( 'Operator to compare product attribute terms.', 'woocommerce' ),
405 'type' => 'string',
406 'enum' => [ 'in', 'not_in', 'and' ],
407 ),
408 ),
409 ),
410 'default' => [],
411 );
412
413 $params['attribute_relation'] = array(
414 'description' => __( 'The logical relationship between attributes when filtering across multiple at once.', 'woocommerce' ),
415 'type' => 'string',
416 'enum' => [ 'in', 'and' ],
417 'default' => 'and',
418 'sanitize_callback' => 'sanitize_key',
419 'validate_callback' => 'rest_validate_request_arg',
420 );
421
422 $params['catalog_visibility'] = array(
423 'description' => __( 'Determines if hidden or visible catalog products are shown.', 'woocommerce' ),
424 'type' => 'string',
425 'enum' => array( 'any', CatalogVisibility::VISIBLE, CatalogVisibility::CATALOG, CatalogVisibility::SEARCH, CatalogVisibility::HIDDEN ),
426 'sanitize_callback' => 'sanitize_key',
427 'validate_callback' => 'rest_validate_request_arg',
428 );
429
430 $params['rating'] = array(
431 'description' => __( 'Limit result set to products with a certain average rating.', 'woocommerce' ),
432 'type' => 'array',
433 'items' => array(
434 'type' => 'integer',
435 'enum' => range( 1, 5 ),
436 ),
437 'default' => [],
438 'sanitize_callback' => 'wp_parse_id_list',
439 );
440
441 $params['related'] = array(
442 'description' => __( 'Limit result set to products related to a specific product ID.', 'woocommerce' ),
443 'type' => 'integer',
444 'sanitize_callback' => 'absint',
445 'validate_callback' => 'rest_validate_request_arg',
446 );
447
448 return $params;
449 }
450 }
451