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
Order.php
96 lines
| 1 | <?php |
| 2 | namespace Automattic\WooCommerce\StoreApi\Routes\V1; |
| 3 | |
| 4 | use Automattic\WooCommerce\StoreApi\SchemaController; |
| 5 | use Automattic\WooCommerce\StoreApi\Schemas\V1\AbstractSchema; |
| 6 | use Automattic\WooCommerce\StoreApi\Utilities\OrderController; |
| 7 | use Automattic\WooCommerce\StoreApi\Exceptions\RouteException; |
| 8 | use Automattic\WooCommerce\StoreApi\Utilities\OrderAuthorizationTrait; |
| 9 | |
| 10 | /** |
| 11 | * Order class. |
| 12 | */ |
| 13 | class Order extends AbstractRoute { |
| 14 | use OrderAuthorizationTrait; |
| 15 | |
| 16 | /** |
| 17 | * The route identifier. |
| 18 | * |
| 19 | * @var string |
| 20 | */ |
| 21 | const IDENTIFIER = 'order'; |
| 22 | |
| 23 | /** |
| 24 | * The schema item identifier. |
| 25 | * |
| 26 | * @var string |
| 27 | */ |
| 28 | const SCHEMA_TYPE = 'order'; |
| 29 | |
| 30 | /** |
| 31 | * Order controller class instance. |
| 32 | * |
| 33 | * @var OrderController |
| 34 | */ |
| 35 | protected $order_controller; |
| 36 | |
| 37 | /** |
| 38 | * Constructor. |
| 39 | * |
| 40 | * @param SchemaController $schema_controller Schema Controller instance. |
| 41 | * @param AbstractSchema $schema Schema class for this route. |
| 42 | */ |
| 43 | public function __construct( SchemaController $schema_controller, AbstractSchema $schema ) { |
| 44 | parent::__construct( $schema_controller, $schema ); |
| 45 | $this->order_controller = new OrderController(); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Get the path of this REST route. |
| 50 | * |
| 51 | * @return string |
| 52 | */ |
| 53 | public function get_path() { |
| 54 | return self::get_path_regex(); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Get the path of this rest route. |
| 59 | * |
| 60 | * @return string |
| 61 | */ |
| 62 | public static function get_path_regex() { |
| 63 | return '/order/(?P<id>[\d]+)'; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Get method arguments for this REST route. |
| 68 | * |
| 69 | * @return array An array of endpoints. |
| 70 | */ |
| 71 | public function get_args() { |
| 72 | return [ |
| 73 | [ |
| 74 | 'methods' => \WP_REST_Server::READABLE, |
| 75 | 'callback' => [ $this, 'get_response' ], |
| 76 | 'permission_callback' => [ $this, 'is_authorized' ], |
| 77 | 'args' => [ |
| 78 | 'context' => $this->get_context_param( [ 'default' => 'view' ] ), |
| 79 | ], |
| 80 | ], |
| 81 | 'schema' => [ $this->schema, 'get_public_item_schema' ], |
| 82 | ]; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Handle the request and return a valid response for this endpoint. |
| 87 | * |
| 88 | * @param \WP_REST_Request $request Request object. |
| 89 | * @return \WP_REST_Response |
| 90 | */ |
| 91 | protected function get_route_response( \WP_REST_Request $request ) { |
| 92 | $order_id = absint( $request['id'] ); |
| 93 | return rest_ensure_response( $this->schema->get_item_response( wc_get_order( $order_id ) ) ); |
| 94 | } |
| 95 | } |
| 96 |