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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 / Schemas / V1 / OrderSchema.php
woocommerce / src / StoreApi / Schemas / V1 Last commit date
AI 1 year ago Agentic 7 months ago AbstractAddressSchema.php 1 year ago AbstractSchema.php 1 month ago BatchSchema.php 2 years ago BillingAddressSchema.php 2 years ago CartCouponSchema.php 1 year ago CartExtensionsSchema.php 1 year ago CartFeeSchema.php 2 years ago CartItemSchema.php 1 month ago CartSchema.php 2 months ago CartShippingRateSchema.php 1 month ago CheckoutOrderSchema.php 2 years ago CheckoutSchema.php 1 month ago ErrorSchema.php 2 years ago ImageAttachmentSchema.php 3 months ago ItemSchema.php 11 months ago OrderCouponSchema.php 2 years ago OrderFeeSchema.php 2 years ago OrderItemSchema.php 1 month ago OrderSchema.php 2 months ago PatternsSchema.php 1 year ago ProductAttributeSchema.php 2 years ago ProductAttributeTermSchema.php 1 month ago ProductBrandSchema.php 1 year ago ProductCategorySchema.php 2 years ago ProductCollectionDataSchema.php 11 months ago ProductReviewSchema.php 2 years ago ProductSchema.php 1 month ago ShippingAddressSchema.php 2 years ago ShopperListItemSchema.php 1 month ago ShopperListSchema.php 1 month ago TermSchema.php 2 years ago
OrderSchema.php
393 lines
1 <?php
2 namespace Automattic\WooCommerce\StoreApi\Schemas\V1;
3
4 use Automattic\WooCommerce\Enums\OrderItemType;
5 use Automattic\WooCommerce\StoreApi\SchemaController;
6 use Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema;
7 use Automattic\WooCommerce\StoreApi\Utilities\OrderController;
8
9 /**
10 * OrderSchema class.
11 */
12 class OrderSchema extends AbstractSchema {
13 /**
14 * The schema item name.
15 *
16 * @var string
17 */
18 protected $title = 'order';
19
20 /**
21 * The schema item identifier.
22 *
23 * @var string
24 */
25 const IDENTIFIER = 'order';
26
27 /**
28 * Item schema instance.
29 *
30 * @var OrderItemSchema
31 */
32 public $item_schema;
33
34 /**
35 * Order controller class instance.
36 *
37 * @var OrderController
38 */
39 protected $order_controller;
40
41 /**
42 * Coupon schema instance.
43 *
44 * @var OrderCouponSchema
45 */
46 public $coupon_schema;
47
48 /**
49 * Product item schema instance representing cross-sell items.
50 *
51 * @var ProductSchema
52 */
53 public $cross_sells_item_schema;
54
55 /**
56 * Fee schema instance.
57 *
58 * @var OrderFeeSchema
59 */
60 public $fee_schema;
61
62 /**
63 * Shipping rates schema instance.
64 *
65 * @var CartShippingRateSchema
66 */
67 public $shipping_rate_schema;
68
69 /**
70 * Shipping address schema instance.
71 *
72 * @var ShippingAddressSchema
73 */
74 public $shipping_address_schema;
75
76 /**
77 * Billing address schema instance.
78 *
79 * @var BillingAddressSchema
80 */
81 public $billing_address_schema;
82
83 /**
84 * Error schema instance.
85 *
86 * @var ErrorSchema
87 */
88 public $error_schema;
89
90 /**
91 * Constructor.
92 *
93 * @param ExtendSchema $extend Rest Extending instance.
94 * @param SchemaController $controller Schema Controller instance.
95 */
96 public function __construct( ExtendSchema $extend, SchemaController $controller ) {
97 parent::__construct( $extend, $controller );
98 $this->item_schema = $this->controller->get( OrderItemSchema::IDENTIFIER );
99 $this->coupon_schema = $this->controller->get( OrderCouponSchema::IDENTIFIER );
100 $this->fee_schema = $this->controller->get( OrderFeeSchema::IDENTIFIER );
101 $this->shipping_rate_schema = $this->controller->get( CartShippingRateSchema::IDENTIFIER );
102 $this->shipping_address_schema = $this->controller->get( ShippingAddressSchema::IDENTIFIER );
103 $this->billing_address_schema = $this->controller->get( BillingAddressSchema::IDENTIFIER );
104 $this->error_schema = $this->controller->get( ErrorSchema::IDENTIFIER );
105 $this->order_controller = new OrderController();
106 }
107
108 /**
109 * Order schema properties.
110 *
111 * @return array
112 */
113 public function get_properties() {
114 return [
115 'id' => [
116 'description' => __( 'The order ID.', 'woocommerce' ),
117 'type' => 'integer',
118 'context' => [ 'view', 'edit' ],
119 'readonly' => true,
120 ],
121 'items' => [
122 'description' => __( 'Line items data.', 'woocommerce' ),
123 'type' => 'array',
124 'context' => [ 'view', 'edit' ],
125 'items' => [
126 'type' => 'object',
127 'properties' => $this->force_schema_readonly( $this->item_schema->get_properties() ),
128 ],
129 ],
130 'totals' => [
131 'description' => __( 'Order totals.', 'woocommerce' ),
132 'type' => 'object',
133 'context' => [ 'view', 'edit' ],
134 'readonly' => true,
135 'properties' => array_merge(
136 $this->get_store_currency_properties(),
137 [
138 'subtotal' => [
139 'description' => __( 'Subtotal of the order.', 'woocommerce' ),
140 'type' => 'string',
141 'context' => [ 'view', 'edit' ],
142 'readonly' => true,
143 ],
144 'total_discount' => [
145 'description' => __( 'Total discount from applied coupons.', 'woocommerce' ),
146 'type' => 'string',
147 'context' => [ 'view', 'edit' ],
148 'readonly' => true,
149 ],
150 'total_shipping' => [
151 'description' => __( 'Total price of shipping.', 'woocommerce' ),
152 'type' => [ 'string', 'null' ],
153 'context' => [ 'view', 'edit' ],
154 'readonly' => true,
155 ],
156 'total_fees' => [
157 'description' => __( 'Total price of any applied fees.', 'woocommerce' ),
158 'type' => 'string',
159 'context' => [ 'view', 'edit' ],
160 'readonly' => true,
161 ],
162 'total_tax' => [
163 'description' => __( 'Total tax applied to the order.', 'woocommerce' ),
164 'type' => 'string',
165 'context' => [ 'view', 'edit' ],
166 'readonly' => true,
167 ],
168 'total_refund' => [
169 'description' => __( 'Total refund applied to the order.', 'woocommerce' ),
170 'type' => 'string',
171 'context' => [ 'view', 'edit' ],
172 'readonly' => true,
173 ],
174 'total_price' => [
175 'description' => __( 'Total price the customer will pay.', 'woocommerce' ),
176 'type' => 'string',
177 'context' => [ 'view', 'edit' ],
178 'readonly' => true,
179 ],
180 'total_items' => [
181 'description' => __( 'Total price of items in the order.', 'woocommerce' ),
182 'type' => 'string',
183 'context' => [ 'view', 'edit' ],
184 'readonly' => true,
185 ],
186 'total_items_tax' => [
187 'description' => __( 'Total tax on items in the order.', 'woocommerce' ),
188 'type' => 'string',
189 'context' => [ 'view', 'edit' ],
190 'readonly' => true,
191 ],
192 'total_fees_tax' => [
193 'description' => __( 'Total tax on fees.', 'woocommerce' ),
194 'type' => 'string',
195 'context' => [ 'view', 'edit' ],
196 'readonly' => true,
197 ],
198 'total_discount_tax' => [
199 'description' => __( 'Total tax removed due to discount from applied coupons.', 'woocommerce' ),
200 'type' => 'string',
201 'context' => [ 'view', 'edit' ],
202 'readonly' => true,
203 ],
204 'total_shipping_tax' => [
205 'description' => __( 'Total tax on shipping. If shipping has not been calculated, a null response will be sent.', 'woocommerce' ),
206 'type' => [ 'string', 'null' ],
207 'context' => [ 'view', 'edit' ],
208 'readonly' => true,
209 ],
210 'tax_lines' => [
211 'description' => __( 'Lines of taxes applied to items and shipping.', 'woocommerce' ),
212 'type' => 'array',
213 'context' => [ 'view', 'edit' ],
214 'readonly' => true,
215 'items' => [
216 'type' => 'object',
217 'properties' => [
218 'name' => [
219 'description' => __( 'The name of the tax.', 'woocommerce' ),
220 'type' => 'string',
221 'context' => [ 'view', 'edit' ],
222 'readonly' => true,
223 ],
224 'price' => [
225 'description' => __( 'The amount of tax charged.', 'woocommerce' ),
226 'type' => 'string',
227 'context' => [ 'view', 'edit' ],
228 'readonly' => true,
229 ],
230 'rate' => [
231 'description' => __( 'The rate at which tax is applied.', 'woocommerce' ),
232 'type' => 'string',
233 'context' => [ 'view', 'edit' ],
234 'readonly' => true,
235 ],
236 ],
237 ],
238 ],
239 ]
240 ),
241 ],
242 'coupons' => [
243 'description' => __( 'List of applied cart coupons.', 'woocommerce' ),
244 'type' => 'array',
245 'context' => [ 'view', 'edit' ],
246 'readonly' => true,
247 'items' => [
248 'type' => 'object',
249 'properties' => $this->force_schema_readonly( $this->coupon_schema->get_properties() ),
250 ],
251 ],
252 'shipping_address' => [
253 'description' => __( 'Current set shipping address for the customer.', 'woocommerce' ),
254 'type' => 'object',
255 'context' => [ 'view', 'edit' ],
256 'readonly' => true,
257 'properties' => $this->force_schema_readonly( $this->shipping_address_schema->get_properties() ),
258 ],
259 'billing_address' => [
260 'description' => __( 'Current set billing address for the customer.', 'woocommerce' ),
261 'type' => 'object',
262 'context' => [ 'view', 'edit' ],
263 'readonly' => true,
264 'properties' => $this->force_schema_readonly( $this->billing_address_schema->get_properties() ),
265 ],
266 'needs_payment' => [
267 'description' => __( 'True if the cart needs payment. False for carts with only free products and no shipping costs.', 'woocommerce' ),
268 'type' => 'boolean',
269 'context' => [ 'view', 'edit' ],
270 'readonly' => true,
271 ],
272 'needs_shipping' => [
273 'description' => __( 'True if the cart needs shipping. False for carts with only digital goods or stores with no shipping methods set-up.', 'woocommerce' ),
274 'type' => 'boolean',
275 'context' => [ 'view', 'edit' ],
276 'readonly' => true,
277 ],
278 'errors' => [
279 'description' => __( 'List of cart item errors, for example, items in the cart which are out of stock.', 'woocommerce' ),
280 'type' => 'array',
281 'context' => [ 'view', 'edit' ],
282 'readonly' => true,
283 'items' => [
284 'type' => 'object',
285 'properties' => $this->force_schema_readonly( $this->error_schema->get_properties() ),
286 ],
287 ],
288 'payment_requirements' => [
289 'description' => __( 'List of required payment gateway features to process the order.', 'woocommerce' ),
290 'type' => 'array',
291 'context' => [ 'view', 'edit' ],
292 'readonly' => true,
293 ],
294 'status' => [
295 'description' => __( 'Status of the order.', 'woocommerce' ),
296 'type' => 'string',
297 'context' => [ 'view', 'edit' ],
298 'readonly' => true,
299 ],
300 ];
301 }
302
303 /**
304 * Get an order for response.
305 *
306 * @param \WC_Order $order Order instance.
307 * @return array
308 */
309 public function get_item_response( $order ) {
310 $order_id = $order->get_id();
311 $errors = [];
312 $failed_order_stock_error = $this->order_controller->get_failed_order_stock_error( $order_id );
313 if ( $failed_order_stock_error ) {
314 $errors[] = $failed_order_stock_error;
315 }
316
317 return [
318 'id' => $order_id,
319 'status' => $order->get_status(),
320 'items' => $this->get_item_responses_from_schema( $this->item_schema, $order->get_items() ),
321 'coupons' => $this->get_item_responses_from_schema( $this->coupon_schema, $order->get_items( OrderItemType::COUPON ) ),
322 'fees' => $this->get_item_responses_from_schema( $this->fee_schema, $order->get_items( OrderItemType::FEE ) ),
323 'totals' => (object) $this->prepare_currency_response( $this->get_totals( $order ) ),
324 'shipping_address' => (object) $this->shipping_address_schema->get_item_response( $order ),
325 'billing_address' => (object) $this->billing_address_schema->get_item_response( $order ),
326 'needs_payment' => $order->needs_payment(),
327 'needs_shipping' => $order->needs_shipping_address(),
328 'payment_requirements' => $this->extend->get_payment_requirements(),
329 'errors' => $errors,
330 ];
331 }
332
333 /**
334 * Get total data.
335 *
336 * @param \WC_Order $order Order instance.
337 * @return array
338 */
339 protected function get_totals( $order ) {
340 return [
341 'subtotal' => $this->prepare_money_response( $order->get_subtotal() ),
342 'total_discount' => $this->prepare_money_response( $order->get_total_discount() ),
343 'total_shipping' => $this->prepare_money_response( $order->get_total_shipping() ),
344 'total_fees' => $this->prepare_money_response( $order->get_total_fees() ),
345 'total_tax' => $this->prepare_money_response( $order->get_total_tax() ),
346 'total_refund' => $this->prepare_money_response( $order->get_total_refunded() ),
347 'total_price' => $this->prepare_money_response( $order->get_total() ),
348 'total_items' => $this->prepare_money_response(
349 array_sum(
350 array_map(
351 function( $item ) {
352 return $item->get_total();
353 },
354 array_values( $order->get_items( OrderItemType::LINE_ITEM ) )
355 )
356 )
357 ),
358 'total_items_tax' => $this->prepare_money_response(
359 array_sum(
360 array_map(
361 function( $item ) {
362 return $item->get_tax_total();
363 },
364 array_values( $order->get_items( OrderItemType::TAX ) )
365 )
366 )
367 ),
368 'total_fees_tax' => $this->prepare_money_response(
369 array_sum(
370 array_map(
371 function( $item ) {
372 return $item->get_total_tax();
373 },
374 array_values( $order->get_items( OrderItemType::FEE ) )
375 )
376 )
377 ),
378 'total_discount_tax' => $this->prepare_money_response( $order->get_discount_tax() ),
379 'total_shipping_tax' => $this->prepare_money_response( $order->get_shipping_tax() ),
380 'tax_lines' => array_map(
381 function( $item ) {
382 return [
383 'name' => $item->get_label(),
384 'price' => $this->prepare_money_response( $item->get_tax_total() ),
385 'rate' => strval( $item->get_rate_percent() ),
386 ];
387 },
388 array_values( $order->get_items( OrderItemType::TAX ) )
389 ),
390 ];
391 }
392 }
393