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
ShopperLists.php
84 lines
| 1 | <?php |
| 2 | declare( strict_types = 1 ); |
| 3 | |
| 4 | namespace Automattic\WooCommerce\StoreApi\Routes\V1; |
| 5 | |
| 6 | use Automattic\WooCommerce\Internal\ShopperLists\ShopperList; |
| 7 | |
| 8 | /** |
| 9 | * GET /shopper-lists — collection of the current user's shopper lists. |
| 10 | */ |
| 11 | class ShopperLists extends AbstractRoute { |
| 12 | /** |
| 13 | * Route identifier. |
| 14 | * |
| 15 | * @var string |
| 16 | */ |
| 17 | const IDENTIFIER = 'shopper-lists'; |
| 18 | |
| 19 | /** |
| 20 | * Schema identifier this route uses. |
| 21 | * |
| 22 | * @var string |
| 23 | */ |
| 24 | const SCHEMA_TYPE = 'shopper-list'; |
| 25 | |
| 26 | /** |
| 27 | * Get the path of this REST route. |
| 28 | * |
| 29 | * @return string |
| 30 | */ |
| 31 | public function get_path() { |
| 32 | return self::get_path_regex(); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Get the path regex for this REST route. |
| 37 | * |
| 38 | * @return string |
| 39 | */ |
| 40 | public static function get_path_regex() { |
| 41 | return '/shopper-lists'; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Get method arguments for this REST route. |
| 46 | * |
| 47 | * @return array |
| 48 | */ |
| 49 | public function get_args() { |
| 50 | return array( |
| 51 | array( |
| 52 | 'methods' => \WP_REST_Server::READABLE, |
| 53 | 'callback' => array( $this, 'get_response' ), |
| 54 | 'permission_callback' => function () { |
| 55 | return is_user_logged_in(); |
| 56 | }, |
| 57 | 'args' => array( |
| 58 | 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
| 59 | ), |
| 60 | ), |
| 61 | 'schema' => array( $this->schema, 'get_public_item_schema' ), |
| 62 | ); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Return the lists for the current user. |
| 67 | * |
| 68 | * @param \WP_REST_Request $request Request object. |
| 69 | * |
| 70 | * @phpstan-param \WP_REST_Request<array<string, mixed>> $request |
| 71 | * |
| 72 | * @return \WP_REST_Response |
| 73 | */ |
| 74 | protected function get_route_response( \WP_REST_Request $request ) { |
| 75 | $response = array(); |
| 76 | |
| 77 | foreach ( ShopperList::get_all_for_user() as $list ) { |
| 78 | $response[] = $this->prepare_response_for_collection( $this->prepare_item_for_response( $list, $request ) ); |
| 79 | } |
| 80 | |
| 81 | return rest_ensure_response( $response ); |
| 82 | } |
| 83 | } |
| 84 |