Passed
Push — main ( aaef5c...e4c121 )
by TARIQ
71:39
created
packages/woocommerce-blocks/src/StoreApi/Schemas/V1/CartItemSchema.php 2 patches
Indentation   +450 added lines, -450 removed lines patch added patch discarded remove patch
@@ -8,470 +8,470 @@
 block discarded – undo
8 8
  * CartItemSchema class.
9 9
  */
10 10
 class CartItemSchema extends ProductSchema {
11
-	use DraftOrderTrait;
11
+    use DraftOrderTrait;
12 12
 
13
-	/**
14
-	 * The schema item name.
15
-	 *
16
-	 * @var string
17
-	 */
18
-	protected $title = 'cart_item';
13
+    /**
14
+     * The schema item name.
15
+     *
16
+     * @var string
17
+     */
18
+    protected $title = 'cart_item';
19 19
 
20
-	/**
21
-	 * The schema item identifier.
22
-	 *
23
-	 * @var string
24
-	 */
25
-	const IDENTIFIER = 'cart-item';
20
+    /**
21
+     * The schema item identifier.
22
+     *
23
+     * @var string
24
+     */
25
+    const IDENTIFIER = 'cart-item';
26 26
 
27
-	/**
28
-	 * Cart schema properties.
29
-	 *
30
-	 * @return array
31
-	 */
32
-	public function get_properties() {
33
-		return [
34
-			'key'                  => [
35
-				'description' => __( 'Unique identifier for the item within the cart.', 'woocommerce' ),
36
-				'type'        => 'string',
37
-				'context'     => [ 'view', 'edit' ],
38
-				'readonly'    => true,
39
-			],
40
-			'id'                   => [
41
-				'description' => __( 'The cart item product or variation ID.', 'woocommerce' ),
42
-				'type'        => 'integer',
43
-				'context'     => [ 'view', 'edit' ],
44
-				'readonly'    => true,
45
-			],
46
-			'quantity'             => [
47
-				'description' => __( 'Quantity of this item in the cart.', 'woocommerce' ),
48
-				'type'        => 'number',
49
-				'context'     => [ 'view', 'edit' ],
50
-				'readonly'    => true,
51
-			],
52
-			'quantity_limits'      => [
53
-				'description' => __( 'How the quantity of this item should be controlled, for example, any limits in place.', 'woocommerce' ),
54
-				'type'        => 'object',
55
-				'context'     => [ 'view', 'edit' ],
56
-				'readonly'    => true,
57
-				'properties'  => [
58
-					'minimum'     => [
59
-						'description' => __( 'The minimum quantity allowed in the cart for this line item.', 'woocommerce' ),
60
-						'type'        => 'integer',
61
-						'context'     => [ 'view', 'edit' ],
62
-						'readonly'    => true,
63
-					],
64
-					'maximum'     => [
65
-						'description' => __( 'The maximum quantity allowed in the cart for this line item.', 'woocommerce' ),
66
-						'type'        => 'integer',
67
-						'context'     => [ 'view', 'edit' ],
68
-						'readonly'    => true,
69
-					],
70
-					'multiple_of' => [
71
-						'description' => __( 'The amount that quantities increment by. Quantity must be an multiple of this value.', 'woocommerce' ),
72
-						'type'        => 'integer',
73
-						'context'     => [ 'view', 'edit' ],
74
-						'readonly'    => true,
75
-						'default'     => 1,
76
-					],
77
-					'editable'    => [
78
-						'description' => __( 'If the quantity in the cart is editable or fixed.', 'woocommerce' ),
79
-						'type'        => 'boolean',
80
-						'context'     => [ 'view', 'edit' ],
81
-						'readonly'    => true,
82
-						'default'     => true,
83
-					],
84
-				],
85
-			],
86
-			'name'                 => [
87
-				'description' => __( 'Product name.', 'woocommerce' ),
88
-				'type'        => 'string',
89
-				'context'     => [ 'view', 'edit' ],
90
-				'readonly'    => true,
91
-			],
92
-			'short_description'    => [
93
-				'description' => __( 'Product short description in HTML format.', 'woocommerce' ),
94
-				'type'        => 'string',
95
-				'context'     => [ 'view', 'edit' ],
96
-				'readonly'    => true,
97
-			],
98
-			'description'          => [
99
-				'description' => __( 'Product full description in HTML format.', 'woocommerce' ),
100
-				'type'        => 'string',
101
-				'context'     => [ 'view', 'edit' ],
102
-				'readonly'    => true,
103
-			],
104
-			'sku'                  => [
105
-				'description' => __( 'Stock keeping unit, if applicable.', 'woocommerce' ),
106
-				'type'        => 'string',
107
-				'context'     => [ 'view', 'edit' ],
108
-				'readonly'    => true,
109
-			],
110
-			'low_stock_remaining'  => [
111
-				'description' => __( 'Quantity left in stock if stock is low, or null if not applicable.', 'woocommerce' ),
112
-				'type'        => [ 'integer', 'null' ],
113
-				'context'     => [ 'view', 'edit' ],
114
-				'readonly'    => true,
115
-			],
116
-			'backorders_allowed'   => [
117
-				'description' => __( 'True if backorders are allowed past stock availability.', 'woocommerce' ),
118
-				'type'        => [ 'boolean' ],
119
-				'context'     => [ 'view', 'edit' ],
120
-				'readonly'    => true,
121
-			],
122
-			'show_backorder_badge' => [
123
-				'description' => __( 'True if the product is on backorder.', 'woocommerce' ),
124
-				'type'        => [ 'boolean' ],
125
-				'context'     => [ 'view', 'edit' ],
126
-				'readonly'    => true,
127
-			],
128
-			'sold_individually'    => [
129
-				'description' => __( 'If true, only one item of this product is allowed for purchase in a single order.', 'woocommerce' ),
130
-				'type'        => 'boolean',
131
-				'context'     => [ 'view', 'edit' ],
132
-				'readonly'    => true,
133
-			],
134
-			'permalink'            => [
135
-				'description' => __( 'Product URL.', 'woocommerce' ),
136
-				'type'        => 'string',
137
-				'format'      => 'uri',
138
-				'context'     => [ 'view', 'edit' ],
139
-				'readonly'    => true,
140
-			],
141
-			'images'               => [
142
-				'description' => __( 'List of images.', 'woocommerce' ),
143
-				'type'        => 'array',
144
-				'context'     => [ 'view', 'edit' ],
145
-				'readonly'    => true,
146
-				'items'       => [
147
-					'type'       => 'object',
148
-					'properties' => $this->image_attachment_schema->get_properties(),
149
-				],
150
-			],
151
-			'variation'            => [
152
-				'description' => __( 'Chosen attributes (for variations).', 'woocommerce' ),
153
-				'type'        => 'array',
154
-				'context'     => [ 'view', 'edit' ],
155
-				'readonly'    => true,
156
-				'items'       => [
157
-					'type'       => 'object',
158
-					'properties' => [
159
-						'attribute' => [
160
-							'description' => __( 'Variation attribute name.', 'woocommerce' ),
161
-							'type'        => 'string',
162
-							'context'     => [ 'view', 'edit' ],
163
-							'readonly'    => true,
164
-						],
165
-						'value'     => [
166
-							'description' => __( 'Variation attribute value.', 'woocommerce' ),
167
-							'type'        => 'string',
168
-							'context'     => [ 'view', 'edit' ],
169
-							'readonly'    => true,
170
-						],
171
-					],
172
-				],
173
-			],
174
-			'item_data'            => [
175
-				'description' => __( 'Metadata related to the cart item', 'woocommerce' ),
176
-				'type'        => 'array',
177
-				'context'     => [ 'view', 'edit' ],
178
-				'readonly'    => true,
179
-				'items'       => [
180
-					'type'       => 'object',
181
-					'properties' => [
182
-						'name'    => [
183
-							'description' => __( 'Name of the metadata.', 'woocommerce' ),
184
-							'type'        => 'string',
185
-							'context'     => [ 'view', 'edit' ],
186
-							'readonly'    => true,
187
-						],
188
-						'value'   => [
189
-							'description' => __( 'Value of the metadata.', 'woocommerce' ),
190
-							'type'        => 'string',
191
-							'context'     => [ 'view', 'edit' ],
192
-							'readonly'    => true,
193
-						],
194
-						'display' => [
195
-							'description' => __( 'Optionally, how the metadata value should be displayed to the user.', 'woocommerce' ),
196
-							'type'        => 'string',
197
-							'context'     => [ 'view', 'edit' ],
198
-							'readonly'    => true,
199
-						],
200
-					],
201
-				],
202
-			],
203
-			'prices'               => [
204
-				'description' => __( 'Price data for the product in the current line item, including or excluding taxes based on the "display prices during cart and checkout" setting. Provided using the smallest unit of the currency.', 'woocommerce' ),
205
-				'type'        => 'object',
206
-				'context'     => [ 'view', 'edit' ],
207
-				'readonly'    => true,
208
-				'properties'  => array_merge(
209
-					$this->get_store_currency_properties(),
210
-					[
211
-						'price'         => [
212
-							'description' => __( 'Current product price.', 'woocommerce' ),
213
-							'type'        => 'string',
214
-							'context'     => [ 'view', 'edit' ],
215
-							'readonly'    => true,
216
-						],
217
-						'regular_price' => [
218
-							'description' => __( 'Regular product price.', 'woocommerce' ),
219
-							'type'        => 'string',
220
-							'context'     => [ 'view', 'edit' ],
221
-							'readonly'    => true,
222
-						],
223
-						'sale_price'    => [
224
-							'description' => __( 'Sale product price, if applicable.', 'woocommerce' ),
225
-							'type'        => 'string',
226
-							'context'     => [ 'view', 'edit' ],
227
-							'readonly'    => true,
228
-						],
229
-						'price_range'   => [
230
-							'description' => __( 'Price range, if applicable.', 'woocommerce' ),
231
-							'type'        => [ 'object', 'null' ],
232
-							'context'     => [ 'view', 'edit' ],
233
-							'readonly'    => true,
234
-							'properties'  => [
235
-								'min_amount' => [
236
-									'description' => __( 'Price amount.', 'woocommerce' ),
237
-									'type'        => 'string',
238
-									'context'     => [ 'view', 'edit' ],
239
-									'readonly'    => true,
240
-								],
241
-								'max_amount' => [
242
-									'description' => __( 'Price amount.', 'woocommerce' ),
243
-									'type'        => 'string',
244
-									'context'     => [ 'view', 'edit' ],
245
-									'readonly'    => true,
246
-								],
247
-							],
248
-						],
249
-						'raw_prices'    => [
250
-							'description' => __( 'Raw unrounded product prices used in calculations. Provided using a higher unit of precision than the currency.', 'woocommerce' ),
251
-							'type'        => [ 'object', 'null' ],
252
-							'context'     => [ 'view', 'edit' ],
253
-							'readonly'    => true,
254
-							'properties'  => [
255
-								'precision'     => [
256
-									'description' => __( 'Decimal precision of the returned prices.', 'woocommerce' ),
257
-									'type'        => 'integer',
258
-									'context'     => [ 'view', 'edit' ],
259
-									'readonly'    => true,
260
-								],
261
-								'price'         => [
262
-									'description' => __( 'Current product price.', 'woocommerce' ),
263
-									'type'        => 'string',
264
-									'context'     => [ 'view', 'edit' ],
265
-									'readonly'    => true,
266
-								],
267
-								'regular_price' => [
268
-									'description' => __( 'Regular product price.', 'woocommerce' ),
269
-									'type'        => 'string',
270
-									'context'     => [ 'view', 'edit' ],
271
-									'readonly'    => true,
272
-								],
273
-								'sale_price'    => [
274
-									'description' => __( 'Sale product price, if applicable.', 'woocommerce' ),
275
-									'type'        => 'string',
276
-									'context'     => [ 'view', 'edit' ],
277
-									'readonly'    => true,
278
-								],
279
-							],
280
-						],
281
-					]
282
-				),
283
-			],
284
-			'totals'               => [
285
-				'description' => __( 'Item total amounts provided using the smallest unit of the currency.', 'woocommerce' ),
286
-				'type'        => 'object',
287
-				'context'     => [ 'view', 'edit' ],
288
-				'readonly'    => true,
289
-				'properties'  => array_merge(
290
-					$this->get_store_currency_properties(),
291
-					[
292
-						'line_subtotal'     => [
293
-							'description' => __( 'Line subtotal (the price of the product before coupon discounts have been applied).', 'woocommerce' ),
294
-							'type'        => 'string',
295
-							'context'     => [ 'view', 'edit' ],
296
-							'readonly'    => true,
297
-						],
298
-						'line_subtotal_tax' => [
299
-							'description' => __( 'Line subtotal tax.', 'woocommerce' ),
300
-							'type'        => 'string',
301
-							'context'     => [ 'view', 'edit' ],
302
-							'readonly'    => true,
303
-						],
304
-						'line_total'        => [
305
-							'description' => __( 'Line total (the price of the product after coupon discounts have been applied).', 'woocommerce' ),
306
-							'type'        => 'string',
307
-							'context'     => [ 'view', 'edit' ],
308
-							'readonly'    => true,
309
-						],
310
-						'line_total_tax'    => [
311
-							'description' => __( 'Line total tax.', 'woocommerce' ),
312
-							'type'        => 'string',
313
-							'context'     => [ 'view', 'edit' ],
314
-							'readonly'    => true,
315
-						],
316
-					]
317
-				),
318
-			],
319
-			'catalog_visibility'   => [
320
-				'description' => __( 'Whether the product is visible in the catalog', 'woocommerce' ),
321
-				'type'        => 'string',
322
-				'context'     => [ 'view', 'edit' ],
323
-				'readonly'    => true,
324
-			],
325
-			self::EXTENDING_KEY    => $this->get_extended_schema( self::IDENTIFIER ),
326
-		];
327
-	}
27
+    /**
28
+     * Cart schema properties.
29
+     *
30
+     * @return array
31
+     */
32
+    public function get_properties() {
33
+        return [
34
+            'key'                  => [
35
+                'description' => __( 'Unique identifier for the item within the cart.', 'woocommerce' ),
36
+                'type'        => 'string',
37
+                'context'     => [ 'view', 'edit' ],
38
+                'readonly'    => true,
39
+            ],
40
+            'id'                   => [
41
+                'description' => __( 'The cart item product or variation ID.', 'woocommerce' ),
42
+                'type'        => 'integer',
43
+                'context'     => [ 'view', 'edit' ],
44
+                'readonly'    => true,
45
+            ],
46
+            'quantity'             => [
47
+                'description' => __( 'Quantity of this item in the cart.', 'woocommerce' ),
48
+                'type'        => 'number',
49
+                'context'     => [ 'view', 'edit' ],
50
+                'readonly'    => true,
51
+            ],
52
+            'quantity_limits'      => [
53
+                'description' => __( 'How the quantity of this item should be controlled, for example, any limits in place.', 'woocommerce' ),
54
+                'type'        => 'object',
55
+                'context'     => [ 'view', 'edit' ],
56
+                'readonly'    => true,
57
+                'properties'  => [
58
+                    'minimum'     => [
59
+                        'description' => __( 'The minimum quantity allowed in the cart for this line item.', 'woocommerce' ),
60
+                        'type'        => 'integer',
61
+                        'context'     => [ 'view', 'edit' ],
62
+                        'readonly'    => true,
63
+                    ],
64
+                    'maximum'     => [
65
+                        'description' => __( 'The maximum quantity allowed in the cart for this line item.', 'woocommerce' ),
66
+                        'type'        => 'integer',
67
+                        'context'     => [ 'view', 'edit' ],
68
+                        'readonly'    => true,
69
+                    ],
70
+                    'multiple_of' => [
71
+                        'description' => __( 'The amount that quantities increment by. Quantity must be an multiple of this value.', 'woocommerce' ),
72
+                        'type'        => 'integer',
73
+                        'context'     => [ 'view', 'edit' ],
74
+                        'readonly'    => true,
75
+                        'default'     => 1,
76
+                    ],
77
+                    'editable'    => [
78
+                        'description' => __( 'If the quantity in the cart is editable or fixed.', 'woocommerce' ),
79
+                        'type'        => 'boolean',
80
+                        'context'     => [ 'view', 'edit' ],
81
+                        'readonly'    => true,
82
+                        'default'     => true,
83
+                    ],
84
+                ],
85
+            ],
86
+            'name'                 => [
87
+                'description' => __( 'Product name.', 'woocommerce' ),
88
+                'type'        => 'string',
89
+                'context'     => [ 'view', 'edit' ],
90
+                'readonly'    => true,
91
+            ],
92
+            'short_description'    => [
93
+                'description' => __( 'Product short description in HTML format.', 'woocommerce' ),
94
+                'type'        => 'string',
95
+                'context'     => [ 'view', 'edit' ],
96
+                'readonly'    => true,
97
+            ],
98
+            'description'          => [
99
+                'description' => __( 'Product full description in HTML format.', 'woocommerce' ),
100
+                'type'        => 'string',
101
+                'context'     => [ 'view', 'edit' ],
102
+                'readonly'    => true,
103
+            ],
104
+            'sku'                  => [
105
+                'description' => __( 'Stock keeping unit, if applicable.', 'woocommerce' ),
106
+                'type'        => 'string',
107
+                'context'     => [ 'view', 'edit' ],
108
+                'readonly'    => true,
109
+            ],
110
+            'low_stock_remaining'  => [
111
+                'description' => __( 'Quantity left in stock if stock is low, or null if not applicable.', 'woocommerce' ),
112
+                'type'        => [ 'integer', 'null' ],
113
+                'context'     => [ 'view', 'edit' ],
114
+                'readonly'    => true,
115
+            ],
116
+            'backorders_allowed'   => [
117
+                'description' => __( 'True if backorders are allowed past stock availability.', 'woocommerce' ),
118
+                'type'        => [ 'boolean' ],
119
+                'context'     => [ 'view', 'edit' ],
120
+                'readonly'    => true,
121
+            ],
122
+            'show_backorder_badge' => [
123
+                'description' => __( 'True if the product is on backorder.', 'woocommerce' ),
124
+                'type'        => [ 'boolean' ],
125
+                'context'     => [ 'view', 'edit' ],
126
+                'readonly'    => true,
127
+            ],
128
+            'sold_individually'    => [
129
+                'description' => __( 'If true, only one item of this product is allowed for purchase in a single order.', 'woocommerce' ),
130
+                'type'        => 'boolean',
131
+                'context'     => [ 'view', 'edit' ],
132
+                'readonly'    => true,
133
+            ],
134
+            'permalink'            => [
135
+                'description' => __( 'Product URL.', 'woocommerce' ),
136
+                'type'        => 'string',
137
+                'format'      => 'uri',
138
+                'context'     => [ 'view', 'edit' ],
139
+                'readonly'    => true,
140
+            ],
141
+            'images'               => [
142
+                'description' => __( 'List of images.', 'woocommerce' ),
143
+                'type'        => 'array',
144
+                'context'     => [ 'view', 'edit' ],
145
+                'readonly'    => true,
146
+                'items'       => [
147
+                    'type'       => 'object',
148
+                    'properties' => $this->image_attachment_schema->get_properties(),
149
+                ],
150
+            ],
151
+            'variation'            => [
152
+                'description' => __( 'Chosen attributes (for variations).', 'woocommerce' ),
153
+                'type'        => 'array',
154
+                'context'     => [ 'view', 'edit' ],
155
+                'readonly'    => true,
156
+                'items'       => [
157
+                    'type'       => 'object',
158
+                    'properties' => [
159
+                        'attribute' => [
160
+                            'description' => __( 'Variation attribute name.', 'woocommerce' ),
161
+                            'type'        => 'string',
162
+                            'context'     => [ 'view', 'edit' ],
163
+                            'readonly'    => true,
164
+                        ],
165
+                        'value'     => [
166
+                            'description' => __( 'Variation attribute value.', 'woocommerce' ),
167
+                            'type'        => 'string',
168
+                            'context'     => [ 'view', 'edit' ],
169
+                            'readonly'    => true,
170
+                        ],
171
+                    ],
172
+                ],
173
+            ],
174
+            'item_data'            => [
175
+                'description' => __( 'Metadata related to the cart item', 'woocommerce' ),
176
+                'type'        => 'array',
177
+                'context'     => [ 'view', 'edit' ],
178
+                'readonly'    => true,
179
+                'items'       => [
180
+                    'type'       => 'object',
181
+                    'properties' => [
182
+                        'name'    => [
183
+                            'description' => __( 'Name of the metadata.', 'woocommerce' ),
184
+                            'type'        => 'string',
185
+                            'context'     => [ 'view', 'edit' ],
186
+                            'readonly'    => true,
187
+                        ],
188
+                        'value'   => [
189
+                            'description' => __( 'Value of the metadata.', 'woocommerce' ),
190
+                            'type'        => 'string',
191
+                            'context'     => [ 'view', 'edit' ],
192
+                            'readonly'    => true,
193
+                        ],
194
+                        'display' => [
195
+                            'description' => __( 'Optionally, how the metadata value should be displayed to the user.', 'woocommerce' ),
196
+                            'type'        => 'string',
197
+                            'context'     => [ 'view', 'edit' ],
198
+                            'readonly'    => true,
199
+                        ],
200
+                    ],
201
+                ],
202
+            ],
203
+            'prices'               => [
204
+                'description' => __( 'Price data for the product in the current line item, including or excluding taxes based on the "display prices during cart and checkout" setting. Provided using the smallest unit of the currency.', 'woocommerce' ),
205
+                'type'        => 'object',
206
+                'context'     => [ 'view', 'edit' ],
207
+                'readonly'    => true,
208
+                'properties'  => array_merge(
209
+                    $this->get_store_currency_properties(),
210
+                    [
211
+                        'price'         => [
212
+                            'description' => __( 'Current product price.', 'woocommerce' ),
213
+                            'type'        => 'string',
214
+                            'context'     => [ 'view', 'edit' ],
215
+                            'readonly'    => true,
216
+                        ],
217
+                        'regular_price' => [
218
+                            'description' => __( 'Regular product price.', 'woocommerce' ),
219
+                            'type'        => 'string',
220
+                            'context'     => [ 'view', 'edit' ],
221
+                            'readonly'    => true,
222
+                        ],
223
+                        'sale_price'    => [
224
+                            'description' => __( 'Sale product price, if applicable.', 'woocommerce' ),
225
+                            'type'        => 'string',
226
+                            'context'     => [ 'view', 'edit' ],
227
+                            'readonly'    => true,
228
+                        ],
229
+                        'price_range'   => [
230
+                            'description' => __( 'Price range, if applicable.', 'woocommerce' ),
231
+                            'type'        => [ 'object', 'null' ],
232
+                            'context'     => [ 'view', 'edit' ],
233
+                            'readonly'    => true,
234
+                            'properties'  => [
235
+                                'min_amount' => [
236
+                                    'description' => __( 'Price amount.', 'woocommerce' ),
237
+                                    'type'        => 'string',
238
+                                    'context'     => [ 'view', 'edit' ],
239
+                                    'readonly'    => true,
240
+                                ],
241
+                                'max_amount' => [
242
+                                    'description' => __( 'Price amount.', 'woocommerce' ),
243
+                                    'type'        => 'string',
244
+                                    'context'     => [ 'view', 'edit' ],
245
+                                    'readonly'    => true,
246
+                                ],
247
+                            ],
248
+                        ],
249
+                        'raw_prices'    => [
250
+                            'description' => __( 'Raw unrounded product prices used in calculations. Provided using a higher unit of precision than the currency.', 'woocommerce' ),
251
+                            'type'        => [ 'object', 'null' ],
252
+                            'context'     => [ 'view', 'edit' ],
253
+                            'readonly'    => true,
254
+                            'properties'  => [
255
+                                'precision'     => [
256
+                                    'description' => __( 'Decimal precision of the returned prices.', 'woocommerce' ),
257
+                                    'type'        => 'integer',
258
+                                    'context'     => [ 'view', 'edit' ],
259
+                                    'readonly'    => true,
260
+                                ],
261
+                                'price'         => [
262
+                                    'description' => __( 'Current product price.', 'woocommerce' ),
263
+                                    'type'        => 'string',
264
+                                    'context'     => [ 'view', 'edit' ],
265
+                                    'readonly'    => true,
266
+                                ],
267
+                                'regular_price' => [
268
+                                    'description' => __( 'Regular product price.', 'woocommerce' ),
269
+                                    'type'        => 'string',
270
+                                    'context'     => [ 'view', 'edit' ],
271
+                                    'readonly'    => true,
272
+                                ],
273
+                                'sale_price'    => [
274
+                                    'description' => __( 'Sale product price, if applicable.', 'woocommerce' ),
275
+                                    'type'        => 'string',
276
+                                    'context'     => [ 'view', 'edit' ],
277
+                                    'readonly'    => true,
278
+                                ],
279
+                            ],
280
+                        ],
281
+                    ]
282
+                ),
283
+            ],
284
+            'totals'               => [
285
+                'description' => __( 'Item total amounts provided using the smallest unit of the currency.', 'woocommerce' ),
286
+                'type'        => 'object',
287
+                'context'     => [ 'view', 'edit' ],
288
+                'readonly'    => true,
289
+                'properties'  => array_merge(
290
+                    $this->get_store_currency_properties(),
291
+                    [
292
+                        'line_subtotal'     => [
293
+                            'description' => __( 'Line subtotal (the price of the product before coupon discounts have been applied).', 'woocommerce' ),
294
+                            'type'        => 'string',
295
+                            'context'     => [ 'view', 'edit' ],
296
+                            'readonly'    => true,
297
+                        ],
298
+                        'line_subtotal_tax' => [
299
+                            'description' => __( 'Line subtotal tax.', 'woocommerce' ),
300
+                            'type'        => 'string',
301
+                            'context'     => [ 'view', 'edit' ],
302
+                            'readonly'    => true,
303
+                        ],
304
+                        'line_total'        => [
305
+                            'description' => __( 'Line total (the price of the product after coupon discounts have been applied).', 'woocommerce' ),
306
+                            'type'        => 'string',
307
+                            'context'     => [ 'view', 'edit' ],
308
+                            'readonly'    => true,
309
+                        ],
310
+                        'line_total_tax'    => [
311
+                            'description' => __( 'Line total tax.', 'woocommerce' ),
312
+                            'type'        => 'string',
313
+                            'context'     => [ 'view', 'edit' ],
314
+                            'readonly'    => true,
315
+                        ],
316
+                    ]
317
+                ),
318
+            ],
319
+            'catalog_visibility'   => [
320
+                'description' => __( 'Whether the product is visible in the catalog', 'woocommerce' ),
321
+                'type'        => 'string',
322
+                'context'     => [ 'view', 'edit' ],
323
+                'readonly'    => true,
324
+            ],
325
+            self::EXTENDING_KEY    => $this->get_extended_schema( self::IDENTIFIER ),
326
+        ];
327
+    }
328 328
 
329
-	/**
330
-	 * Convert a WooCommerce cart item to an object suitable for the response.
331
-	 *
332
-	 * @param array $cart_item Cart item array.
333
-	 * @return array
334
-	 */
335
-	public function get_item_response( $cart_item ) {
336
-		$product = $cart_item['data'];
329
+    /**
330
+     * Convert a WooCommerce cart item to an object suitable for the response.
331
+     *
332
+     * @param array $cart_item Cart item array.
333
+     * @return array
334
+     */
335
+    public function get_item_response( $cart_item ) {
336
+        $product = $cart_item['data'];
337 337
 
338
-		return [
339
-			'key'                  => $cart_item['key'],
340
-			'id'                   => $product->get_id(),
341
-			'quantity'             => wc_stock_amount( $cart_item['quantity'] ),
342
-			'quantity_limits'      => (object) ( new QuantityLimits() )->get_cart_item_quantity_limits( $cart_item ),
343
-			'name'                 => $this->prepare_html_response( $product->get_title() ),
344
-			'short_description'    => $this->prepare_html_response( wc_format_content( wp_kses_post( $product->get_short_description() ) ) ),
345
-			'description'          => $this->prepare_html_response( wc_format_content( wp_kses_post( $product->get_description() ) ) ),
346
-			'sku'                  => $this->prepare_html_response( $product->get_sku() ),
347
-			'low_stock_remaining'  => $this->get_low_stock_remaining( $product ),
348
-			'backorders_allowed'   => (bool) $product->backorders_allowed(),
349
-			'show_backorder_badge' => (bool) $product->backorders_require_notification() && $product->is_on_backorder( $cart_item['quantity'] ),
350
-			'sold_individually'    => $product->is_sold_individually(),
351
-			'permalink'            => $product->get_permalink(),
352
-			'images'               => $this->get_images( $product ),
353
-			'variation'            => $this->format_variation_data( $cart_item['variation'], $product ),
354
-			'item_data'            => $this->get_item_data( $cart_item ),
355
-			'prices'               => (object) $this->prepare_product_price_response( $product, get_option( 'woocommerce_tax_display_cart' ) ),
356
-			'totals'               => (object) $this->prepare_currency_response(
357
-				[
358
-					'line_subtotal'     => $this->prepare_money_response( $cart_item['line_subtotal'], wc_get_price_decimals() ),
359
-					'line_subtotal_tax' => $this->prepare_money_response( $cart_item['line_subtotal_tax'], wc_get_price_decimals() ),
360
-					'line_total'        => $this->prepare_money_response( $cart_item['line_total'], wc_get_price_decimals() ),
361
-					'line_total_tax'    => $this->prepare_money_response( $cart_item['line_tax'], wc_get_price_decimals() ),
362
-				]
363
-			),
364
-			'catalog_visibility'   => $product->get_catalog_visibility(),
365
-			self::EXTENDING_KEY    => $this->get_extended_data( self::IDENTIFIER, $cart_item ),
366
-		];
367
-	}
338
+        return [
339
+            'key'                  => $cart_item['key'],
340
+            'id'                   => $product->get_id(),
341
+            'quantity'             => wc_stock_amount( $cart_item['quantity'] ),
342
+            'quantity_limits'      => (object) ( new QuantityLimits() )->get_cart_item_quantity_limits( $cart_item ),
343
+            'name'                 => $this->prepare_html_response( $product->get_title() ),
344
+            'short_description'    => $this->prepare_html_response( wc_format_content( wp_kses_post( $product->get_short_description() ) ) ),
345
+            'description'          => $this->prepare_html_response( wc_format_content( wp_kses_post( $product->get_description() ) ) ),
346
+            'sku'                  => $this->prepare_html_response( $product->get_sku() ),
347
+            'low_stock_remaining'  => $this->get_low_stock_remaining( $product ),
348
+            'backorders_allowed'   => (bool) $product->backorders_allowed(),
349
+            'show_backorder_badge' => (bool) $product->backorders_require_notification() && $product->is_on_backorder( $cart_item['quantity'] ),
350
+            'sold_individually'    => $product->is_sold_individually(),
351
+            'permalink'            => $product->get_permalink(),
352
+            'images'               => $this->get_images( $product ),
353
+            'variation'            => $this->format_variation_data( $cart_item['variation'], $product ),
354
+            'item_data'            => $this->get_item_data( $cart_item ),
355
+            'prices'               => (object) $this->prepare_product_price_response( $product, get_option( 'woocommerce_tax_display_cart' ) ),
356
+            'totals'               => (object) $this->prepare_currency_response(
357
+                [
358
+                    'line_subtotal'     => $this->prepare_money_response( $cart_item['line_subtotal'], wc_get_price_decimals() ),
359
+                    'line_subtotal_tax' => $this->prepare_money_response( $cart_item['line_subtotal_tax'], wc_get_price_decimals() ),
360
+                    'line_total'        => $this->prepare_money_response( $cart_item['line_total'], wc_get_price_decimals() ),
361
+                    'line_total_tax'    => $this->prepare_money_response( $cart_item['line_tax'], wc_get_price_decimals() ),
362
+                ]
363
+            ),
364
+            'catalog_visibility'   => $product->get_catalog_visibility(),
365
+            self::EXTENDING_KEY    => $this->get_extended_data( self::IDENTIFIER, $cart_item ),
366
+        ];
367
+    }
368 368
 
369
-	/**
370
-	 * Get an array of pricing data.
371
-	 *
372
-	 * @param \WC_Product $product Product instance.
373
-	 * @param string      $tax_display_mode If returned prices are incl or excl of tax.
374
-	 * @return array
375
-	 */
376
-	protected function prepare_product_price_response( \WC_Product $product, $tax_display_mode = '' ) {
377
-		$tax_display_mode = $this->get_tax_display_mode( $tax_display_mode );
378
-		$price_function   = $this->get_price_function_from_tax_display_mode( $tax_display_mode );
379
-		$prices           = parent::prepare_product_price_response( $product, $tax_display_mode );
369
+    /**
370
+     * Get an array of pricing data.
371
+     *
372
+     * @param \WC_Product $product Product instance.
373
+     * @param string      $tax_display_mode If returned prices are incl or excl of tax.
374
+     * @return array
375
+     */
376
+    protected function prepare_product_price_response( \WC_Product $product, $tax_display_mode = '' ) {
377
+        $tax_display_mode = $this->get_tax_display_mode( $tax_display_mode );
378
+        $price_function   = $this->get_price_function_from_tax_display_mode( $tax_display_mode );
379
+        $prices           = parent::prepare_product_price_response( $product, $tax_display_mode );
380 380
 
381
-		// Add raw prices (prices with greater precision).
382
-		$prices['raw_prices'] = [
383
-			'precision'     => wc_get_rounding_precision(),
384
-			'price'         => $this->prepare_money_response( $price_function( $product ), wc_get_rounding_precision() ),
385
-			'regular_price' => $this->prepare_money_response( $price_function( $product, [ 'price' => $product->get_regular_price() ] ), wc_get_rounding_precision() ),
386
-			'sale_price'    => $this->prepare_money_response( $price_function( $product, [ 'price' => $product->get_sale_price() ] ), wc_get_rounding_precision() ),
387
-		];
381
+        // Add raw prices (prices with greater precision).
382
+        $prices['raw_prices'] = [
383
+            'precision'     => wc_get_rounding_precision(),
384
+            'price'         => $this->prepare_money_response( $price_function( $product ), wc_get_rounding_precision() ),
385
+            'regular_price' => $this->prepare_money_response( $price_function( $product, [ 'price' => $product->get_regular_price() ] ), wc_get_rounding_precision() ),
386
+            'sale_price'    => $this->prepare_money_response( $price_function( $product, [ 'price' => $product->get_sale_price() ] ), wc_get_rounding_precision() ),
387
+        ];
388 388
 
389
-		return $prices;
390
-	}
389
+        return $prices;
390
+    }
391 391
 
392
-	/**
393
-	 * Format variation data, for example convert slugs such as attribute_pa_size to Size.
394
-	 *
395
-	 * @param array       $variation_data Array of data from the cart.
396
-	 * @param \WC_Product $product Product data.
397
-	 * @return array
398
-	 */
399
-	protected function format_variation_data( $variation_data, $product ) {
400
-		$return = [];
392
+    /**
393
+     * Format variation data, for example convert slugs such as attribute_pa_size to Size.
394
+     *
395
+     * @param array       $variation_data Array of data from the cart.
396
+     * @param \WC_Product $product Product data.
397
+     * @return array
398
+     */
399
+    protected function format_variation_data( $variation_data, $product ) {
400
+        $return = [];
401 401
 
402
-		if ( ! is_iterable( $variation_data ) ) {
403
-			return $return;
404
-		}
402
+        if ( ! is_iterable( $variation_data ) ) {
403
+            return $return;
404
+        }
405 405
 
406
-		foreach ( $variation_data as $key => $value ) {
407
-			$taxonomy = wc_attribute_taxonomy_name( str_replace( 'attribute_pa_', '', urldecode( $key ) ) );
406
+        foreach ( $variation_data as $key => $value ) {
407
+            $taxonomy = wc_attribute_taxonomy_name( str_replace( 'attribute_pa_', '', urldecode( $key ) ) );
408 408
 
409
-			if ( taxonomy_exists( $taxonomy ) ) {
410
-				// If this is a term slug, get the term's nice name.
411
-				$term = get_term_by( 'slug', $value, $taxonomy );
412
-				if ( ! is_wp_error( $term ) && $term && $term->name ) {
413
-					$value = $term->name;
414
-				}
415
-				$label = wc_attribute_label( $taxonomy );
416
-			} else {
417
-				/**
418
-				 * Filters the variation option name.
419
-				 *
420
-				 * Filters the variation option name for custom option slugs.
421
-				 *
422
-				 * @internal Matches filter name in WooCommerce core.
423
-				 *
424
-				 * @param string $value The name to display.
425
-				 * @param null $unused Unused because this is not a variation taxonomy.
426
-				 * @param string $taxonomy Taxonomy or product attribute name.
427
-				 * @param \WC_Product $product Product data.
428
-				 * @return string
429
-				 */
430
-				$value = apply_filters( 'woocommerce_variation_option_name', $value, null, $taxonomy, $product );
431
-				$label = wc_attribute_label( str_replace( 'attribute_', '', $key ), $product );
432
-			}
409
+            if ( taxonomy_exists( $taxonomy ) ) {
410
+                // If this is a term slug, get the term's nice name.
411
+                $term = get_term_by( 'slug', $value, $taxonomy );
412
+                if ( ! is_wp_error( $term ) && $term && $term->name ) {
413
+                    $value = $term->name;
414
+                }
415
+                $label = wc_attribute_label( $taxonomy );
416
+            } else {
417
+                /**
418
+                 * Filters the variation option name.
419
+                 *
420
+                 * Filters the variation option name for custom option slugs.
421
+                 *
422
+                 * @internal Matches filter name in WooCommerce core.
423
+                 *
424
+                 * @param string $value The name to display.
425
+                 * @param null $unused Unused because this is not a variation taxonomy.
426
+                 * @param string $taxonomy Taxonomy or product attribute name.
427
+                 * @param \WC_Product $product Product data.
428
+                 * @return string
429
+                 */
430
+                $value = apply_filters( 'woocommerce_variation_option_name', $value, null, $taxonomy, $product );
431
+                $label = wc_attribute_label( str_replace( 'attribute_', '', $key ), $product );
432
+            }
433 433
 
434
-			$return[] = [
435
-				'attribute' => $this->prepare_html_response( $label ),
436
-				'value'     => $this->prepare_html_response( $value ),
437
-			];
438
-		}
434
+            $return[] = [
435
+                'attribute' => $this->prepare_html_response( $label ),
436
+                'value'     => $this->prepare_html_response( $value ),
437
+            ];
438
+        }
439 439
 
440
-		return $return;
441
-	}
440
+        return $return;
441
+    }
442 442
 
443
-	/**
444
-	 * Format cart item data removing any HTML tag.
445
-	 *
446
-	 * @param array $cart_item Cart item array.
447
-	 * @return array
448
-	 */
449
-	protected function get_item_data( $cart_item ) {
450
-		/**
451
-		 * Filters cart item data.
452
-		 *
453
-		 * Filters the variation option name for custom option slugs.
454
-		 *
455
-		 * @internal Matches filter name in WooCommerce core.
456
-		 *
457
-		 * @param array $item_data Cart item data. Empty by default.
458
-		 * @param array $cart_item Cart item array.
459
-		 * @return array
460
-		 */
461
-		$item_data = apply_filters( 'woocommerce_get_item_data', array(), $cart_item );
462
-		return array_map( [ $this, 'format_item_data_element' ], $item_data );
463
-	}
443
+    /**
444
+     * Format cart item data removing any HTML tag.
445
+     *
446
+     * @param array $cart_item Cart item array.
447
+     * @return array
448
+     */
449
+    protected function get_item_data( $cart_item ) {
450
+        /**
451
+         * Filters cart item data.
452
+         *
453
+         * Filters the variation option name for custom option slugs.
454
+         *
455
+         * @internal Matches filter name in WooCommerce core.
456
+         *
457
+         * @param array $item_data Cart item data. Empty by default.
458
+         * @param array $cart_item Cart item array.
459
+         * @return array
460
+         */
461
+        $item_data = apply_filters( 'woocommerce_get_item_data', array(), $cart_item );
462
+        return array_map( [ $this, 'format_item_data_element' ], $item_data );
463
+    }
464 464
 
465
-	/**
466
-	 * Remove HTML tags from cart item data and set the `hidden` property to `__experimental_woocommerce_blocks_hidden`.
467
-	 *
468
-	 * @param array $item_data_element Individual element of a cart item data.
469
-	 * @return array
470
-	 */
471
-	protected function format_item_data_element( $item_data_element ) {
472
-		if ( array_key_exists( '__experimental_woocommerce_blocks_hidden', $item_data_element ) ) {
473
-			$item_data_element['hidden'] = $item_data_element['__experimental_woocommerce_blocks_hidden'];
474
-		}
475
-		return array_map( 'wp_strip_all_tags', $item_data_element );
476
-	}
465
+    /**
466
+     * Remove HTML tags from cart item data and set the `hidden` property to `__experimental_woocommerce_blocks_hidden`.
467
+     *
468
+     * @param array $item_data_element Individual element of a cart item data.
469
+     * @return array
470
+     */
471
+    protected function format_item_data_element( $item_data_element ) {
472
+        if ( array_key_exists( '__experimental_woocommerce_blocks_hidden', $item_data_element ) ) {
473
+            $item_data_element['hidden'] = $item_data_element['__experimental_woocommerce_blocks_hidden'];
474
+        }
475
+        return array_map( 'wp_strip_all_tags', $item_data_element );
476
+    }
477 477
 }
Please login to merge, or discard this patch.
Spacing   +135 added lines, -135 removed lines patch added patch discarded remove patch
@@ -32,116 +32,116 @@  discard block
 block discarded – undo
32 32
 	public function get_properties() {
33 33
 		return [
34 34
 			'key'                  => [
35
-				'description' => __( 'Unique identifier for the item within the cart.', 'woocommerce' ),
35
+				'description' => __('Unique identifier for the item within the cart.', 'woocommerce'),
36 36
 				'type'        => 'string',
37
-				'context'     => [ 'view', 'edit' ],
37
+				'context'     => ['view', 'edit'],
38 38
 				'readonly'    => true,
39 39
 			],
40 40
 			'id'                   => [
41
-				'description' => __( 'The cart item product or variation ID.', 'woocommerce' ),
41
+				'description' => __('The cart item product or variation ID.', 'woocommerce'),
42 42
 				'type'        => 'integer',
43
-				'context'     => [ 'view', 'edit' ],
43
+				'context'     => ['view', 'edit'],
44 44
 				'readonly'    => true,
45 45
 			],
46 46
 			'quantity'             => [
47
-				'description' => __( 'Quantity of this item in the cart.', 'woocommerce' ),
47
+				'description' => __('Quantity of this item in the cart.', 'woocommerce'),
48 48
 				'type'        => 'number',
49
-				'context'     => [ 'view', 'edit' ],
49
+				'context'     => ['view', 'edit'],
50 50
 				'readonly'    => true,
51 51
 			],
52 52
 			'quantity_limits'      => [
53
-				'description' => __( 'How the quantity of this item should be controlled, for example, any limits in place.', 'woocommerce' ),
53
+				'description' => __('How the quantity of this item should be controlled, for example, any limits in place.', 'woocommerce'),
54 54
 				'type'        => 'object',
55
-				'context'     => [ 'view', 'edit' ],
55
+				'context'     => ['view', 'edit'],
56 56
 				'readonly'    => true,
57 57
 				'properties'  => [
58 58
 					'minimum'     => [
59
-						'description' => __( 'The minimum quantity allowed in the cart for this line item.', 'woocommerce' ),
59
+						'description' => __('The minimum quantity allowed in the cart for this line item.', 'woocommerce'),
60 60
 						'type'        => 'integer',
61
-						'context'     => [ 'view', 'edit' ],
61
+						'context'     => ['view', 'edit'],
62 62
 						'readonly'    => true,
63 63
 					],
64 64
 					'maximum'     => [
65
-						'description' => __( 'The maximum quantity allowed in the cart for this line item.', 'woocommerce' ),
65
+						'description' => __('The maximum quantity allowed in the cart for this line item.', 'woocommerce'),
66 66
 						'type'        => 'integer',
67
-						'context'     => [ 'view', 'edit' ],
67
+						'context'     => ['view', 'edit'],
68 68
 						'readonly'    => true,
69 69
 					],
70 70
 					'multiple_of' => [
71
-						'description' => __( 'The amount that quantities increment by. Quantity must be an multiple of this value.', 'woocommerce' ),
71
+						'description' => __('The amount that quantities increment by. Quantity must be an multiple of this value.', 'woocommerce'),
72 72
 						'type'        => 'integer',
73
-						'context'     => [ 'view', 'edit' ],
73
+						'context'     => ['view', 'edit'],
74 74
 						'readonly'    => true,
75 75
 						'default'     => 1,
76 76
 					],
77 77
 					'editable'    => [
78
-						'description' => __( 'If the quantity in the cart is editable or fixed.', 'woocommerce' ),
78
+						'description' => __('If the quantity in the cart is editable or fixed.', 'woocommerce'),
79 79
 						'type'        => 'boolean',
80
-						'context'     => [ 'view', 'edit' ],
80
+						'context'     => ['view', 'edit'],
81 81
 						'readonly'    => true,
82 82
 						'default'     => true,
83 83
 					],
84 84
 				],
85 85
 			],
86 86
 			'name'                 => [
87
-				'description' => __( 'Product name.', 'woocommerce' ),
87
+				'description' => __('Product name.', 'woocommerce'),
88 88
 				'type'        => 'string',
89
-				'context'     => [ 'view', 'edit' ],
89
+				'context'     => ['view', 'edit'],
90 90
 				'readonly'    => true,
91 91
 			],
92 92
 			'short_description'    => [
93
-				'description' => __( 'Product short description in HTML format.', 'woocommerce' ),
93
+				'description' => __('Product short description in HTML format.', 'woocommerce'),
94 94
 				'type'        => 'string',
95
-				'context'     => [ 'view', 'edit' ],
95
+				'context'     => ['view', 'edit'],
96 96
 				'readonly'    => true,
97 97
 			],
98 98
 			'description'          => [
99
-				'description' => __( 'Product full description in HTML format.', 'woocommerce' ),
99
+				'description' => __('Product full description in HTML format.', 'woocommerce'),
100 100
 				'type'        => 'string',
101
-				'context'     => [ 'view', 'edit' ],
101
+				'context'     => ['view', 'edit'],
102 102
 				'readonly'    => true,
103 103
 			],
104 104
 			'sku'                  => [
105
-				'description' => __( 'Stock keeping unit, if applicable.', 'woocommerce' ),
105
+				'description' => __('Stock keeping unit, if applicable.', 'woocommerce'),
106 106
 				'type'        => 'string',
107
-				'context'     => [ 'view', 'edit' ],
107
+				'context'     => ['view', 'edit'],
108 108
 				'readonly'    => true,
109 109
 			],
110 110
 			'low_stock_remaining'  => [
111
-				'description' => __( 'Quantity left in stock if stock is low, or null if not applicable.', 'woocommerce' ),
112
-				'type'        => [ 'integer', 'null' ],
113
-				'context'     => [ 'view', 'edit' ],
111
+				'description' => __('Quantity left in stock if stock is low, or null if not applicable.', 'woocommerce'),
112
+				'type'        => ['integer', 'null'],
113
+				'context'     => ['view', 'edit'],
114 114
 				'readonly'    => true,
115 115
 			],
116 116
 			'backorders_allowed'   => [
117
-				'description' => __( 'True if backorders are allowed past stock availability.', 'woocommerce' ),
118
-				'type'        => [ 'boolean' ],
119
-				'context'     => [ 'view', 'edit' ],
117
+				'description' => __('True if backorders are allowed past stock availability.', 'woocommerce'),
118
+				'type'        => ['boolean'],
119
+				'context'     => ['view', 'edit'],
120 120
 				'readonly'    => true,
121 121
 			],
122 122
 			'show_backorder_badge' => [
123
-				'description' => __( 'True if the product is on backorder.', 'woocommerce' ),
124
-				'type'        => [ 'boolean' ],
125
-				'context'     => [ 'view', 'edit' ],
123
+				'description' => __('True if the product is on backorder.', 'woocommerce'),
124
+				'type'        => ['boolean'],
125
+				'context'     => ['view', 'edit'],
126 126
 				'readonly'    => true,
127 127
 			],
128 128
 			'sold_individually'    => [
129
-				'description' => __( 'If true, only one item of this product is allowed for purchase in a single order.', 'woocommerce' ),
129
+				'description' => __('If true, only one item of this product is allowed for purchase in a single order.', 'woocommerce'),
130 130
 				'type'        => 'boolean',
131
-				'context'     => [ 'view', 'edit' ],
131
+				'context'     => ['view', 'edit'],
132 132
 				'readonly'    => true,
133 133
 			],
134 134
 			'permalink'            => [
135
-				'description' => __( 'Product URL.', 'woocommerce' ),
135
+				'description' => __('Product URL.', 'woocommerce'),
136 136
 				'type'        => 'string',
137 137
 				'format'      => 'uri',
138
-				'context'     => [ 'view', 'edit' ],
138
+				'context'     => ['view', 'edit'],
139 139
 				'readonly'    => true,
140 140
 			],
141 141
 			'images'               => [
142
-				'description' => __( 'List of images.', 'woocommerce' ),
142
+				'description' => __('List of images.', 'woocommerce'),
143 143
 				'type'        => 'array',
144
-				'context'     => [ 'view', 'edit' ],
144
+				'context'     => ['view', 'edit'],
145 145
 				'readonly'    => true,
146 146
 				'items'       => [
147 147
 					'type'       => 'object',
@@ -149,131 +149,131 @@  discard block
 block discarded – undo
149 149
 				],
150 150
 			],
151 151
 			'variation'            => [
152
-				'description' => __( 'Chosen attributes (for variations).', 'woocommerce' ),
152
+				'description' => __('Chosen attributes (for variations).', 'woocommerce'),
153 153
 				'type'        => 'array',
154
-				'context'     => [ 'view', 'edit' ],
154
+				'context'     => ['view', 'edit'],
155 155
 				'readonly'    => true,
156 156
 				'items'       => [
157 157
 					'type'       => 'object',
158 158
 					'properties' => [
159 159
 						'attribute' => [
160
-							'description' => __( 'Variation attribute name.', 'woocommerce' ),
160
+							'description' => __('Variation attribute name.', 'woocommerce'),
161 161
 							'type'        => 'string',
162
-							'context'     => [ 'view', 'edit' ],
162
+							'context'     => ['view', 'edit'],
163 163
 							'readonly'    => true,
164 164
 						],
165 165
 						'value'     => [
166
-							'description' => __( 'Variation attribute value.', 'woocommerce' ),
166
+							'description' => __('Variation attribute value.', 'woocommerce'),
167 167
 							'type'        => 'string',
168
-							'context'     => [ 'view', 'edit' ],
168
+							'context'     => ['view', 'edit'],
169 169
 							'readonly'    => true,
170 170
 						],
171 171
 					],
172 172
 				],
173 173
 			],
174 174
 			'item_data'            => [
175
-				'description' => __( 'Metadata related to the cart item', 'woocommerce' ),
175
+				'description' => __('Metadata related to the cart item', 'woocommerce'),
176 176
 				'type'        => 'array',
177
-				'context'     => [ 'view', 'edit' ],
177
+				'context'     => ['view', 'edit'],
178 178
 				'readonly'    => true,
179 179
 				'items'       => [
180 180
 					'type'       => 'object',
181 181
 					'properties' => [
182 182
 						'name'    => [
183
-							'description' => __( 'Name of the metadata.', 'woocommerce' ),
183
+							'description' => __('Name of the metadata.', 'woocommerce'),
184 184
 							'type'        => 'string',
185
-							'context'     => [ 'view', 'edit' ],
185
+							'context'     => ['view', 'edit'],
186 186
 							'readonly'    => true,
187 187
 						],
188 188
 						'value'   => [
189
-							'description' => __( 'Value of the metadata.', 'woocommerce' ),
189
+							'description' => __('Value of the metadata.', 'woocommerce'),
190 190
 							'type'        => 'string',
191
-							'context'     => [ 'view', 'edit' ],
191
+							'context'     => ['view', 'edit'],
192 192
 							'readonly'    => true,
193 193
 						],
194 194
 						'display' => [
195
-							'description' => __( 'Optionally, how the metadata value should be displayed to the user.', 'woocommerce' ),
195
+							'description' => __('Optionally, how the metadata value should be displayed to the user.', 'woocommerce'),
196 196
 							'type'        => 'string',
197
-							'context'     => [ 'view', 'edit' ],
197
+							'context'     => ['view', 'edit'],
198 198
 							'readonly'    => true,
199 199
 						],
200 200
 					],
201 201
 				],
202 202
 			],
203 203
 			'prices'               => [
204
-				'description' => __( 'Price data for the product in the current line item, including or excluding taxes based on the "display prices during cart and checkout" setting. Provided using the smallest unit of the currency.', 'woocommerce' ),
204
+				'description' => __('Price data for the product in the current line item, including or excluding taxes based on the "display prices during cart and checkout" setting. Provided using the smallest unit of the currency.', 'woocommerce'),
205 205
 				'type'        => 'object',
206
-				'context'     => [ 'view', 'edit' ],
206
+				'context'     => ['view', 'edit'],
207 207
 				'readonly'    => true,
208 208
 				'properties'  => array_merge(
209 209
 					$this->get_store_currency_properties(),
210 210
 					[
211 211
 						'price'         => [
212
-							'description' => __( 'Current product price.', 'woocommerce' ),
212
+							'description' => __('Current product price.', 'woocommerce'),
213 213
 							'type'        => 'string',
214
-							'context'     => [ 'view', 'edit' ],
214
+							'context'     => ['view', 'edit'],
215 215
 							'readonly'    => true,
216 216
 						],
217 217
 						'regular_price' => [
218
-							'description' => __( 'Regular product price.', 'woocommerce' ),
218
+							'description' => __('Regular product price.', 'woocommerce'),
219 219
 							'type'        => 'string',
220
-							'context'     => [ 'view', 'edit' ],
220
+							'context'     => ['view', 'edit'],
221 221
 							'readonly'    => true,
222 222
 						],
223 223
 						'sale_price'    => [
224
-							'description' => __( 'Sale product price, if applicable.', 'woocommerce' ),
224
+							'description' => __('Sale product price, if applicable.', 'woocommerce'),
225 225
 							'type'        => 'string',
226
-							'context'     => [ 'view', 'edit' ],
226
+							'context'     => ['view', 'edit'],
227 227
 							'readonly'    => true,
228 228
 						],
229 229
 						'price_range'   => [
230
-							'description' => __( 'Price range, if applicable.', 'woocommerce' ),
231
-							'type'        => [ 'object', 'null' ],
232
-							'context'     => [ 'view', 'edit' ],
230
+							'description' => __('Price range, if applicable.', 'woocommerce'),
231
+							'type'        => ['object', 'null'],
232
+							'context'     => ['view', 'edit'],
233 233
 							'readonly'    => true,
234 234
 							'properties'  => [
235 235
 								'min_amount' => [
236
-									'description' => __( 'Price amount.', 'woocommerce' ),
236
+									'description' => __('Price amount.', 'woocommerce'),
237 237
 									'type'        => 'string',
238
-									'context'     => [ 'view', 'edit' ],
238
+									'context'     => ['view', 'edit'],
239 239
 									'readonly'    => true,
240 240
 								],
241 241
 								'max_amount' => [
242
-									'description' => __( 'Price amount.', 'woocommerce' ),
242
+									'description' => __('Price amount.', 'woocommerce'),
243 243
 									'type'        => 'string',
244
-									'context'     => [ 'view', 'edit' ],
244
+									'context'     => ['view', 'edit'],
245 245
 									'readonly'    => true,
246 246
 								],
247 247
 							],
248 248
 						],
249 249
 						'raw_prices'    => [
250
-							'description' => __( 'Raw unrounded product prices used in calculations. Provided using a higher unit of precision than the currency.', 'woocommerce' ),
251
-							'type'        => [ 'object', 'null' ],
252
-							'context'     => [ 'view', 'edit' ],
250
+							'description' => __('Raw unrounded product prices used in calculations. Provided using a higher unit of precision than the currency.', 'woocommerce'),
251
+							'type'        => ['object', 'null'],
252
+							'context'     => ['view', 'edit'],
253 253
 							'readonly'    => true,
254 254
 							'properties'  => [
255 255
 								'precision'     => [
256
-									'description' => __( 'Decimal precision of the returned prices.', 'woocommerce' ),
256
+									'description' => __('Decimal precision of the returned prices.', 'woocommerce'),
257 257
 									'type'        => 'integer',
258
-									'context'     => [ 'view', 'edit' ],
258
+									'context'     => ['view', 'edit'],
259 259
 									'readonly'    => true,
260 260
 								],
261 261
 								'price'         => [
262
-									'description' => __( 'Current product price.', 'woocommerce' ),
262
+									'description' => __('Current product price.', 'woocommerce'),
263 263
 									'type'        => 'string',
264
-									'context'     => [ 'view', 'edit' ],
264
+									'context'     => ['view', 'edit'],
265 265
 									'readonly'    => true,
266 266
 								],
267 267
 								'regular_price' => [
268
-									'description' => __( 'Regular product price.', 'woocommerce' ),
268
+									'description' => __('Regular product price.', 'woocommerce'),
269 269
 									'type'        => 'string',
270
-									'context'     => [ 'view', 'edit' ],
270
+									'context'     => ['view', 'edit'],
271 271
 									'readonly'    => true,
272 272
 								],
273 273
 								'sale_price'    => [
274
-									'description' => __( 'Sale product price, if applicable.', 'woocommerce' ),
274
+									'description' => __('Sale product price, if applicable.', 'woocommerce'),
275 275
 									'type'        => 'string',
276
-									'context'     => [ 'view', 'edit' ],
276
+									'context'     => ['view', 'edit'],
277 277
 									'readonly'    => true,
278 278
 								],
279 279
 							],
@@ -282,47 +282,47 @@  discard block
 block discarded – undo
282 282
 				),
283 283
 			],
284 284
 			'totals'               => [
285
-				'description' => __( 'Item total amounts provided using the smallest unit of the currency.', 'woocommerce' ),
285
+				'description' => __('Item total amounts provided using the smallest unit of the currency.', 'woocommerce'),
286 286
 				'type'        => 'object',
287
-				'context'     => [ 'view', 'edit' ],
287
+				'context'     => ['view', 'edit'],
288 288
 				'readonly'    => true,
289 289
 				'properties'  => array_merge(
290 290
 					$this->get_store_currency_properties(),
291 291
 					[
292 292
 						'line_subtotal'     => [
293
-							'description' => __( 'Line subtotal (the price of the product before coupon discounts have been applied).', 'woocommerce' ),
293
+							'description' => __('Line subtotal (the price of the product before coupon discounts have been applied).', 'woocommerce'),
294 294
 							'type'        => 'string',
295
-							'context'     => [ 'view', 'edit' ],
295
+							'context'     => ['view', 'edit'],
296 296
 							'readonly'    => true,
297 297
 						],
298 298
 						'line_subtotal_tax' => [
299
-							'description' => __( 'Line subtotal tax.', 'woocommerce' ),
299
+							'description' => __('Line subtotal tax.', 'woocommerce'),
300 300
 							'type'        => 'string',
301
-							'context'     => [ 'view', 'edit' ],
301
+							'context'     => ['view', 'edit'],
302 302
 							'readonly'    => true,
303 303
 						],
304 304
 						'line_total'        => [
305
-							'description' => __( 'Line total (the price of the product after coupon discounts have been applied).', 'woocommerce' ),
305
+							'description' => __('Line total (the price of the product after coupon discounts have been applied).', 'woocommerce'),
306 306
 							'type'        => 'string',
307
-							'context'     => [ 'view', 'edit' ],
307
+							'context'     => ['view', 'edit'],
308 308
 							'readonly'    => true,
309 309
 						],
310 310
 						'line_total_tax'    => [
311
-							'description' => __( 'Line total tax.', 'woocommerce' ),
311
+							'description' => __('Line total tax.', 'woocommerce'),
312 312
 							'type'        => 'string',
313
-							'context'     => [ 'view', 'edit' ],
313
+							'context'     => ['view', 'edit'],
314 314
 							'readonly'    => true,
315 315
 						],
316 316
 					]
317 317
 				),
318 318
 			],
319 319
 			'catalog_visibility'   => [
320
-				'description' => __( 'Whether the product is visible in the catalog', 'woocommerce' ),
320
+				'description' => __('Whether the product is visible in the catalog', 'woocommerce'),
321 321
 				'type'        => 'string',
322
-				'context'     => [ 'view', 'edit' ],
322
+				'context'     => ['view', 'edit'],
323 323
 				'readonly'    => true,
324 324
 			],
325
-			self::EXTENDING_KEY    => $this->get_extended_schema( self::IDENTIFIER ),
325
+			self::EXTENDING_KEY    => $this->get_extended_schema(self::IDENTIFIER),
326 326
 		];
327 327
 	}
328 328
 
@@ -332,37 +332,37 @@  discard block
 block discarded – undo
332 332
 	 * @param array $cart_item Cart item array.
333 333
 	 * @return array
334 334
 	 */
335
-	public function get_item_response( $cart_item ) {
335
+	public function get_item_response($cart_item) {
336 336
 		$product = $cart_item['data'];
337 337
 
338 338
 		return [
339 339
 			'key'                  => $cart_item['key'],
340 340
 			'id'                   => $product->get_id(),
341
-			'quantity'             => wc_stock_amount( $cart_item['quantity'] ),
342
-			'quantity_limits'      => (object) ( new QuantityLimits() )->get_cart_item_quantity_limits( $cart_item ),
343
-			'name'                 => $this->prepare_html_response( $product->get_title() ),
344
-			'short_description'    => $this->prepare_html_response( wc_format_content( wp_kses_post( $product->get_short_description() ) ) ),
345
-			'description'          => $this->prepare_html_response( wc_format_content( wp_kses_post( $product->get_description() ) ) ),
346
-			'sku'                  => $this->prepare_html_response( $product->get_sku() ),
347
-			'low_stock_remaining'  => $this->get_low_stock_remaining( $product ),
341
+			'quantity'             => wc_stock_amount($cart_item['quantity']),
342
+			'quantity_limits'      => (object) (new QuantityLimits())->get_cart_item_quantity_limits($cart_item),
343
+			'name'                 => $this->prepare_html_response($product->get_title()),
344
+			'short_description'    => $this->prepare_html_response(wc_format_content(wp_kses_post($product->get_short_description()))),
345
+			'description'          => $this->prepare_html_response(wc_format_content(wp_kses_post($product->get_description()))),
346
+			'sku'                  => $this->prepare_html_response($product->get_sku()),
347
+			'low_stock_remaining'  => $this->get_low_stock_remaining($product),
348 348
 			'backorders_allowed'   => (bool) $product->backorders_allowed(),
349
-			'show_backorder_badge' => (bool) $product->backorders_require_notification() && $product->is_on_backorder( $cart_item['quantity'] ),
349
+			'show_backorder_badge' => (bool) $product->backorders_require_notification() && $product->is_on_backorder($cart_item['quantity']),
350 350
 			'sold_individually'    => $product->is_sold_individually(),
351 351
 			'permalink'            => $product->get_permalink(),
352
-			'images'               => $this->get_images( $product ),
353
-			'variation'            => $this->format_variation_data( $cart_item['variation'], $product ),
354
-			'item_data'            => $this->get_item_data( $cart_item ),
355
-			'prices'               => (object) $this->prepare_product_price_response( $product, get_option( 'woocommerce_tax_display_cart' ) ),
352
+			'images'               => $this->get_images($product),
353
+			'variation'            => $this->format_variation_data($cart_item['variation'], $product),
354
+			'item_data'            => $this->get_item_data($cart_item),
355
+			'prices'               => (object) $this->prepare_product_price_response($product, get_option('woocommerce_tax_display_cart')),
356 356
 			'totals'               => (object) $this->prepare_currency_response(
357 357
 				[
358
-					'line_subtotal'     => $this->prepare_money_response( $cart_item['line_subtotal'], wc_get_price_decimals() ),
359
-					'line_subtotal_tax' => $this->prepare_money_response( $cart_item['line_subtotal_tax'], wc_get_price_decimals() ),
360
-					'line_total'        => $this->prepare_money_response( $cart_item['line_total'], wc_get_price_decimals() ),
361
-					'line_total_tax'    => $this->prepare_money_response( $cart_item['line_tax'], wc_get_price_decimals() ),
358
+					'line_subtotal'     => $this->prepare_money_response($cart_item['line_subtotal'], wc_get_price_decimals()),
359
+					'line_subtotal_tax' => $this->prepare_money_response($cart_item['line_subtotal_tax'], wc_get_price_decimals()),
360
+					'line_total'        => $this->prepare_money_response($cart_item['line_total'], wc_get_price_decimals()),
361
+					'line_total_tax'    => $this->prepare_money_response($cart_item['line_tax'], wc_get_price_decimals()),
362 362
 				]
363 363
 			),
364 364
 			'catalog_visibility'   => $product->get_catalog_visibility(),
365
-			self::EXTENDING_KEY    => $this->get_extended_data( self::IDENTIFIER, $cart_item ),
365
+			self::EXTENDING_KEY    => $this->get_extended_data(self::IDENTIFIER, $cart_item),
366 366
 		];
367 367
 	}
368 368
 
@@ -373,17 +373,17 @@  discard block
 block discarded – undo
373 373
 	 * @param string      $tax_display_mode If returned prices are incl or excl of tax.
374 374
 	 * @return array
375 375
 	 */
376
-	protected function prepare_product_price_response( \WC_Product $product, $tax_display_mode = '' ) {
377
-		$tax_display_mode = $this->get_tax_display_mode( $tax_display_mode );
378
-		$price_function   = $this->get_price_function_from_tax_display_mode( $tax_display_mode );
379
-		$prices           = parent::prepare_product_price_response( $product, $tax_display_mode );
376
+	protected function prepare_product_price_response(\WC_Product $product, $tax_display_mode = '') {
377
+		$tax_display_mode = $this->get_tax_display_mode($tax_display_mode);
378
+		$price_function   = $this->get_price_function_from_tax_display_mode($tax_display_mode);
379
+		$prices           = parent::prepare_product_price_response($product, $tax_display_mode);
380 380
 
381 381
 		// Add raw prices (prices with greater precision).
382 382
 		$prices['raw_prices'] = [
383 383
 			'precision'     => wc_get_rounding_precision(),
384
-			'price'         => $this->prepare_money_response( $price_function( $product ), wc_get_rounding_precision() ),
385
-			'regular_price' => $this->prepare_money_response( $price_function( $product, [ 'price' => $product->get_regular_price() ] ), wc_get_rounding_precision() ),
386
-			'sale_price'    => $this->prepare_money_response( $price_function( $product, [ 'price' => $product->get_sale_price() ] ), wc_get_rounding_precision() ),
384
+			'price'         => $this->prepare_money_response($price_function($product), wc_get_rounding_precision()),
385
+			'regular_price' => $this->prepare_money_response($price_function($product, ['price' => $product->get_regular_price()]), wc_get_rounding_precision()),
386
+			'sale_price'    => $this->prepare_money_response($price_function($product, ['price' => $product->get_sale_price()]), wc_get_rounding_precision()),
387 387
 		];
388 388
 
389 389
 		return $prices;
@@ -396,23 +396,23 @@  discard block
 block discarded – undo
396 396
 	 * @param \WC_Product $product Product data.
397 397
 	 * @return array
398 398
 	 */
399
-	protected function format_variation_data( $variation_data, $product ) {
399
+	protected function format_variation_data($variation_data, $product) {
400 400
 		$return = [];
401 401
 
402
-		if ( ! is_iterable( $variation_data ) ) {
402
+		if (!is_iterable($variation_data)) {
403 403
 			return $return;
404 404
 		}
405 405
 
406
-		foreach ( $variation_data as $key => $value ) {
407
-			$taxonomy = wc_attribute_taxonomy_name( str_replace( 'attribute_pa_', '', urldecode( $key ) ) );
406
+		foreach ($variation_data as $key => $value) {
407
+			$taxonomy = wc_attribute_taxonomy_name(str_replace('attribute_pa_', '', urldecode($key)));
408 408
 
409
-			if ( taxonomy_exists( $taxonomy ) ) {
409
+			if (taxonomy_exists($taxonomy)) {
410 410
 				// If this is a term slug, get the term's nice name.
411
-				$term = get_term_by( 'slug', $value, $taxonomy );
412
-				if ( ! is_wp_error( $term ) && $term && $term->name ) {
411
+				$term = get_term_by('slug', $value, $taxonomy);
412
+				if (!is_wp_error($term) && $term && $term->name) {
413 413
 					$value = $term->name;
414 414
 				}
415
-				$label = wc_attribute_label( $taxonomy );
415
+				$label = wc_attribute_label($taxonomy);
416 416
 			} else {
417 417
 				/**
418 418
 				 * Filters the variation option name.
@@ -427,13 +427,13 @@  discard block
 block discarded – undo
427 427
 				 * @param \WC_Product $product Product data.
428 428
 				 * @return string
429 429
 				 */
430
-				$value = apply_filters( 'woocommerce_variation_option_name', $value, null, $taxonomy, $product );
431
-				$label = wc_attribute_label( str_replace( 'attribute_', '', $key ), $product );
430
+				$value = apply_filters('woocommerce_variation_option_name', $value, null, $taxonomy, $product);
431
+				$label = wc_attribute_label(str_replace('attribute_', '', $key), $product);
432 432
 			}
433 433
 
434 434
 			$return[] = [
435
-				'attribute' => $this->prepare_html_response( $label ),
436
-				'value'     => $this->prepare_html_response( $value ),
435
+				'attribute' => $this->prepare_html_response($label),
436
+				'value'     => $this->prepare_html_response($value),
437 437
 			];
438 438
 		}
439 439
 
@@ -446,7 +446,7 @@  discard block
 block discarded – undo
446 446
 	 * @param array $cart_item Cart item array.
447 447
 	 * @return array
448 448
 	 */
449
-	protected function get_item_data( $cart_item ) {
449
+	protected function get_item_data($cart_item) {
450 450
 		/**
451 451
 		 * Filters cart item data.
452 452
 		 *
@@ -458,8 +458,8 @@  discard block
 block discarded – undo
458 458
 		 * @param array $cart_item Cart item array.
459 459
 		 * @return array
460 460
 		 */
461
-		$item_data = apply_filters( 'woocommerce_get_item_data', array(), $cart_item );
462
-		return array_map( [ $this, 'format_item_data_element' ], $item_data );
461
+		$item_data = apply_filters('woocommerce_get_item_data', array(), $cart_item);
462
+		return array_map([$this, 'format_item_data_element'], $item_data);
463 463
 	}
464 464
 
465 465
 	/**
@@ -468,10 +468,10 @@  discard block
 block discarded – undo
468 468
 	 * @param array $item_data_element Individual element of a cart item data.
469 469
 	 * @return array
470 470
 	 */
471
-	protected function format_item_data_element( $item_data_element ) {
472
-		if ( array_key_exists( '__experimental_woocommerce_blocks_hidden', $item_data_element ) ) {
471
+	protected function format_item_data_element($item_data_element) {
472
+		if (array_key_exists('__experimental_woocommerce_blocks_hidden', $item_data_element)) {
473 473
 			$item_data_element['hidden'] = $item_data_element['__experimental_woocommerce_blocks_hidden'];
474 474
 		}
475
-		return array_map( 'wp_strip_all_tags', $item_data_element );
475
+		return array_map('wp_strip_all_tags', $item_data_element);
476 476
 	}
477 477
 }
Please login to merge, or discard this patch.
packages/woocommerce-blocks/src/StoreApi/Schemas/V1/AbstractSchema.php 2 patches
Indentation   +375 added lines, -375 removed lines patch added patch discarded remove patch
@@ -10,379 +10,379 @@
 block discarded – undo
10 10
  * For REST Route Schemas
11 11
  */
12 12
 abstract class AbstractSchema {
13
-	/**
14
-	 * The schema item name.
15
-	 *
16
-	 * @var string
17
-	 */
18
-	protected $title = 'Schema';
19
-
20
-	/**
21
-	 * Rest extend instance.
22
-	 *
23
-	 * @var ExtendSchema
24
-	 */
25
-	protected $extend;
26
-
27
-	/**
28
-	 * Schema Controller instance.
29
-	 *
30
-	 * @var SchemaController
31
-	 */
32
-	protected $controller;
33
-
34
-	/**
35
-	 * Extending key that gets added to endpoint.
36
-	 *
37
-	 * @var string
38
-	 */
39
-	const EXTENDING_KEY = 'extensions';
40
-
41
-	/**
42
-	 * Constructor.
43
-	 *
44
-	 * @param ExtendSchema     $extend Rest Extending instance.
45
-	 * @param SchemaController $controller Schema Controller instance.
46
-	 */
47
-	public function __construct( ExtendSchema $extend, SchemaController $controller ) {
48
-		$this->extend     = $extend;
49
-		$this->controller = $controller;
50
-	}
51
-
52
-	/**
53
-	 * Returns the full item schema.
54
-	 *
55
-	 * @return array
56
-	 */
57
-	public function get_item_schema() {
58
-		return array(
59
-			'$schema'    => 'http://json-schema.org/draft-04/schema#',
60
-			'title'      => $this->title,
61
-			'type'       => 'object',
62
-			'properties' => $this->get_properties(),
63
-		);
64
-	}
65
-
66
-	/**
67
-	 * Return schema properties.
68
-	 *
69
-	 * @return array
70
-	 */
71
-	abstract public function get_properties();
72
-
73
-	/**
74
-	 * Recursive removal of arg_options.
75
-	 *
76
-	 * @param array $properties Schema properties.
77
-	 */
78
-	protected function remove_arg_options( $properties ) {
79
-		return array_map(
80
-			function( $property ) {
81
-				if ( isset( $property['properties'] ) ) {
82
-					$property['properties'] = $this->remove_arg_options( $property['properties'] );
83
-				} elseif ( isset( $property['items']['properties'] ) ) {
84
-					$property['items']['properties'] = $this->remove_arg_options( $property['items']['properties'] );
85
-				}
86
-				unset( $property['arg_options'] );
87
-				return $property;
88
-			},
89
-			(array) $properties
90
-		);
91
-	}
92
-
93
-	/**
94
-	 * Returns the public schema.
95
-	 *
96
-	 * @return array
97
-	 */
98
-	public function get_public_item_schema() {
99
-		$schema = $this->get_item_schema();
100
-
101
-		if ( isset( $schema['properties'] ) ) {
102
-			$schema['properties'] = $this->remove_arg_options( $schema['properties'] );
103
-		}
104
-
105
-		return $schema;
106
-	}
107
-
108
-	/**
109
-	 * Returns extended data for a specific endpoint.
110
-	 *
111
-	 * @param string $endpoint The endpoint identifier.
112
-	 * @param array  ...$passed_args An array of arguments to be passed to callbacks.
113
-	 * @return object the data that will get added.
114
-	 */
115
-	protected function get_extended_data( $endpoint, ...$passed_args ) {
116
-		return $this->extend->get_endpoint_data( $endpoint, $passed_args );
117
-	}
118
-
119
-	/**
120
-	 * Gets an array of schema defaults recursively.
121
-	 *
122
-	 * @param array $properties Schema property data.
123
-	 * @return array Array of defaults, pulled from arg_options
124
-	 */
125
-	protected function get_recursive_schema_property_defaults( $properties ) {
126
-		$defaults = [];
127
-
128
-		foreach ( $properties as $property_key => $property_value ) {
129
-			if ( isset( $property_value['arg_options']['default'] ) ) {
130
-				$defaults[ $property_key ] = $property_value['arg_options']['default'];
131
-			} elseif ( isset( $property_value['properties'] ) ) {
132
-				$defaults[ $property_key ] = $this->get_recursive_schema_property_defaults( $property_value['properties'] );
133
-			}
134
-		}
135
-
136
-		return $defaults;
137
-	}
138
-
139
-	/**
140
-	 * Gets a function that validates recursively.
141
-	 *
142
-	 * @param array $properties Schema property data.
143
-	 * @return function Anonymous validation callback.
144
-	 */
145
-	protected function get_recursive_validate_callback( $properties ) {
146
-		/**
147
-		 * Validate a request argument based on details registered to the route.
148
-		 *
149
-		 * @param mixed            $values
150
-		 * @param \WP_REST_Request $request
151
-		 * @param string           $param
152
-		 * @return true|\WP_Error
153
-		 */
154
-		return function ( $values, $request, $param ) use ( $properties ) {
155
-			foreach ( $properties as $property_key => $property_value ) {
156
-				$current_value = isset( $values[ $property_key ] ) ? $values[ $property_key ] : null;
157
-
158
-				if ( isset( $property_value['arg_options']['validate_callback'] ) ) {
159
-					$callback = $property_value['arg_options']['validate_callback'];
160
-					$result   = is_callable( $callback ) ? $callback( $current_value, $request, $param ) : false;
161
-				} else {
162
-					$result = rest_validate_value_from_schema( $current_value, $property_value, $param . ' > ' . $property_key );
163
-				}
164
-
165
-				if ( ! $result || is_wp_error( $result ) ) {
166
-					return $result;
167
-				}
168
-
169
-				if ( isset( $property_value['properties'] ) ) {
170
-					$validate_callback = $this->get_recursive_validate_callback( $property_value['properties'] );
171
-					return $validate_callback( $current_value, $request, $param . ' > ' . $property_key );
172
-				}
173
-			}
174
-
175
-			return true;
176
-		};
177
-	}
178
-
179
-	/**
180
-	 * Gets a function that sanitizes recursively.
181
-	 *
182
-	 * @param array $properties Schema property data.
183
-	 * @return function Anonymous validation callback.
184
-	 */
185
-	protected function get_recursive_sanitize_callback( $properties ) {
186
-		/**
187
-		 * Validate a request argument based on details registered to the route.
188
-		 *
189
-		 * @param mixed            $values
190
-		 * @param \WP_REST_Request $request
191
-		 * @param string           $param
192
-		 * @return true|\WP_Error
193
-		 */
194
-		return function ( $values, $request, $param ) use ( $properties ) {
195
-			$sanitized_values = [];
196
-
197
-			foreach ( $properties as $property_key => $property_value ) {
198
-				$current_value = isset( $values[ $property_key ] ) ? $values[ $property_key ] : null;
199
-
200
-				if ( isset( $property_value['arg_options']['sanitize_callback'] ) ) {
201
-					$callback      = $property_value['arg_options']['sanitize_callback'];
202
-					$current_value = is_callable( $callback ) ? $callback( $current_value, $request, $param ) : $current_value;
203
-				} else {
204
-					$current_value = rest_sanitize_value_from_schema( $current_value, $property_value, $param . ' > ' . $property_key );
205
-				}
206
-
207
-				// If sanitization failed, return the WP_Error object straight away.
208
-				if ( is_wp_error( $current_value ) ) {
209
-					return $current_value;
210
-				}
211
-
212
-				if ( isset( $property_value['properties'] ) ) {
213
-					$sanitize_callback                 = $this->get_recursive_sanitize_callback( $property_value['properties'] );
214
-					$sanitized_values[ $property_key ] = $sanitize_callback( $current_value, $request, $param . ' > ' . $property_key );
215
-				} else {
216
-					$sanitized_values[ $property_key ] = $current_value;
217
-				}
218
-			}
219
-
220
-			return $sanitized_values;
221
-		};
222
-	}
223
-
224
-	/**
225
-	 * Returns extended schema for a specific endpoint.
226
-	 *
227
-	 * @param string $endpoint The endpoint identifer.
228
-	 * @param array  ...$passed_args An array of arguments to be passed to callbacks.
229
-	 * @return array the data that will get added.
230
-	 */
231
-	protected function get_extended_schema( $endpoint, ...$passed_args ) {
232
-		$extended_schema = $this->extend->get_endpoint_schema( $endpoint, $passed_args );
233
-		$defaults        = $this->get_recursive_schema_property_defaults( $extended_schema );
234
-
235
-		return [
236
-			'type'        => 'object',
237
-			'context'     => [ 'view', 'edit' ],
238
-			'arg_options' => [
239
-				'default'           => $defaults,
240
-				'validate_callback' => $this->get_recursive_validate_callback( $extended_schema ),
241
-				'sanitize_callback' => $this->get_recursive_sanitize_callback( $extended_schema ),
242
-			],
243
-			'properties'  => $extended_schema,
244
-		];
245
-	}
246
-
247
-	/**
248
-	 * Apply a schema get_item_response callback to an array of items and return the result.
249
-	 *
250
-	 * @param AbstractSchema $schema Schema class instance.
251
-	 * @param array          $items Array of items.
252
-	 * @return array Array of values from the callback function.
253
-	 */
254
-	protected function get_item_responses_from_schema( AbstractSchema $schema, $items ) {
255
-		$items = array_filter( $items );
256
-
257
-		if ( empty( $items ) ) {
258
-			return [];
259
-		}
260
-
261
-		return array_values( array_map( [ $schema, 'get_item_response' ], $items ) );
262
-	}
263
-
264
-	/**
265
-	 * Retrieves an array of endpoint arguments from the item schema for the controller.
266
-	 *
267
-	 * @uses rest_get_endpoint_args_for_schema()
268
-	 * @param string $method Optional. HTTP method of the request.
269
-	 * @return array Endpoint arguments.
270
-	 */
271
-	public function get_endpoint_args_for_item_schema( $method = \WP_REST_Server::CREATABLE ) {
272
-		$schema        = $this->get_item_schema();
273
-		$endpoint_args = rest_get_endpoint_args_for_schema( $schema, $method );
274
-		$endpoint_args = $this->remove_arg_options( $endpoint_args );
275
-		return $endpoint_args;
276
-	}
277
-
278
-
279
-	/**
280
-	 * Force all schema properties to be readonly.
281
-	 *
282
-	 * @param array $properties Schema.
283
-	 * @return array Updated schema.
284
-	 */
285
-	protected function force_schema_readonly( $properties ) {
286
-		return array_map(
287
-			function( $property ) {
288
-				$property['readonly'] = true;
289
-				if ( isset( $property['items']['properties'] ) ) {
290
-					$property['items']['properties'] = $this->force_schema_readonly( $property['items']['properties'] );
291
-				}
292
-				return $property;
293
-			},
294
-			(array) $properties
295
-		);
296
-	}
297
-
298
-	/**
299
-	 * Returns consistent currency schema used across endpoints for prices.
300
-	 *
301
-	 * @return array
302
-	 */
303
-	protected function get_store_currency_properties() {
304
-		return [
305
-			'currency_code'               => [
306
-				'description' => __( 'Currency code (in ISO format) for returned prices.', 'woocommerce' ),
307
-				'type'        => 'string',
308
-				'context'     => [ 'view', 'edit' ],
309
-				'readonly'    => true,
310
-			],
311
-			'currency_symbol'             => [
312
-				'description' => __( 'Currency symbol for the currency which can be used to format returned prices.', 'woocommerce' ),
313
-				'type'        => 'string',
314
-				'context'     => [ 'view', 'edit' ],
315
-				'readonly'    => true,
316
-			],
317
-			'currency_minor_unit'         => [
318
-				'description' => __( 'Currency minor unit (number of digits after the decimal separator) for returned prices.', 'woocommerce' ),
319
-				'type'        => 'integer',
320
-				'context'     => [ 'view', 'edit' ],
321
-				'readonly'    => true,
322
-			],
323
-			'currency_decimal_separator'  => array(
324
-				'description' => __( 'Decimal separator for the currency which can be used to format returned prices.', 'woocommerce' ),
325
-				'type'        => 'string',
326
-				'context'     => array( 'view', 'edit' ),
327
-				'readonly'    => true,
328
-			),
329
-			'currency_thousand_separator' => array(
330
-				'description' => __( 'Thousand separator for the currency which can be used to format returned prices.', 'woocommerce' ),
331
-				'type'        => 'string',
332
-				'context'     => array( 'view', 'edit' ),
333
-				'readonly'    => true,
334
-			),
335
-			'currency_prefix'             => array(
336
-				'description' => __( 'Price prefix for the currency which can be used to format returned prices.', 'woocommerce' ),
337
-				'type'        => 'string',
338
-				'context'     => array( 'view', 'edit' ),
339
-				'readonly'    => true,
340
-			),
341
-			'currency_suffix'             => array(
342
-				'description' => __( 'Price prefix for the currency which can be used to format returned prices.', 'woocommerce' ),
343
-				'type'        => 'string',
344
-				'context'     => array( 'view', 'edit' ),
345
-				'readonly'    => true,
346
-			),
347
-		];
348
-	}
349
-
350
-	/**
351
-	 * Adds currency data to an array of monetary values.
352
-	 *
353
-	 * @param array $values Monetary amounts.
354
-	 * @return array Monetary amounts with currency data appended.
355
-	 */
356
-	protected function prepare_currency_response( $values ) {
357
-		return $this->extend->get_formatter( 'currency' )->format( $values );
358
-	}
359
-
360
-	/**
361
-	 * Convert monetary values from WooCommerce to string based integers, using
362
-	 * the smallest unit of a currency.
363
-	 *
364
-	 * @param string|float $amount Monetary amount with decimals.
365
-	 * @param int          $decimals Number of decimals the amount is formatted with.
366
-	 * @param int          $rounding_mode Defaults to the PHP_ROUND_HALF_UP constant.
367
-	 * @return string      The new amount.
368
-	 */
369
-	protected function prepare_money_response( $amount, $decimals = 2, $rounding_mode = PHP_ROUND_HALF_UP ) {
370
-		return $this->extend->get_formatter( 'money' )->format(
371
-			$amount,
372
-			[
373
-				'decimals'      => $decimals,
374
-				'rounding_mode' => $rounding_mode,
375
-			]
376
-		);
377
-	}
378
-
379
-	/**
380
-	 * Prepares HTML based content, such as post titles and content, for the API response.
381
-	 *
382
-	 * @param string|array $response Data to format.
383
-	 * @return string|array Formatted data.
384
-	 */
385
-	protected function prepare_html_response( $response ) {
386
-		return $this->extend->get_formatter( 'html' )->format( $response );
387
-	}
13
+    /**
14
+     * The schema item name.
15
+     *
16
+     * @var string
17
+     */
18
+    protected $title = 'Schema';
19
+
20
+    /**
21
+     * Rest extend instance.
22
+     *
23
+     * @var ExtendSchema
24
+     */
25
+    protected $extend;
26
+
27
+    /**
28
+     * Schema Controller instance.
29
+     *
30
+     * @var SchemaController
31
+     */
32
+    protected $controller;
33
+
34
+    /**
35
+     * Extending key that gets added to endpoint.
36
+     *
37
+     * @var string
38
+     */
39
+    const EXTENDING_KEY = 'extensions';
40
+
41
+    /**
42
+     * Constructor.
43
+     *
44
+     * @param ExtendSchema     $extend Rest Extending instance.
45
+     * @param SchemaController $controller Schema Controller instance.
46
+     */
47
+    public function __construct( ExtendSchema $extend, SchemaController $controller ) {
48
+        $this->extend     = $extend;
49
+        $this->controller = $controller;
50
+    }
51
+
52
+    /**
53
+     * Returns the full item schema.
54
+     *
55
+     * @return array
56
+     */
57
+    public function get_item_schema() {
58
+        return array(
59
+            '$schema'    => 'http://json-schema.org/draft-04/schema#',
60
+            'title'      => $this->title,
61
+            'type'       => 'object',
62
+            'properties' => $this->get_properties(),
63
+        );
64
+    }
65
+
66
+    /**
67
+     * Return schema properties.
68
+     *
69
+     * @return array
70
+     */
71
+    abstract public function get_properties();
72
+
73
+    /**
74
+     * Recursive removal of arg_options.
75
+     *
76
+     * @param array $properties Schema properties.
77
+     */
78
+    protected function remove_arg_options( $properties ) {
79
+        return array_map(
80
+            function( $property ) {
81
+                if ( isset( $property['properties'] ) ) {
82
+                    $property['properties'] = $this->remove_arg_options( $property['properties'] );
83
+                } elseif ( isset( $property['items']['properties'] ) ) {
84
+                    $property['items']['properties'] = $this->remove_arg_options( $property['items']['properties'] );
85
+                }
86
+                unset( $property['arg_options'] );
87
+                return $property;
88
+            },
89
+            (array) $properties
90
+        );
91
+    }
92
+
93
+    /**
94
+     * Returns the public schema.
95
+     *
96
+     * @return array
97
+     */
98
+    public function get_public_item_schema() {
99
+        $schema = $this->get_item_schema();
100
+
101
+        if ( isset( $schema['properties'] ) ) {
102
+            $schema['properties'] = $this->remove_arg_options( $schema['properties'] );
103
+        }
104
+
105
+        return $schema;
106
+    }
107
+
108
+    /**
109
+     * Returns extended data for a specific endpoint.
110
+     *
111
+     * @param string $endpoint The endpoint identifier.
112
+     * @param array  ...$passed_args An array of arguments to be passed to callbacks.
113
+     * @return object the data that will get added.
114
+     */
115
+    protected function get_extended_data( $endpoint, ...$passed_args ) {
116
+        return $this->extend->get_endpoint_data( $endpoint, $passed_args );
117
+    }
118
+
119
+    /**
120
+     * Gets an array of schema defaults recursively.
121
+     *
122
+     * @param array $properties Schema property data.
123
+     * @return array Array of defaults, pulled from arg_options
124
+     */
125
+    protected function get_recursive_schema_property_defaults( $properties ) {
126
+        $defaults = [];
127
+
128
+        foreach ( $properties as $property_key => $property_value ) {
129
+            if ( isset( $property_value['arg_options']['default'] ) ) {
130
+                $defaults[ $property_key ] = $property_value['arg_options']['default'];
131
+            } elseif ( isset( $property_value['properties'] ) ) {
132
+                $defaults[ $property_key ] = $this->get_recursive_schema_property_defaults( $property_value['properties'] );
133
+            }
134
+        }
135
+
136
+        return $defaults;
137
+    }
138
+
139
+    /**
140
+     * Gets a function that validates recursively.
141
+     *
142
+     * @param array $properties Schema property data.
143
+     * @return function Anonymous validation callback.
144
+     */
145
+    protected function get_recursive_validate_callback( $properties ) {
146
+        /**
147
+         * Validate a request argument based on details registered to the route.
148
+         *
149
+         * @param mixed            $values
150
+         * @param \WP_REST_Request $request
151
+         * @param string           $param
152
+         * @return true|\WP_Error
153
+         */
154
+        return function ( $values, $request, $param ) use ( $properties ) {
155
+            foreach ( $properties as $property_key => $property_value ) {
156
+                $current_value = isset( $values[ $property_key ] ) ? $values[ $property_key ] : null;
157
+
158
+                if ( isset( $property_value['arg_options']['validate_callback'] ) ) {
159
+                    $callback = $property_value['arg_options']['validate_callback'];
160
+                    $result   = is_callable( $callback ) ? $callback( $current_value, $request, $param ) : false;
161
+                } else {
162
+                    $result = rest_validate_value_from_schema( $current_value, $property_value, $param . ' > ' . $property_key );
163
+                }
164
+
165
+                if ( ! $result || is_wp_error( $result ) ) {
166
+                    return $result;
167
+                }
168
+
169
+                if ( isset( $property_value['properties'] ) ) {
170
+                    $validate_callback = $this->get_recursive_validate_callback( $property_value['properties'] );
171
+                    return $validate_callback( $current_value, $request, $param . ' > ' . $property_key );
172
+                }
173
+            }
174
+
175
+            return true;
176
+        };
177
+    }
178
+
179
+    /**
180
+     * Gets a function that sanitizes recursively.
181
+     *
182
+     * @param array $properties Schema property data.
183
+     * @return function Anonymous validation callback.
184
+     */
185
+    protected function get_recursive_sanitize_callback( $properties ) {
186
+        /**
187
+         * Validate a request argument based on details registered to the route.
188
+         *
189
+         * @param mixed            $values
190
+         * @param \WP_REST_Request $request
191
+         * @param string           $param
192
+         * @return true|\WP_Error
193
+         */
194
+        return function ( $values, $request, $param ) use ( $properties ) {
195
+            $sanitized_values = [];
196
+
197
+            foreach ( $properties as $property_key => $property_value ) {
198
+                $current_value = isset( $values[ $property_key ] ) ? $values[ $property_key ] : null;
199
+
200
+                if ( isset( $property_value['arg_options']['sanitize_callback'] ) ) {
201
+                    $callback      = $property_value['arg_options']['sanitize_callback'];
202
+                    $current_value = is_callable( $callback ) ? $callback( $current_value, $request, $param ) : $current_value;
203
+                } else {
204
+                    $current_value = rest_sanitize_value_from_schema( $current_value, $property_value, $param . ' > ' . $property_key );
205
+                }
206
+
207
+                // If sanitization failed, return the WP_Error object straight away.
208
+                if ( is_wp_error( $current_value ) ) {
209
+                    return $current_value;
210
+                }
211
+
212
+                if ( isset( $property_value['properties'] ) ) {
213
+                    $sanitize_callback                 = $this->get_recursive_sanitize_callback( $property_value['properties'] );
214
+                    $sanitized_values[ $property_key ] = $sanitize_callback( $current_value, $request, $param . ' > ' . $property_key );
215
+                } else {
216
+                    $sanitized_values[ $property_key ] = $current_value;
217
+                }
218
+            }
219
+
220
+            return $sanitized_values;
221
+        };
222
+    }
223
+
224
+    /**
225
+     * Returns extended schema for a specific endpoint.
226
+     *
227
+     * @param string $endpoint The endpoint identifer.
228
+     * @param array  ...$passed_args An array of arguments to be passed to callbacks.
229
+     * @return array the data that will get added.
230
+     */
231
+    protected function get_extended_schema( $endpoint, ...$passed_args ) {
232
+        $extended_schema = $this->extend->get_endpoint_schema( $endpoint, $passed_args );
233
+        $defaults        = $this->get_recursive_schema_property_defaults( $extended_schema );
234
+
235
+        return [
236
+            'type'        => 'object',
237
+            'context'     => [ 'view', 'edit' ],
238
+            'arg_options' => [
239
+                'default'           => $defaults,
240
+                'validate_callback' => $this->get_recursive_validate_callback( $extended_schema ),
241
+                'sanitize_callback' => $this->get_recursive_sanitize_callback( $extended_schema ),
242
+            ],
243
+            'properties'  => $extended_schema,
244
+        ];
245
+    }
246
+
247
+    /**
248
+     * Apply a schema get_item_response callback to an array of items and return the result.
249
+     *
250
+     * @param AbstractSchema $schema Schema class instance.
251
+     * @param array          $items Array of items.
252
+     * @return array Array of values from the callback function.
253
+     */
254
+    protected function get_item_responses_from_schema( AbstractSchema $schema, $items ) {
255
+        $items = array_filter( $items );
256
+
257
+        if ( empty( $items ) ) {
258
+            return [];
259
+        }
260
+
261
+        return array_values( array_map( [ $schema, 'get_item_response' ], $items ) );
262
+    }
263
+
264
+    /**
265
+     * Retrieves an array of endpoint arguments from the item schema for the controller.
266
+     *
267
+     * @uses rest_get_endpoint_args_for_schema()
268
+     * @param string $method Optional. HTTP method of the request.
269
+     * @return array Endpoint arguments.
270
+     */
271
+    public function get_endpoint_args_for_item_schema( $method = \WP_REST_Server::CREATABLE ) {
272
+        $schema        = $this->get_item_schema();
273
+        $endpoint_args = rest_get_endpoint_args_for_schema( $schema, $method );
274
+        $endpoint_args = $this->remove_arg_options( $endpoint_args );
275
+        return $endpoint_args;
276
+    }
277
+
278
+
279
+    /**
280
+     * Force all schema properties to be readonly.
281
+     *
282
+     * @param array $properties Schema.
283
+     * @return array Updated schema.
284
+     */
285
+    protected function force_schema_readonly( $properties ) {
286
+        return array_map(
287
+            function( $property ) {
288
+                $property['readonly'] = true;
289
+                if ( isset( $property['items']['properties'] ) ) {
290
+                    $property['items']['properties'] = $this->force_schema_readonly( $property['items']['properties'] );
291
+                }
292
+                return $property;
293
+            },
294
+            (array) $properties
295
+        );
296
+    }
297
+
298
+    /**
299
+     * Returns consistent currency schema used across endpoints for prices.
300
+     *
301
+     * @return array
302
+     */
303
+    protected function get_store_currency_properties() {
304
+        return [
305
+            'currency_code'               => [
306
+                'description' => __( 'Currency code (in ISO format) for returned prices.', 'woocommerce' ),
307
+                'type'        => 'string',
308
+                'context'     => [ 'view', 'edit' ],
309
+                'readonly'    => true,
310
+            ],
311
+            'currency_symbol'             => [
312
+                'description' => __( 'Currency symbol for the currency which can be used to format returned prices.', 'woocommerce' ),
313
+                'type'        => 'string',
314
+                'context'     => [ 'view', 'edit' ],
315
+                'readonly'    => true,
316
+            ],
317
+            'currency_minor_unit'         => [
318
+                'description' => __( 'Currency minor unit (number of digits after the decimal separator) for returned prices.', 'woocommerce' ),
319
+                'type'        => 'integer',
320
+                'context'     => [ 'view', 'edit' ],
321
+                'readonly'    => true,
322
+            ],
323
+            'currency_decimal_separator'  => array(
324
+                'description' => __( 'Decimal separator for the currency which can be used to format returned prices.', 'woocommerce' ),
325
+                'type'        => 'string',
326
+                'context'     => array( 'view', 'edit' ),
327
+                'readonly'    => true,
328
+            ),
329
+            'currency_thousand_separator' => array(
330
+                'description' => __( 'Thousand separator for the currency which can be used to format returned prices.', 'woocommerce' ),
331
+                'type'        => 'string',
332
+                'context'     => array( 'view', 'edit' ),
333
+                'readonly'    => true,
334
+            ),
335
+            'currency_prefix'             => array(
336
+                'description' => __( 'Price prefix for the currency which can be used to format returned prices.', 'woocommerce' ),
337
+                'type'        => 'string',
338
+                'context'     => array( 'view', 'edit' ),
339
+                'readonly'    => true,
340
+            ),
341
+            'currency_suffix'             => array(
342
+                'description' => __( 'Price prefix for the currency which can be used to format returned prices.', 'woocommerce' ),
343
+                'type'        => 'string',
344
+                'context'     => array( 'view', 'edit' ),
345
+                'readonly'    => true,
346
+            ),
347
+        ];
348
+    }
349
+
350
+    /**
351
+     * Adds currency data to an array of monetary values.
352
+     *
353
+     * @param array $values Monetary amounts.
354
+     * @return array Monetary amounts with currency data appended.
355
+     */
356
+    protected function prepare_currency_response( $values ) {
357
+        return $this->extend->get_formatter( 'currency' )->format( $values );
358
+    }
359
+
360
+    /**
361
+     * Convert monetary values from WooCommerce to string based integers, using
362
+     * the smallest unit of a currency.
363
+     *
364
+     * @param string|float $amount Monetary amount with decimals.
365
+     * @param int          $decimals Number of decimals the amount is formatted with.
366
+     * @param int          $rounding_mode Defaults to the PHP_ROUND_HALF_UP constant.
367
+     * @return string      The new amount.
368
+     */
369
+    protected function prepare_money_response( $amount, $decimals = 2, $rounding_mode = PHP_ROUND_HALF_UP ) {
370
+        return $this->extend->get_formatter( 'money' )->format(
371
+            $amount,
372
+            [
373
+                'decimals'      => $decimals,
374
+                'rounding_mode' => $rounding_mode,
375
+            ]
376
+        );
377
+    }
378
+
379
+    /**
380
+     * Prepares HTML based content, such as post titles and content, for the API response.
381
+     *
382
+     * @param string|array $response Data to format.
383
+     * @return string|array Formatted data.
384
+     */
385
+    protected function prepare_html_response( $response ) {
386
+        return $this->extend->get_formatter( 'html' )->format( $response );
387
+    }
388 388
 }
Please login to merge, or discard this patch.
Spacing   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 	 * @param ExtendSchema     $extend Rest Extending instance.
45 45
 	 * @param SchemaController $controller Schema Controller instance.
46 46
 	 */
47
-	public function __construct( ExtendSchema $extend, SchemaController $controller ) {
47
+	public function __construct(ExtendSchema $extend, SchemaController $controller) {
48 48
 		$this->extend     = $extend;
49 49
 		$this->controller = $controller;
50 50
 	}
@@ -75,15 +75,15 @@  discard block
 block discarded – undo
75 75
 	 *
76 76
 	 * @param array $properties Schema properties.
77 77
 	 */
78
-	protected function remove_arg_options( $properties ) {
78
+	protected function remove_arg_options($properties) {
79 79
 		return array_map(
80
-			function( $property ) {
81
-				if ( isset( $property['properties'] ) ) {
82
-					$property['properties'] = $this->remove_arg_options( $property['properties'] );
83
-				} elseif ( isset( $property['items']['properties'] ) ) {
84
-					$property['items']['properties'] = $this->remove_arg_options( $property['items']['properties'] );
80
+			function($property) {
81
+				if (isset($property['properties'])) {
82
+					$property['properties'] = $this->remove_arg_options($property['properties']);
83
+				} elseif (isset($property['items']['properties'])) {
84
+					$property['items']['properties'] = $this->remove_arg_options($property['items']['properties']);
85 85
 				}
86
-				unset( $property['arg_options'] );
86
+				unset($property['arg_options']);
87 87
 				return $property;
88 88
 			},
89 89
 			(array) $properties
@@ -98,8 +98,8 @@  discard block
 block discarded – undo
98 98
 	public function get_public_item_schema() {
99 99
 		$schema = $this->get_item_schema();
100 100
 
101
-		if ( isset( $schema['properties'] ) ) {
102
-			$schema['properties'] = $this->remove_arg_options( $schema['properties'] );
101
+		if (isset($schema['properties'])) {
102
+			$schema['properties'] = $this->remove_arg_options($schema['properties']);
103 103
 		}
104 104
 
105 105
 		return $schema;
@@ -112,8 +112,8 @@  discard block
 block discarded – undo
112 112
 	 * @param array  ...$passed_args An array of arguments to be passed to callbacks.
113 113
 	 * @return object the data that will get added.
114 114
 	 */
115
-	protected function get_extended_data( $endpoint, ...$passed_args ) {
116
-		return $this->extend->get_endpoint_data( $endpoint, $passed_args );
115
+	protected function get_extended_data($endpoint, ...$passed_args) {
116
+		return $this->extend->get_endpoint_data($endpoint, $passed_args);
117 117
 	}
118 118
 
119 119
 	/**
@@ -122,14 +122,14 @@  discard block
 block discarded – undo
122 122
 	 * @param array $properties Schema property data.
123 123
 	 * @return array Array of defaults, pulled from arg_options
124 124
 	 */
125
-	protected function get_recursive_schema_property_defaults( $properties ) {
125
+	protected function get_recursive_schema_property_defaults($properties) {
126 126
 		$defaults = [];
127 127
 
128
-		foreach ( $properties as $property_key => $property_value ) {
129
-			if ( isset( $property_value['arg_options']['default'] ) ) {
130
-				$defaults[ $property_key ] = $property_value['arg_options']['default'];
131
-			} elseif ( isset( $property_value['properties'] ) ) {
132
-				$defaults[ $property_key ] = $this->get_recursive_schema_property_defaults( $property_value['properties'] );
128
+		foreach ($properties as $property_key => $property_value) {
129
+			if (isset($property_value['arg_options']['default'])) {
130
+				$defaults[$property_key] = $property_value['arg_options']['default'];
131
+			} elseif (isset($property_value['properties'])) {
132
+				$defaults[$property_key] = $this->get_recursive_schema_property_defaults($property_value['properties']);
133 133
 			}
134 134
 		}
135 135
 
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 	 * @param array $properties Schema property data.
143 143
 	 * @return function Anonymous validation callback.
144 144
 	 */
145
-	protected function get_recursive_validate_callback( $properties ) {
145
+	protected function get_recursive_validate_callback($properties) {
146 146
 		/**
147 147
 		 * Validate a request argument based on details registered to the route.
148 148
 		 *
@@ -151,24 +151,24 @@  discard block
 block discarded – undo
151 151
 		 * @param string           $param
152 152
 		 * @return true|\WP_Error
153 153
 		 */
154
-		return function ( $values, $request, $param ) use ( $properties ) {
155
-			foreach ( $properties as $property_key => $property_value ) {
156
-				$current_value = isset( $values[ $property_key ] ) ? $values[ $property_key ] : null;
154
+		return function($values, $request, $param) use ($properties) {
155
+			foreach ($properties as $property_key => $property_value) {
156
+				$current_value = isset($values[$property_key]) ? $values[$property_key] : null;
157 157
 
158
-				if ( isset( $property_value['arg_options']['validate_callback'] ) ) {
158
+				if (isset($property_value['arg_options']['validate_callback'])) {
159 159
 					$callback = $property_value['arg_options']['validate_callback'];
160
-					$result   = is_callable( $callback ) ? $callback( $current_value, $request, $param ) : false;
160
+					$result   = is_callable($callback) ? $callback($current_value, $request, $param) : false;
161 161
 				} else {
162
-					$result = rest_validate_value_from_schema( $current_value, $property_value, $param . ' > ' . $property_key );
162
+					$result = rest_validate_value_from_schema($current_value, $property_value, $param . ' > ' . $property_key);
163 163
 				}
164 164
 
165
-				if ( ! $result || is_wp_error( $result ) ) {
165
+				if (!$result || is_wp_error($result)) {
166 166
 					return $result;
167 167
 				}
168 168
 
169
-				if ( isset( $property_value['properties'] ) ) {
170
-					$validate_callback = $this->get_recursive_validate_callback( $property_value['properties'] );
171
-					return $validate_callback( $current_value, $request, $param . ' > ' . $property_key );
169
+				if (isset($property_value['properties'])) {
170
+					$validate_callback = $this->get_recursive_validate_callback($property_value['properties']);
171
+					return $validate_callback($current_value, $request, $param . ' > ' . $property_key);
172 172
 				}
173 173
 			}
174 174
 
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 	 * @param array $properties Schema property data.
183 183
 	 * @return function Anonymous validation callback.
184 184
 	 */
185
-	protected function get_recursive_sanitize_callback( $properties ) {
185
+	protected function get_recursive_sanitize_callback($properties) {
186 186
 		/**
187 187
 		 * Validate a request argument based on details registered to the route.
188 188
 		 *
@@ -191,29 +191,29 @@  discard block
 block discarded – undo
191 191
 		 * @param string           $param
192 192
 		 * @return true|\WP_Error
193 193
 		 */
194
-		return function ( $values, $request, $param ) use ( $properties ) {
194
+		return function($values, $request, $param) use ($properties) {
195 195
 			$sanitized_values = [];
196 196
 
197
-			foreach ( $properties as $property_key => $property_value ) {
198
-				$current_value = isset( $values[ $property_key ] ) ? $values[ $property_key ] : null;
197
+			foreach ($properties as $property_key => $property_value) {
198
+				$current_value = isset($values[$property_key]) ? $values[$property_key] : null;
199 199
 
200
-				if ( isset( $property_value['arg_options']['sanitize_callback'] ) ) {
200
+				if (isset($property_value['arg_options']['sanitize_callback'])) {
201 201
 					$callback      = $property_value['arg_options']['sanitize_callback'];
202
-					$current_value = is_callable( $callback ) ? $callback( $current_value, $request, $param ) : $current_value;
202
+					$current_value = is_callable($callback) ? $callback($current_value, $request, $param) : $current_value;
203 203
 				} else {
204
-					$current_value = rest_sanitize_value_from_schema( $current_value, $property_value, $param . ' > ' . $property_key );
204
+					$current_value = rest_sanitize_value_from_schema($current_value, $property_value, $param . ' > ' . $property_key);
205 205
 				}
206 206
 
207 207
 				// If sanitization failed, return the WP_Error object straight away.
208
-				if ( is_wp_error( $current_value ) ) {
208
+				if (is_wp_error($current_value)) {
209 209
 					return $current_value;
210 210
 				}
211 211
 
212
-				if ( isset( $property_value['properties'] ) ) {
213
-					$sanitize_callback                 = $this->get_recursive_sanitize_callback( $property_value['properties'] );
214
-					$sanitized_values[ $property_key ] = $sanitize_callback( $current_value, $request, $param . ' > ' . $property_key );
212
+				if (isset($property_value['properties'])) {
213
+					$sanitize_callback                 = $this->get_recursive_sanitize_callback($property_value['properties']);
214
+					$sanitized_values[$property_key] = $sanitize_callback($current_value, $request, $param . ' > ' . $property_key);
215 215
 				} else {
216
-					$sanitized_values[ $property_key ] = $current_value;
216
+					$sanitized_values[$property_key] = $current_value;
217 217
 				}
218 218
 			}
219 219
 
@@ -228,17 +228,17 @@  discard block
 block discarded – undo
228 228
 	 * @param array  ...$passed_args An array of arguments to be passed to callbacks.
229 229
 	 * @return array the data that will get added.
230 230
 	 */
231
-	protected function get_extended_schema( $endpoint, ...$passed_args ) {
232
-		$extended_schema = $this->extend->get_endpoint_schema( $endpoint, $passed_args );
233
-		$defaults        = $this->get_recursive_schema_property_defaults( $extended_schema );
231
+	protected function get_extended_schema($endpoint, ...$passed_args) {
232
+		$extended_schema = $this->extend->get_endpoint_schema($endpoint, $passed_args);
233
+		$defaults        = $this->get_recursive_schema_property_defaults($extended_schema);
234 234
 
235 235
 		return [
236 236
 			'type'        => 'object',
237
-			'context'     => [ 'view', 'edit' ],
237
+			'context'     => ['view', 'edit'],
238 238
 			'arg_options' => [
239 239
 				'default'           => $defaults,
240
-				'validate_callback' => $this->get_recursive_validate_callback( $extended_schema ),
241
-				'sanitize_callback' => $this->get_recursive_sanitize_callback( $extended_schema ),
240
+				'validate_callback' => $this->get_recursive_validate_callback($extended_schema),
241
+				'sanitize_callback' => $this->get_recursive_sanitize_callback($extended_schema),
242 242
 			],
243 243
 			'properties'  => $extended_schema,
244 244
 		];
@@ -251,14 +251,14 @@  discard block
 block discarded – undo
251 251
 	 * @param array          $items Array of items.
252 252
 	 * @return array Array of values from the callback function.
253 253
 	 */
254
-	protected function get_item_responses_from_schema( AbstractSchema $schema, $items ) {
255
-		$items = array_filter( $items );
254
+	protected function get_item_responses_from_schema(AbstractSchema $schema, $items) {
255
+		$items = array_filter($items);
256 256
 
257
-		if ( empty( $items ) ) {
257
+		if (empty($items)) {
258 258
 			return [];
259 259
 		}
260 260
 
261
-		return array_values( array_map( [ $schema, 'get_item_response' ], $items ) );
261
+		return array_values(array_map([$schema, 'get_item_response'], $items));
262 262
 	}
263 263
 
264 264
 	/**
@@ -268,10 +268,10 @@  discard block
 block discarded – undo
268 268
 	 * @param string $method Optional. HTTP method of the request.
269 269
 	 * @return array Endpoint arguments.
270 270
 	 */
271
-	public function get_endpoint_args_for_item_schema( $method = \WP_REST_Server::CREATABLE ) {
271
+	public function get_endpoint_args_for_item_schema($method = \WP_REST_Server::CREATABLE) {
272 272
 		$schema        = $this->get_item_schema();
273
-		$endpoint_args = rest_get_endpoint_args_for_schema( $schema, $method );
274
-		$endpoint_args = $this->remove_arg_options( $endpoint_args );
273
+		$endpoint_args = rest_get_endpoint_args_for_schema($schema, $method);
274
+		$endpoint_args = $this->remove_arg_options($endpoint_args);
275 275
 		return $endpoint_args;
276 276
 	}
277 277
 
@@ -282,12 +282,12 @@  discard block
 block discarded – undo
282 282
 	 * @param array $properties Schema.
283 283
 	 * @return array Updated schema.
284 284
 	 */
285
-	protected function force_schema_readonly( $properties ) {
285
+	protected function force_schema_readonly($properties) {
286 286
 		return array_map(
287
-			function( $property ) {
287
+			function($property) {
288 288
 				$property['readonly'] = true;
289
-				if ( isset( $property['items']['properties'] ) ) {
290
-					$property['items']['properties'] = $this->force_schema_readonly( $property['items']['properties'] );
289
+				if (isset($property['items']['properties'])) {
290
+					$property['items']['properties'] = $this->force_schema_readonly($property['items']['properties']);
291 291
 				}
292 292
 				return $property;
293 293
 			},
@@ -303,45 +303,45 @@  discard block
 block discarded – undo
303 303
 	protected function get_store_currency_properties() {
304 304
 		return [
305 305
 			'currency_code'               => [
306
-				'description' => __( 'Currency code (in ISO format) for returned prices.', 'woocommerce' ),
306
+				'description' => __('Currency code (in ISO format) for returned prices.', 'woocommerce'),
307 307
 				'type'        => 'string',
308
-				'context'     => [ 'view', 'edit' ],
308
+				'context'     => ['view', 'edit'],
309 309
 				'readonly'    => true,
310 310
 			],
311 311
 			'currency_symbol'             => [
312
-				'description' => __( 'Currency symbol for the currency which can be used to format returned prices.', 'woocommerce' ),
312
+				'description' => __('Currency symbol for the currency which can be used to format returned prices.', 'woocommerce'),
313 313
 				'type'        => 'string',
314
-				'context'     => [ 'view', 'edit' ],
314
+				'context'     => ['view', 'edit'],
315 315
 				'readonly'    => true,
316 316
 			],
317 317
 			'currency_minor_unit'         => [
318
-				'description' => __( 'Currency minor unit (number of digits after the decimal separator) for returned prices.', 'woocommerce' ),
318
+				'description' => __('Currency minor unit (number of digits after the decimal separator) for returned prices.', 'woocommerce'),
319 319
 				'type'        => 'integer',
320
-				'context'     => [ 'view', 'edit' ],
320
+				'context'     => ['view', 'edit'],
321 321
 				'readonly'    => true,
322 322
 			],
323 323
 			'currency_decimal_separator'  => array(
324
-				'description' => __( 'Decimal separator for the currency which can be used to format returned prices.', 'woocommerce' ),
324
+				'description' => __('Decimal separator for the currency which can be used to format returned prices.', 'woocommerce'),
325 325
 				'type'        => 'string',
326
-				'context'     => array( 'view', 'edit' ),
326
+				'context'     => array('view', 'edit'),
327 327
 				'readonly'    => true,
328 328
 			),
329 329
 			'currency_thousand_separator' => array(
330
-				'description' => __( 'Thousand separator for the currency which can be used to format returned prices.', 'woocommerce' ),
330
+				'description' => __('Thousand separator for the currency which can be used to format returned prices.', 'woocommerce'),
331 331
 				'type'        => 'string',
332
-				'context'     => array( 'view', 'edit' ),
332
+				'context'     => array('view', 'edit'),
333 333
 				'readonly'    => true,
334 334
 			),
335 335
 			'currency_prefix'             => array(
336
-				'description' => __( 'Price prefix for the currency which can be used to format returned prices.', 'woocommerce' ),
336
+				'description' => __('Price prefix for the currency which can be used to format returned prices.', 'woocommerce'),
337 337
 				'type'        => 'string',
338
-				'context'     => array( 'view', 'edit' ),
338
+				'context'     => array('view', 'edit'),
339 339
 				'readonly'    => true,
340 340
 			),
341 341
 			'currency_suffix'             => array(
342
-				'description' => __( 'Price prefix for the currency which can be used to format returned prices.', 'woocommerce' ),
342
+				'description' => __('Price prefix for the currency which can be used to format returned prices.', 'woocommerce'),
343 343
 				'type'        => 'string',
344
-				'context'     => array( 'view', 'edit' ),
344
+				'context'     => array('view', 'edit'),
345 345
 				'readonly'    => true,
346 346
 			),
347 347
 		];
@@ -353,8 +353,8 @@  discard block
 block discarded – undo
353 353
 	 * @param array $values Monetary amounts.
354 354
 	 * @return array Monetary amounts with currency data appended.
355 355
 	 */
356
-	protected function prepare_currency_response( $values ) {
357
-		return $this->extend->get_formatter( 'currency' )->format( $values );
356
+	protected function prepare_currency_response($values) {
357
+		return $this->extend->get_formatter('currency')->format($values);
358 358
 	}
359 359
 
360 360
 	/**
@@ -366,8 +366,8 @@  discard block
 block discarded – undo
366 366
 	 * @param int          $rounding_mode Defaults to the PHP_ROUND_HALF_UP constant.
367 367
 	 * @return string      The new amount.
368 368
 	 */
369
-	protected function prepare_money_response( $amount, $decimals = 2, $rounding_mode = PHP_ROUND_HALF_UP ) {
370
-		return $this->extend->get_formatter( 'money' )->format(
369
+	protected function prepare_money_response($amount, $decimals = 2, $rounding_mode = PHP_ROUND_HALF_UP) {
370
+		return $this->extend->get_formatter('money')->format(
371 371
 			$amount,
372 372
 			[
373 373
 				'decimals'      => $decimals,
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
 	 * @param string|array $response Data to format.
383 383
 	 * @return string|array Formatted data.
384 384
 	 */
385
-	protected function prepare_html_response( $response ) {
386
-		return $this->extend->get_formatter( 'html' )->format( $response );
385
+	protected function prepare_html_response($response) {
386
+		return $this->extend->get_formatter('html')->format($response);
387 387
 	}
388 388
 }
Please login to merge, or discard this patch.
woocommerce-blocks/src/StoreApi/Schemas/V1/ProductCategorySchema.php 2 patches
Indentation   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -9,116 +9,116 @@
 block discarded – undo
9 9
  * ProductCategorySchema class.
10 10
  */
11 11
 class ProductCategorySchema extends TermSchema {
12
-	/**
13
-	 * The schema item name.
14
-	 *
15
-	 * @var string
16
-	 */
17
-	protected $title = 'product-category';
18
-
19
-	/**
20
-	 * The schema item identifier.
21
-	 *
22
-	 * @var string
23
-	 */
24
-	const IDENTIFIER = 'product-category';
25
-
26
-	/**
27
-	 * Image attachment schema instance.
28
-	 *
29
-	 * @var ImageAttachmentSchema
30
-	 */
31
-	protected $image_attachment_schema;
32
-
33
-	/**
34
-	 * Constructor.
35
-	 *
36
-	 * @param ExtendSchema     $extend Rest Extending instance.
37
-	 * @param SchemaController $controller Schema Controller instance.
38
-	 */
39
-	public function __construct( ExtendSchema $extend, SchemaController $controller ) {
40
-		parent::__construct( $extend, $controller );
41
-		$this->image_attachment_schema = $this->controller->get( ImageAttachmentSchema::IDENTIFIER );
42
-	}
43
-
44
-	/**
45
-	 * Term properties.
46
-	 *
47
-	 * @return array
48
-	 */
49
-	public function get_properties() {
50
-		$schema                 = parent::get_properties();
51
-		$schema['image']        = [
52
-			'description' => __( 'Category image.', 'woocommerce' ),
53
-			'type'        => 'object',
54
-			'context'     => [ 'view', 'edit', 'embed' ],
55
-			'readonly'    => true,
56
-			'properties'  => $this->image_attachment_schema->get_properties(),
57
-		];
58
-		$schema['review_count'] = [
59
-			'description' => __( 'Number of reviews for products in this category.', 'woocommerce' ),
60
-			'type'        => 'integer',
61
-			'context'     => [ 'view', 'edit' ],
62
-			'readonly'    => true,
63
-		];
64
-		$schema['permalink']    = [
65
-			'description' => __( 'Category URL.', 'woocommerce' ),
66
-			'type'        => 'string',
67
-			'format'      => 'uri',
68
-			'context'     => [ 'view', 'edit', 'embed' ],
69
-			'readonly'    => true,
70
-		];
71
-		return $schema;
72
-	}
73
-
74
-	/**
75
-	 * Convert a term object into an object suitable for the response.
76
-	 *
77
-	 * @param \WP_Term $term Term object.
78
-	 * @return array
79
-	 */
80
-	public function get_item_response( $term ) {
81
-		$response = parent::get_item_response( $term );
82
-		$count    = get_term_meta( $term->term_id, 'product_count_product_cat', true );
83
-
84
-		if ( $count ) {
85
-			$response['count'] = (int) $count;
86
-		}
87
-
88
-		$response['image']        = $this->image_attachment_schema->get_item_response( get_term_meta( $term->term_id, 'thumbnail_id', true ) );
89
-		$response['review_count'] = $this->get_category_review_count( $term );
90
-		$response['permalink']    = get_term_link( $term->term_id, 'product_cat' );
91
-
92
-		return $response;
93
-	}
94
-
95
-	/**
96
-	 * Get total number of reviews for products in a category.
97
-	 *
98
-	 * @param \WP_Term $term Term object.
99
-	 * @return int
100
-	 */
101
-	protected function get_category_review_count( $term ) {
102
-		global $wpdb;
103
-
104
-		$children = get_term_children( $term->term_id, 'product_cat' );
105
-
106
-		if ( ! $children || is_wp_error( $children ) ) {
107
-			$terms_to_count_str = absint( $term->term_id );
108
-		} else {
109
-			$terms_to_count     = array_unique( array_map( 'absint', array_merge( array( $term->term_id ), $children ) ) );
110
-			$terms_to_count_str = implode( ',', $terms_to_count );
111
-		}
112
-
113
-		$products_of_category_sql = "
12
+    /**
13
+     * The schema item name.
14
+     *
15
+     * @var string
16
+     */
17
+    protected $title = 'product-category';
18
+
19
+    /**
20
+     * The schema item identifier.
21
+     *
22
+     * @var string
23
+     */
24
+    const IDENTIFIER = 'product-category';
25
+
26
+    /**
27
+     * Image attachment schema instance.
28
+     *
29
+     * @var ImageAttachmentSchema
30
+     */
31
+    protected $image_attachment_schema;
32
+
33
+    /**
34
+     * Constructor.
35
+     *
36
+     * @param ExtendSchema     $extend Rest Extending instance.
37
+     * @param SchemaController $controller Schema Controller instance.
38
+     */
39
+    public function __construct( ExtendSchema $extend, SchemaController $controller ) {
40
+        parent::__construct( $extend, $controller );
41
+        $this->image_attachment_schema = $this->controller->get( ImageAttachmentSchema::IDENTIFIER );
42
+    }
43
+
44
+    /**
45
+     * Term properties.
46
+     *
47
+     * @return array
48
+     */
49
+    public function get_properties() {
50
+        $schema                 = parent::get_properties();
51
+        $schema['image']        = [
52
+            'description' => __( 'Category image.', 'woocommerce' ),
53
+            'type'        => 'object',
54
+            'context'     => [ 'view', 'edit', 'embed' ],
55
+            'readonly'    => true,
56
+            'properties'  => $this->image_attachment_schema->get_properties(),
57
+        ];
58
+        $schema['review_count'] = [
59
+            'description' => __( 'Number of reviews for products in this category.', 'woocommerce' ),
60
+            'type'        => 'integer',
61
+            'context'     => [ 'view', 'edit' ],
62
+            'readonly'    => true,
63
+        ];
64
+        $schema['permalink']    = [
65
+            'description' => __( 'Category URL.', 'woocommerce' ),
66
+            'type'        => 'string',
67
+            'format'      => 'uri',
68
+            'context'     => [ 'view', 'edit', 'embed' ],
69
+            'readonly'    => true,
70
+        ];
71
+        return $schema;
72
+    }
73
+
74
+    /**
75
+     * Convert a term object into an object suitable for the response.
76
+     *
77
+     * @param \WP_Term $term Term object.
78
+     * @return array
79
+     */
80
+    public function get_item_response( $term ) {
81
+        $response = parent::get_item_response( $term );
82
+        $count    = get_term_meta( $term->term_id, 'product_count_product_cat', true );
83
+
84
+        if ( $count ) {
85
+            $response['count'] = (int) $count;
86
+        }
87
+
88
+        $response['image']        = $this->image_attachment_schema->get_item_response( get_term_meta( $term->term_id, 'thumbnail_id', true ) );
89
+        $response['review_count'] = $this->get_category_review_count( $term );
90
+        $response['permalink']    = get_term_link( $term->term_id, 'product_cat' );
91
+
92
+        return $response;
93
+    }
94
+
95
+    /**
96
+     * Get total number of reviews for products in a category.
97
+     *
98
+     * @param \WP_Term $term Term object.
99
+     * @return int
100
+     */
101
+    protected function get_category_review_count( $term ) {
102
+        global $wpdb;
103
+
104
+        $children = get_term_children( $term->term_id, 'product_cat' );
105
+
106
+        if ( ! $children || is_wp_error( $children ) ) {
107
+            $terms_to_count_str = absint( $term->term_id );
108
+        } else {
109
+            $terms_to_count     = array_unique( array_map( 'absint', array_merge( array( $term->term_id ), $children ) ) );
110
+            $terms_to_count_str = implode( ',', $terms_to_count );
111
+        }
112
+
113
+        $products_of_category_sql = "
114 114
 			SELECT SUM(comment_count) as review_count
115 115
 			FROM {$wpdb->posts} AS posts
116 116
 			INNER JOIN {$wpdb->term_relationships} AS term_relationships ON posts.ID = term_relationships.object_id
117 117
 			WHERE term_relationships.term_taxonomy_id IN (" . esc_sql( $terms_to_count_str ) . ')
118 118
 		';
119 119
 
120
-		$review_count = $wpdb->get_var( $products_of_category_sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
120
+        $review_count = $wpdb->get_var( $products_of_category_sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
121 121
 
122
-		return (int) $review_count;
123
-	}
122
+        return (int) $review_count;
123
+    }
124 124
 }
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -36,9 +36,9 @@  discard block
 block discarded – undo
36 36
 	 * @param ExtendSchema     $extend Rest Extending instance.
37 37
 	 * @param SchemaController $controller Schema Controller instance.
38 38
 	 */
39
-	public function __construct( ExtendSchema $extend, SchemaController $controller ) {
40
-		parent::__construct( $extend, $controller );
41
-		$this->image_attachment_schema = $this->controller->get( ImageAttachmentSchema::IDENTIFIER );
39
+	public function __construct(ExtendSchema $extend, SchemaController $controller) {
40
+		parent::__construct($extend, $controller);
41
+		$this->image_attachment_schema = $this->controller->get(ImageAttachmentSchema::IDENTIFIER);
42 42
 	}
43 43
 
44 44
 	/**
@@ -49,23 +49,23 @@  discard block
 block discarded – undo
49 49
 	public function get_properties() {
50 50
 		$schema                 = parent::get_properties();
51 51
 		$schema['image']        = [
52
-			'description' => __( 'Category image.', 'woocommerce' ),
52
+			'description' => __('Category image.', 'woocommerce'),
53 53
 			'type'        => 'object',
54
-			'context'     => [ 'view', 'edit', 'embed' ],
54
+			'context'     => ['view', 'edit', 'embed'],
55 55
 			'readonly'    => true,
56 56
 			'properties'  => $this->image_attachment_schema->get_properties(),
57 57
 		];
58 58
 		$schema['review_count'] = [
59
-			'description' => __( 'Number of reviews for products in this category.', 'woocommerce' ),
59
+			'description' => __('Number of reviews for products in this category.', 'woocommerce'),
60 60
 			'type'        => 'integer',
61
-			'context'     => [ 'view', 'edit' ],
61
+			'context'     => ['view', 'edit'],
62 62
 			'readonly'    => true,
63 63
 		];
64
-		$schema['permalink']    = [
65
-			'description' => __( 'Category URL.', 'woocommerce' ),
64
+		$schema['permalink'] = [
65
+			'description' => __('Category URL.', 'woocommerce'),
66 66
 			'type'        => 'string',
67 67
 			'format'      => 'uri',
68
-			'context'     => [ 'view', 'edit', 'embed' ],
68
+			'context'     => ['view', 'edit', 'embed'],
69 69
 			'readonly'    => true,
70 70
 		];
71 71
 		return $schema;
@@ -77,17 +77,17 @@  discard block
 block discarded – undo
77 77
 	 * @param \WP_Term $term Term object.
78 78
 	 * @return array
79 79
 	 */
80
-	public function get_item_response( $term ) {
81
-		$response = parent::get_item_response( $term );
82
-		$count    = get_term_meta( $term->term_id, 'product_count_product_cat', true );
80
+	public function get_item_response($term) {
81
+		$response = parent::get_item_response($term);
82
+		$count    = get_term_meta($term->term_id, 'product_count_product_cat', true);
83 83
 
84
-		if ( $count ) {
84
+		if ($count) {
85 85
 			$response['count'] = (int) $count;
86 86
 		}
87 87
 
88
-		$response['image']        = $this->image_attachment_schema->get_item_response( get_term_meta( $term->term_id, 'thumbnail_id', true ) );
89
-		$response['review_count'] = $this->get_category_review_count( $term );
90
-		$response['permalink']    = get_term_link( $term->term_id, 'product_cat' );
88
+		$response['image']        = $this->image_attachment_schema->get_item_response(get_term_meta($term->term_id, 'thumbnail_id', true));
89
+		$response['review_count'] = $this->get_category_review_count($term);
90
+		$response['permalink']    = get_term_link($term->term_id, 'product_cat');
91 91
 
92 92
 		return $response;
93 93
 	}
@@ -98,26 +98,26 @@  discard block
 block discarded – undo
98 98
 	 * @param \WP_Term $term Term object.
99 99
 	 * @return int
100 100
 	 */
101
-	protected function get_category_review_count( $term ) {
101
+	protected function get_category_review_count($term) {
102 102
 		global $wpdb;
103 103
 
104
-		$children = get_term_children( $term->term_id, 'product_cat' );
104
+		$children = get_term_children($term->term_id, 'product_cat');
105 105
 
106
-		if ( ! $children || is_wp_error( $children ) ) {
107
-			$terms_to_count_str = absint( $term->term_id );
106
+		if (!$children || is_wp_error($children)) {
107
+			$terms_to_count_str = absint($term->term_id);
108 108
 		} else {
109
-			$terms_to_count     = array_unique( array_map( 'absint', array_merge( array( $term->term_id ), $children ) ) );
110
-			$terms_to_count_str = implode( ',', $terms_to_count );
109
+			$terms_to_count     = array_unique(array_map('absint', array_merge(array($term->term_id), $children)));
110
+			$terms_to_count_str = implode(',', $terms_to_count);
111 111
 		}
112 112
 
113 113
 		$products_of_category_sql = "
114 114
 			SELECT SUM(comment_count) as review_count
115 115
 			FROM {$wpdb->posts} AS posts
116 116
 			INNER JOIN {$wpdb->term_relationships} AS term_relationships ON posts.ID = term_relationships.object_id
117
-			WHERE term_relationships.term_taxonomy_id IN (" . esc_sql( $terms_to_count_str ) . ')
117
+			WHERE term_relationships.term_taxonomy_id IN (" . esc_sql($terms_to_count_str) . ')
118 118
 		';
119 119
 
120
-		$review_count = $wpdb->get_var( $products_of_category_sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
120
+		$review_count = $wpdb->get_var($products_of_category_sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
121 121
 
122 122
 		return (int) $review_count;
123 123
 	}
Please login to merge, or discard this patch.
packages/woocommerce-blocks/src/StoreApi/Schemas/V1/ErrorSchema.php 2 patches
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -5,53 +5,53 @@
 block discarded – undo
5 5
  * ErrorSchema class.
6 6
  */
7 7
 class ErrorSchema extends AbstractSchema {
8
-	/**
9
-	 * The schema item name.
10
-	 *
11
-	 * @var string
12
-	 */
13
-	protected $title = 'error';
8
+    /**
9
+     * The schema item name.
10
+     *
11
+     * @var string
12
+     */
13
+    protected $title = 'error';
14 14
 
15
-	/**
16
-	 * The schema item identifier.
17
-	 *
18
-	 * @var string
19
-	 */
20
-	const IDENTIFIER = 'error';
15
+    /**
16
+     * The schema item identifier.
17
+     *
18
+     * @var string
19
+     */
20
+    const IDENTIFIER = 'error';
21 21
 
22
-	/**
23
-	 * Product schema properties.
24
-	 *
25
-	 * @return array
26
-	 */
27
-	public function get_properties() {
28
-		return [
29
-			'code'    => [
30
-				'description' => __( 'Error code', 'woocommerce' ),
31
-				'type'        => 'string',
32
-				'context'     => [ 'view', 'edit' ],
33
-				'readonly'    => true,
34
-			],
35
-			'message' => [
36
-				'description' => __( 'Error message', 'woocommerce' ),
37
-				'type'        => 'string',
38
-				'context'     => [ 'view', 'edit' ],
39
-				'readonly'    => true,
40
-			],
41
-		];
42
-	}
22
+    /**
23
+     * Product schema properties.
24
+     *
25
+     * @return array
26
+     */
27
+    public function get_properties() {
28
+        return [
29
+            'code'    => [
30
+                'description' => __( 'Error code', 'woocommerce' ),
31
+                'type'        => 'string',
32
+                'context'     => [ 'view', 'edit' ],
33
+                'readonly'    => true,
34
+            ],
35
+            'message' => [
36
+                'description' => __( 'Error message', 'woocommerce' ),
37
+                'type'        => 'string',
38
+                'context'     => [ 'view', 'edit' ],
39
+                'readonly'    => true,
40
+            ],
41
+        ];
42
+    }
43 43
 
44
-	/**
45
-	 * Convert a WP_Error into an object suitable for the response.
46
-	 *
47
-	 * @param \WP_Error $error Error object.
48
-	 * @return array
49
-	 */
50
-	public function get_item_response( \WP_Error $error ) {
51
-		return [
52
-			'code'    => $this->prepare_html_response( $error->get_error_code() ),
53
-			'message' => $this->prepare_html_response( $error->get_error_message() ),
54
-		];
55
-	}
44
+    /**
45
+     * Convert a WP_Error into an object suitable for the response.
46
+     *
47
+     * @param \WP_Error $error Error object.
48
+     * @return array
49
+     */
50
+    public function get_item_response( \WP_Error $error ) {
51
+        return [
52
+            'code'    => $this->prepare_html_response( $error->get_error_code() ),
53
+            'message' => $this->prepare_html_response( $error->get_error_message() ),
54
+        ];
55
+    }
56 56
 
57 57
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -27,15 +27,15 @@  discard block
 block discarded – undo
27 27
 	public function get_properties() {
28 28
 		return [
29 29
 			'code'    => [
30
-				'description' => __( 'Error code', 'woocommerce' ),
30
+				'description' => __('Error code', 'woocommerce'),
31 31
 				'type'        => 'string',
32
-				'context'     => [ 'view', 'edit' ],
32
+				'context'     => ['view', 'edit'],
33 33
 				'readonly'    => true,
34 34
 			],
35 35
 			'message' => [
36
-				'description' => __( 'Error message', 'woocommerce' ),
36
+				'description' => __('Error message', 'woocommerce'),
37 37
 				'type'        => 'string',
38
-				'context'     => [ 'view', 'edit' ],
38
+				'context'     => ['view', 'edit'],
39 39
 				'readonly'    => true,
40 40
 			],
41 41
 		];
@@ -47,10 +47,10 @@  discard block
 block discarded – undo
47 47
 	 * @param \WP_Error $error Error object.
48 48
 	 * @return array
49 49
 	 */
50
-	public function get_item_response( \WP_Error $error ) {
50
+	public function get_item_response(\WP_Error $error) {
51 51
 		return [
52
-			'code'    => $this->prepare_html_response( $error->get_error_code() ),
53
-			'message' => $this->prepare_html_response( $error->get_error_message() ),
52
+			'code'    => $this->prepare_html_response($error->get_error_code()),
53
+			'message' => $this->prepare_html_response($error->get_error_message()),
54 54
 		];
55 55
 	}
56 56
 
Please login to merge, or discard this patch.
packages/woocommerce-blocks/src/StoreApi/Schemas/V1/BatchSchema.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -5,26 +5,26 @@
 block discarded – undo
5 5
  * BatchSchema class.
6 6
  */
7 7
 class BatchSchema extends AbstractSchema {
8
-	/**
9
-	 * The schema item name.
10
-	 *
11
-	 * @var string
12
-	 */
13
-	protected $title = 'batch';
8
+    /**
9
+     * The schema item name.
10
+     *
11
+     * @var string
12
+     */
13
+    protected $title = 'batch';
14 14
 
15
-	/**
16
-	 * The schema item identifier.
17
-	 *
18
-	 * @var string
19
-	 */
20
-	const IDENTIFIER = 'batch';
15
+    /**
16
+     * The schema item identifier.
17
+     *
18
+     * @var string
19
+     */
20
+    const IDENTIFIER = 'batch';
21 21
 
22
-	/**
23
-	 * Batch schema properties.
24
-	 *
25
-	 * @return array
26
-	 */
27
-	public function get_properties() {
28
-		return [];
29
-	}
22
+    /**
23
+     * Batch schema properties.
24
+     *
25
+     * @return array
26
+     */
27
+    public function get_properties() {
28
+        return [];
29
+    }
30 30
 }
Please login to merge, or discard this patch.
woocommerce-blocks/src/StoreApi/Schemas/V1/CartShippingRateSchema.php 2 patches
Indentation   +329 added lines, -329 removed lines patch added patch discarded remove patch
@@ -7,348 +7,348 @@
 block discarded – undo
7 7
  * CartShippingRateSchema class.
8 8
  */
9 9
 class CartShippingRateSchema extends AbstractSchema {
10
-	/**
11
-	 * The schema item name.
12
-	 *
13
-	 * @var string
14
-	 */
15
-	protected $title = 'cart-shipping-rate';
10
+    /**
11
+     * The schema item name.
12
+     *
13
+     * @var string
14
+     */
15
+    protected $title = 'cart-shipping-rate';
16 16
 
17
-	/**
18
-	 * The schema item identifier.
19
-	 *
20
-	 * @var string
21
-	 */
22
-	const IDENTIFIER = 'cart-shipping-rate';
17
+    /**
18
+     * The schema item identifier.
19
+     *
20
+     * @var string
21
+     */
22
+    const IDENTIFIER = 'cart-shipping-rate';
23 23
 
24
-	/**
25
-	 * Cart schema properties.
26
-	 *
27
-	 * @return array
28
-	 */
29
-	public function get_properties() {
30
-		return [
31
-			'package_id'     => [
32
-				'description' => __( 'The ID of the package the shipping rates belong to.', 'woocommerce' ),
33
-				'type'        => [ 'integer', 'string' ],
34
-				'context'     => [ 'view', 'edit' ],
35
-				'readonly'    => true,
36
-			],
37
-			'name'           => [
38
-				'description' => __( 'Name of the package.', 'woocommerce' ),
39
-				'type'        => 'string',
40
-				'context'     => [ 'view', 'edit' ],
41
-				'readonly'    => true,
42
-			],
43
-			'destination'    => [
44
-				'description' => __( 'Shipping destination address.', 'woocommerce' ),
45
-				'type'        => 'object',
46
-				'context'     => [ 'view', 'edit' ],
47
-				'readonly'    => true,
48
-				'properties'  => [
49
-					'address_1' => [
50
-						'description' => __( 'First line of the address being shipped to.', 'woocommerce' ),
51
-						'type'        => 'string',
52
-						'context'     => [ 'view', 'edit' ],
53
-						'readonly'    => true,
54
-					],
55
-					'address_2' => [
56
-						'description' => __( 'Second line of the address being shipped to.', 'woocommerce' ),
57
-						'type'        => 'string',
58
-						'context'     => [ 'view', 'edit' ],
59
-						'readonly'    => true,
60
-					],
61
-					'city'      => [
62
-						'description' => __( 'City of the address being shipped to.', 'woocommerce' ),
63
-						'type'        => 'string',
64
-						'context'     => [ 'view', 'edit' ],
65
-						'readonly'    => true,
66
-					],
67
-					'state'     => [
68
-						'description' => __( 'ISO code, or name, for the state, province, or district of the address being shipped to.', 'woocommerce' ),
69
-						'type'        => 'string',
70
-						'context'     => [ 'view', 'edit' ],
71
-						'readonly'    => true,
72
-					],
73
-					'postcode'  => [
74
-						'description' => __( 'Zip or Postcode of the address being shipped to.', 'woocommerce' ),
75
-						'type'        => 'string',
76
-						'context'     => [ 'view', 'edit' ],
77
-						'readonly'    => true,
78
-					],
79
-					'country'   => [
80
-						'description' => __( 'ISO code for the country of the address being shipped to.', 'woocommerce' ),
81
-						'type'        => 'string',
82
-						'context'     => [ 'view', 'edit' ],
83
-						'readonly'    => true,
84
-					],
85
-				],
86
-			],
87
-			'items'          => [
88
-				'description' => __( 'List of cart items the returned shipping rates apply to.', 'woocommerce' ),
89
-				'type'        => 'array',
90
-				'context'     => [ 'view', 'edit' ],
91
-				'readonly'    => true,
92
-				'items'       => [
93
-					'type'       => 'object',
94
-					'properties' => [
95
-						'key'      => [
96
-							'description' => __( 'Unique identifier for the item within the cart.', 'woocommerce' ),
97
-							'type'        => 'string',
98
-							'context'     => [ 'view', 'edit' ],
99
-							'readonly'    => true,
100
-						],
101
-						'name'     => [
102
-							'description' => __( 'Name of the item.', 'woocommerce' ),
103
-							'type'        => 'string',
104
-							'context'     => [ 'view', 'edit' ],
105
-							'readonly'    => true,
106
-						],
107
-						'quantity' => [
108
-							'description' => __( 'Quantity of the item in the current package.', 'woocommerce' ),
109
-							'type'        => 'number',
110
-							'context'     => [ 'view', 'edit' ],
111
-							'readonly'    => true,
112
-						],
113
-					],
114
-				],
115
-			],
116
-			'shipping_rates' => [
117
-				'description' => __( 'List of shipping rates.', 'woocommerce' ),
118
-				'type'        => 'array',
119
-				'context'     => [ 'view', 'edit' ],
120
-				'readonly'    => true,
121
-				'items'       => [
122
-					'type'       => 'object',
123
-					'properties' => $this->get_rate_properties(),
124
-				],
125
-			],
126
-		];
127
-	}
24
+    /**
25
+     * Cart schema properties.
26
+     *
27
+     * @return array
28
+     */
29
+    public function get_properties() {
30
+        return [
31
+            'package_id'     => [
32
+                'description' => __( 'The ID of the package the shipping rates belong to.', 'woocommerce' ),
33
+                'type'        => [ 'integer', 'string' ],
34
+                'context'     => [ 'view', 'edit' ],
35
+                'readonly'    => true,
36
+            ],
37
+            'name'           => [
38
+                'description' => __( 'Name of the package.', 'woocommerce' ),
39
+                'type'        => 'string',
40
+                'context'     => [ 'view', 'edit' ],
41
+                'readonly'    => true,
42
+            ],
43
+            'destination'    => [
44
+                'description' => __( 'Shipping destination address.', 'woocommerce' ),
45
+                'type'        => 'object',
46
+                'context'     => [ 'view', 'edit' ],
47
+                'readonly'    => true,
48
+                'properties'  => [
49
+                    'address_1' => [
50
+                        'description' => __( 'First line of the address being shipped to.', 'woocommerce' ),
51
+                        'type'        => 'string',
52
+                        'context'     => [ 'view', 'edit' ],
53
+                        'readonly'    => true,
54
+                    ],
55
+                    'address_2' => [
56
+                        'description' => __( 'Second line of the address being shipped to.', 'woocommerce' ),
57
+                        'type'        => 'string',
58
+                        'context'     => [ 'view', 'edit' ],
59
+                        'readonly'    => true,
60
+                    ],
61
+                    'city'      => [
62
+                        'description' => __( 'City of the address being shipped to.', 'woocommerce' ),
63
+                        'type'        => 'string',
64
+                        'context'     => [ 'view', 'edit' ],
65
+                        'readonly'    => true,
66
+                    ],
67
+                    'state'     => [
68
+                        'description' => __( 'ISO code, or name, for the state, province, or district of the address being shipped to.', 'woocommerce' ),
69
+                        'type'        => 'string',
70
+                        'context'     => [ 'view', 'edit' ],
71
+                        'readonly'    => true,
72
+                    ],
73
+                    'postcode'  => [
74
+                        'description' => __( 'Zip or Postcode of the address being shipped to.', 'woocommerce' ),
75
+                        'type'        => 'string',
76
+                        'context'     => [ 'view', 'edit' ],
77
+                        'readonly'    => true,
78
+                    ],
79
+                    'country'   => [
80
+                        'description' => __( 'ISO code for the country of the address being shipped to.', 'woocommerce' ),
81
+                        'type'        => 'string',
82
+                        'context'     => [ 'view', 'edit' ],
83
+                        'readonly'    => true,
84
+                    ],
85
+                ],
86
+            ],
87
+            'items'          => [
88
+                'description' => __( 'List of cart items the returned shipping rates apply to.', 'woocommerce' ),
89
+                'type'        => 'array',
90
+                'context'     => [ 'view', 'edit' ],
91
+                'readonly'    => true,
92
+                'items'       => [
93
+                    'type'       => 'object',
94
+                    'properties' => [
95
+                        'key'      => [
96
+                            'description' => __( 'Unique identifier for the item within the cart.', 'woocommerce' ),
97
+                            'type'        => 'string',
98
+                            'context'     => [ 'view', 'edit' ],
99
+                            'readonly'    => true,
100
+                        ],
101
+                        'name'     => [
102
+                            'description' => __( 'Name of the item.', 'woocommerce' ),
103
+                            'type'        => 'string',
104
+                            'context'     => [ 'view', 'edit' ],
105
+                            'readonly'    => true,
106
+                        ],
107
+                        'quantity' => [
108
+                            'description' => __( 'Quantity of the item in the current package.', 'woocommerce' ),
109
+                            'type'        => 'number',
110
+                            'context'     => [ 'view', 'edit' ],
111
+                            'readonly'    => true,
112
+                        ],
113
+                    ],
114
+                ],
115
+            ],
116
+            'shipping_rates' => [
117
+                'description' => __( 'List of shipping rates.', 'woocommerce' ),
118
+                'type'        => 'array',
119
+                'context'     => [ 'view', 'edit' ],
120
+                'readonly'    => true,
121
+                'items'       => [
122
+                    'type'       => 'object',
123
+                    'properties' => $this->get_rate_properties(),
124
+                ],
125
+            ],
126
+        ];
127
+    }
128 128
 
129
-	/**
130
-	 * Schema for a single rate.
131
-	 *
132
-	 * @return array
133
-	 */
134
-	protected function get_rate_properties() {
135
-		return array_merge(
136
-			[
137
-				'rate_id'       => [
138
-					'description' => __( 'ID of the shipping rate.', 'woocommerce' ),
139
-					'type'        => 'string',
140
-					'context'     => [ 'view', 'edit' ],
141
-					'readonly'    => true,
142
-				],
143
-				'name'          => [
144
-					'description' => __( 'Name of the shipping rate, e.g. Express shipping.', 'woocommerce' ),
145
-					'type'        => 'string',
146
-					'context'     => [ 'view', 'edit' ],
147
-					'readonly'    => true,
148
-				],
149
-				'description'   => [
150
-					'description' => __( 'Description of the shipping rate, e.g. Dispatched via USPS.', 'woocommerce' ),
151
-					'type'        => 'string',
152
-					'context'     => [ 'view', 'edit' ],
153
-					'readonly'    => true,
154
-				],
155
-				'delivery_time' => [
156
-					'description' => __( 'Delivery time estimate text, e.g. 3-5 business days.', 'woocommerce' ),
157
-					'type'        => 'string',
158
-					'context'     => [ 'view', 'edit' ],
159
-					'readonly'    => true,
160
-				],
161
-				'price'         => [
162
-					'description' => __( 'Price of this shipping rate using the smallest unit of the currency.', 'woocommerce' ),
163
-					'type'        => 'string',
164
-					'context'     => [ 'view', 'edit' ],
165
-					'readonly'    => true,
166
-				],
167
-				'taxes'         => [
168
-					'description' => __( 'Taxes applied to this shipping rate using the smallest unit of the currency.', 'woocommerce' ),
169
-					'type'        => 'string',
170
-					'context'     => [ 'view', 'edit' ],
171
-					'readonly'    => true,
172
-				],
173
-				'method_id'     => [
174
-					'description' => __( 'ID of the shipping method that provided the rate.', 'woocommerce' ),
175
-					'type'        => 'string',
176
-					'context'     => [ 'view', 'edit' ],
177
-					'readonly'    => true,
178
-				],
179
-				'instance_id'   => [
180
-					'description' => __( 'Instance ID of the shipping method that provided the rate.', 'woocommerce' ),
181
-					'type'        => 'integer',
182
-					'context'     => [ 'view', 'edit' ],
183
-					'readonly'    => true,
184
-				],
185
-				'meta_data'     => [
186
-					'description' => __( 'Meta data attached to the shipping rate.', 'woocommerce' ),
187
-					'type'        => 'array',
188
-					'context'     => [ 'view', 'edit' ],
189
-					'items'       => [
190
-						'type'       => 'object',
191
-						'properties' => [
192
-							'key'   => [
193
-								'description' => __( 'Meta key.', 'woocommerce' ),
194
-								'type'        => 'string',
195
-								'context'     => [ 'view', 'edit' ],
196
-								'readonly'    => true,
197
-							],
198
-							'value' => [
199
-								'description' => __( 'Meta value.', 'woocommerce' ),
200
-								'type'        => 'string',
201
-								'context'     => [ 'view', 'edit' ],
202
-								'readonly'    => true,
203
-							],
204
-						],
205
-					],
206
-				],
207
-				'selected'      => [
208
-					'description' => __( 'True if this is the rate currently selected by the customer for the cart.', 'woocommerce' ),
209
-					'type'        => 'boolean',
210
-					'context'     => [ 'view', 'edit' ],
211
-					'readonly'    => true,
212
-				],
213
-			],
214
-			$this->get_store_currency_properties()
215
-		);
216
-	}
129
+    /**
130
+     * Schema for a single rate.
131
+     *
132
+     * @return array
133
+     */
134
+    protected function get_rate_properties() {
135
+        return array_merge(
136
+            [
137
+                'rate_id'       => [
138
+                    'description' => __( 'ID of the shipping rate.', 'woocommerce' ),
139
+                    'type'        => 'string',
140
+                    'context'     => [ 'view', 'edit' ],
141
+                    'readonly'    => true,
142
+                ],
143
+                'name'          => [
144
+                    'description' => __( 'Name of the shipping rate, e.g. Express shipping.', 'woocommerce' ),
145
+                    'type'        => 'string',
146
+                    'context'     => [ 'view', 'edit' ],
147
+                    'readonly'    => true,
148
+                ],
149
+                'description'   => [
150
+                    'description' => __( 'Description of the shipping rate, e.g. Dispatched via USPS.', 'woocommerce' ),
151
+                    'type'        => 'string',
152
+                    'context'     => [ 'view', 'edit' ],
153
+                    'readonly'    => true,
154
+                ],
155
+                'delivery_time' => [
156
+                    'description' => __( 'Delivery time estimate text, e.g. 3-5 business days.', 'woocommerce' ),
157
+                    'type'        => 'string',
158
+                    'context'     => [ 'view', 'edit' ],
159
+                    'readonly'    => true,
160
+                ],
161
+                'price'         => [
162
+                    'description' => __( 'Price of this shipping rate using the smallest unit of the currency.', 'woocommerce' ),
163
+                    'type'        => 'string',
164
+                    'context'     => [ 'view', 'edit' ],
165
+                    'readonly'    => true,
166
+                ],
167
+                'taxes'         => [
168
+                    'description' => __( 'Taxes applied to this shipping rate using the smallest unit of the currency.', 'woocommerce' ),
169
+                    'type'        => 'string',
170
+                    'context'     => [ 'view', 'edit' ],
171
+                    'readonly'    => true,
172
+                ],
173
+                'method_id'     => [
174
+                    'description' => __( 'ID of the shipping method that provided the rate.', 'woocommerce' ),
175
+                    'type'        => 'string',
176
+                    'context'     => [ 'view', 'edit' ],
177
+                    'readonly'    => true,
178
+                ],
179
+                'instance_id'   => [
180
+                    'description' => __( 'Instance ID of the shipping method that provided the rate.', 'woocommerce' ),
181
+                    'type'        => 'integer',
182
+                    'context'     => [ 'view', 'edit' ],
183
+                    'readonly'    => true,
184
+                ],
185
+                'meta_data'     => [
186
+                    'description' => __( 'Meta data attached to the shipping rate.', 'woocommerce' ),
187
+                    'type'        => 'array',
188
+                    'context'     => [ 'view', 'edit' ],
189
+                    'items'       => [
190
+                        'type'       => 'object',
191
+                        'properties' => [
192
+                            'key'   => [
193
+                                'description' => __( 'Meta key.', 'woocommerce' ),
194
+                                'type'        => 'string',
195
+                                'context'     => [ 'view', 'edit' ],
196
+                                'readonly'    => true,
197
+                            ],
198
+                            'value' => [
199
+                                'description' => __( 'Meta value.', 'woocommerce' ),
200
+                                'type'        => 'string',
201
+                                'context'     => [ 'view', 'edit' ],
202
+                                'readonly'    => true,
203
+                            ],
204
+                        ],
205
+                    ],
206
+                ],
207
+                'selected'      => [
208
+                    'description' => __( 'True if this is the rate currently selected by the customer for the cart.', 'woocommerce' ),
209
+                    'type'        => 'boolean',
210
+                    'context'     => [ 'view', 'edit' ],
211
+                    'readonly'    => true,
212
+                ],
213
+            ],
214
+            $this->get_store_currency_properties()
215
+        );
216
+    }
217 217
 
218
-	/**
219
-	 * Convert a shipping rate from WooCommerce into a valid response.
220
-	 *
221
-	 * @param array $package Shipping package complete with rates from WooCommerce.
222
-	 * @return array
223
-	 */
224
-	public function get_item_response( $package ) {
225
-		return [
226
-			'package_id'     => $package['package_id'],
227
-			'name'           => $package['package_name'],
228
-			'destination'    => $this->prepare_package_destination_response( $package ),
229
-			'items'          => $this->prepare_package_items_response( $package ),
230
-			'shipping_rates' => $this->prepare_package_shipping_rates_response( $package ),
231
-		];
232
-	}
218
+    /**
219
+     * Convert a shipping rate from WooCommerce into a valid response.
220
+     *
221
+     * @param array $package Shipping package complete with rates from WooCommerce.
222
+     * @return array
223
+     */
224
+    public function get_item_response( $package ) {
225
+        return [
226
+            'package_id'     => $package['package_id'],
227
+            'name'           => $package['package_name'],
228
+            'destination'    => $this->prepare_package_destination_response( $package ),
229
+            'items'          => $this->prepare_package_items_response( $package ),
230
+            'shipping_rates' => $this->prepare_package_shipping_rates_response( $package ),
231
+        ];
232
+    }
233 233
 
234
-	/**
235
-	 * Gets and formats the destination address of a package.
236
-	 *
237
-	 * @param array $package Shipping package complete with rates from WooCommerce.
238
-	 * @return object
239
-	 */
240
-	protected function prepare_package_destination_response( $package ) {
241
-		// If address_1 fails check address for back compatability.
242
-		$address = isset( $package['destination']['address_1'] ) ? $package['destination']['address_1'] : $package['destination']['address'];
243
-		return (object) $this->prepare_html_response(
244
-			[
245
-				'address_1' => $address,
246
-				'address_2' => $package['destination']['address_2'],
247
-				'city'      => $package['destination']['city'],
248
-				'state'     => $package['destination']['state'],
249
-				'postcode'  => $package['destination']['postcode'],
250
-				'country'   => $package['destination']['country'],
251
-			]
252
-		);
253
-	}
234
+    /**
235
+     * Gets and formats the destination address of a package.
236
+     *
237
+     * @param array $package Shipping package complete with rates from WooCommerce.
238
+     * @return object
239
+     */
240
+    protected function prepare_package_destination_response( $package ) {
241
+        // If address_1 fails check address for back compatability.
242
+        $address = isset( $package['destination']['address_1'] ) ? $package['destination']['address_1'] : $package['destination']['address'];
243
+        return (object) $this->prepare_html_response(
244
+            [
245
+                'address_1' => $address,
246
+                'address_2' => $package['destination']['address_2'],
247
+                'city'      => $package['destination']['city'],
248
+                'state'     => $package['destination']['state'],
249
+                'postcode'  => $package['destination']['postcode'],
250
+                'country'   => $package['destination']['country'],
251
+            ]
252
+        );
253
+    }
254 254
 
255
-	/**
256
-	 * Gets items from a package and creates an array of strings containing product names and quantities.
257
-	 *
258
-	 * @param array $package Shipping package complete with rates from WooCommerce.
259
-	 * @return array
260
-	 */
261
-	protected function prepare_package_items_response( $package ) {
262
-		$items = array();
263
-		foreach ( $package['contents'] as $item_id => $values ) {
264
-			$items[] = [
265
-				'key'      => $item_id,
266
-				'name'     => $values['data']->get_name(),
267
-				'quantity' => $values['quantity'],
268
-			];
269
-		}
270
-		return $items;
271
-	}
255
+    /**
256
+     * Gets items from a package and creates an array of strings containing product names and quantities.
257
+     *
258
+     * @param array $package Shipping package complete with rates from WooCommerce.
259
+     * @return array
260
+     */
261
+    protected function prepare_package_items_response( $package ) {
262
+        $items = array();
263
+        foreach ( $package['contents'] as $item_id => $values ) {
264
+            $items[] = [
265
+                'key'      => $item_id,
266
+                'name'     => $values['data']->get_name(),
267
+                'quantity' => $values['quantity'],
268
+            ];
269
+        }
270
+        return $items;
271
+    }
272 272
 
273
-	/**
274
-	 * Prepare an array of rates from a package for the response.
275
-	 *
276
-	 * @param array $package Shipping package complete with rates from WooCommerce.
277
-	 * @return array
278
-	 */
279
-	protected function prepare_package_shipping_rates_response( $package ) {
280
-		$rates          = $package['rates'];
281
-		$selected_rates = wc()->session->get( 'chosen_shipping_methods', array() );
282
-		$selected_rate  = isset( $selected_rates[ $package['package_id'] ] ) ? $selected_rates[ $package['package_id'] ] : '';
273
+    /**
274
+     * Prepare an array of rates from a package for the response.
275
+     *
276
+     * @param array $package Shipping package complete with rates from WooCommerce.
277
+     * @return array
278
+     */
279
+    protected function prepare_package_shipping_rates_response( $package ) {
280
+        $rates          = $package['rates'];
281
+        $selected_rates = wc()->session->get( 'chosen_shipping_methods', array() );
282
+        $selected_rate  = isset( $selected_rates[ $package['package_id'] ] ) ? $selected_rates[ $package['package_id'] ] : '';
283 283
 
284
-		if ( empty( $selected_rate ) && ! empty( $package['rates'] ) ) {
285
-			$selected_rate = wc_get_chosen_shipping_method_for_package( $package['package_id'], $package );
286
-		}
284
+        if ( empty( $selected_rate ) && ! empty( $package['rates'] ) ) {
285
+            $selected_rate = wc_get_chosen_shipping_method_for_package( $package['package_id'], $package );
286
+        }
287 287
 
288
-		$response = [];
288
+        $response = [];
289 289
 
290
-		foreach ( $package['rates'] as $rate ) {
291
-			$response[] = $this->get_rate_response( $rate, $selected_rate );
292
-		}
290
+        foreach ( $package['rates'] as $rate ) {
291
+            $response[] = $this->get_rate_response( $rate, $selected_rate );
292
+        }
293 293
 
294
-		return $response;
295
-	}
294
+        return $response;
295
+    }
296 296
 
297
-	/**
298
-	 * Response for a single rate.
299
-	 *
300
-	 * @param WC_Shipping_Rate $rate Rate object.
301
-	 * @param string           $selected_rate Selected rate.
302
-	 * @return array
303
-	 */
304
-	protected function get_rate_response( $rate, $selected_rate = '' ) {
305
-		return $this->prepare_currency_response(
306
-			[
307
-				'rate_id'       => $this->get_rate_prop( $rate, 'id' ),
308
-				'name'          => $this->prepare_html_response( $this->get_rate_prop( $rate, 'label' ) ),
309
-				'description'   => $this->prepare_html_response( $this->get_rate_prop( $rate, 'description' ) ),
310
-				'delivery_time' => $this->prepare_html_response( $this->get_rate_prop( $rate, 'delivery_time' ) ),
311
-				'price'         => $this->prepare_money_response( $this->get_rate_prop( $rate, 'cost' ), wc_get_price_decimals() ),
312
-				'taxes'         => $this->prepare_money_response( array_sum( $this->get_rate_prop( $rate, 'taxes' ) ), wc_get_price_decimals() ),
313
-				'instance_id'   => $this->get_rate_prop( $rate, 'instance_id' ),
314
-				'method_id'     => $this->get_rate_prop( $rate, 'method_id' ),
315
-				'meta_data'     => $this->get_rate_meta_data( $rate ),
316
-				'selected'      => $selected_rate === $this->get_rate_prop( $rate, 'id' ),
317
-			]
318
-		);
319
-	}
297
+    /**
298
+     * Response for a single rate.
299
+     *
300
+     * @param WC_Shipping_Rate $rate Rate object.
301
+     * @param string           $selected_rate Selected rate.
302
+     * @return array
303
+     */
304
+    protected function get_rate_response( $rate, $selected_rate = '' ) {
305
+        return $this->prepare_currency_response(
306
+            [
307
+                'rate_id'       => $this->get_rate_prop( $rate, 'id' ),
308
+                'name'          => $this->prepare_html_response( $this->get_rate_prop( $rate, 'label' ) ),
309
+                'description'   => $this->prepare_html_response( $this->get_rate_prop( $rate, 'description' ) ),
310
+                'delivery_time' => $this->prepare_html_response( $this->get_rate_prop( $rate, 'delivery_time' ) ),
311
+                'price'         => $this->prepare_money_response( $this->get_rate_prop( $rate, 'cost' ), wc_get_price_decimals() ),
312
+                'taxes'         => $this->prepare_money_response( array_sum( $this->get_rate_prop( $rate, 'taxes' ) ), wc_get_price_decimals() ),
313
+                'instance_id'   => $this->get_rate_prop( $rate, 'instance_id' ),
314
+                'method_id'     => $this->get_rate_prop( $rate, 'method_id' ),
315
+                'meta_data'     => $this->get_rate_meta_data( $rate ),
316
+                'selected'      => $selected_rate === $this->get_rate_prop( $rate, 'id' ),
317
+            ]
318
+        );
319
+    }
320 320
 
321
-	/**
322
-	 * Gets a prop of the rate object, if callable.
323
-	 *
324
-	 * @param WC_Shipping_Rate $rate Rate object.
325
-	 * @param string           $prop Prop name.
326
-	 * @return string
327
-	 */
328
-	protected function get_rate_prop( $rate, $prop ) {
329
-		$getter = 'get_' . $prop;
330
-		return \is_callable( array( $rate, $getter ) ) ? $rate->$getter() : '';
331
-	}
321
+    /**
322
+     * Gets a prop of the rate object, if callable.
323
+     *
324
+     * @param WC_Shipping_Rate $rate Rate object.
325
+     * @param string           $prop Prop name.
326
+     * @return string
327
+     */
328
+    protected function get_rate_prop( $rate, $prop ) {
329
+        $getter = 'get_' . $prop;
330
+        return \is_callable( array( $rate, $getter ) ) ? $rate->$getter() : '';
331
+    }
332 332
 
333
-	/**
334
-	 * Converts rate meta data into a suitable response object.
335
-	 *
336
-	 * @param WC_Shipping_Rate $rate Rate object.
337
-	 * @return array
338
-	 */
339
-	protected function get_rate_meta_data( $rate ) {
340
-		$meta_data = $rate->get_meta_data();
333
+    /**
334
+     * Converts rate meta data into a suitable response object.
335
+     *
336
+     * @param WC_Shipping_Rate $rate Rate object.
337
+     * @return array
338
+     */
339
+    protected function get_rate_meta_data( $rate ) {
340
+        $meta_data = $rate->get_meta_data();
341 341
 
342
-		return array_reduce(
343
-			array_keys( $meta_data ),
344
-			function( $return, $key ) use ( $meta_data ) {
345
-				$return[] = [
346
-					'key'   => $key,
347
-					'value' => $meta_data[ $key ],
348
-				];
349
-				return $return;
350
-			},
351
-			[]
352
-		);
353
-	}
342
+        return array_reduce(
343
+            array_keys( $meta_data ),
344
+            function( $return, $key ) use ( $meta_data ) {
345
+                $return[] = [
346
+                    'key'   => $key,
347
+                    'value' => $meta_data[ $key ],
348
+                ];
349
+                return $return;
350
+            },
351
+            []
352
+        );
353
+    }
354 354
 }
Please login to merge, or discard this patch.
Spacing   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -29,94 +29,94 @@  discard block
 block discarded – undo
29 29
 	public function get_properties() {
30 30
 		return [
31 31
 			'package_id'     => [
32
-				'description' => __( 'The ID of the package the shipping rates belong to.', 'woocommerce' ),
33
-				'type'        => [ 'integer', 'string' ],
34
-				'context'     => [ 'view', 'edit' ],
32
+				'description' => __('The ID of the package the shipping rates belong to.', 'woocommerce'),
33
+				'type'        => ['integer', 'string'],
34
+				'context'     => ['view', 'edit'],
35 35
 				'readonly'    => true,
36 36
 			],
37 37
 			'name'           => [
38
-				'description' => __( 'Name of the package.', 'woocommerce' ),
38
+				'description' => __('Name of the package.', 'woocommerce'),
39 39
 				'type'        => 'string',
40
-				'context'     => [ 'view', 'edit' ],
40
+				'context'     => ['view', 'edit'],
41 41
 				'readonly'    => true,
42 42
 			],
43 43
 			'destination'    => [
44
-				'description' => __( 'Shipping destination address.', 'woocommerce' ),
44
+				'description' => __('Shipping destination address.', 'woocommerce'),
45 45
 				'type'        => 'object',
46
-				'context'     => [ 'view', 'edit' ],
46
+				'context'     => ['view', 'edit'],
47 47
 				'readonly'    => true,
48 48
 				'properties'  => [
49 49
 					'address_1' => [
50
-						'description' => __( 'First line of the address being shipped to.', 'woocommerce' ),
50
+						'description' => __('First line of the address being shipped to.', 'woocommerce'),
51 51
 						'type'        => 'string',
52
-						'context'     => [ 'view', 'edit' ],
52
+						'context'     => ['view', 'edit'],
53 53
 						'readonly'    => true,
54 54
 					],
55 55
 					'address_2' => [
56
-						'description' => __( 'Second line of the address being shipped to.', 'woocommerce' ),
56
+						'description' => __('Second line of the address being shipped to.', 'woocommerce'),
57 57
 						'type'        => 'string',
58
-						'context'     => [ 'view', 'edit' ],
58
+						'context'     => ['view', 'edit'],
59 59
 						'readonly'    => true,
60 60
 					],
61 61
 					'city'      => [
62
-						'description' => __( 'City of the address being shipped to.', 'woocommerce' ),
62
+						'description' => __('City of the address being shipped to.', 'woocommerce'),
63 63
 						'type'        => 'string',
64
-						'context'     => [ 'view', 'edit' ],
64
+						'context'     => ['view', 'edit'],
65 65
 						'readonly'    => true,
66 66
 					],
67 67
 					'state'     => [
68
-						'description' => __( 'ISO code, or name, for the state, province, or district of the address being shipped to.', 'woocommerce' ),
68
+						'description' => __('ISO code, or name, for the state, province, or district of the address being shipped to.', 'woocommerce'),
69 69
 						'type'        => 'string',
70
-						'context'     => [ 'view', 'edit' ],
70
+						'context'     => ['view', 'edit'],
71 71
 						'readonly'    => true,
72 72
 					],
73 73
 					'postcode'  => [
74
-						'description' => __( 'Zip or Postcode of the address being shipped to.', 'woocommerce' ),
74
+						'description' => __('Zip or Postcode of the address being shipped to.', 'woocommerce'),
75 75
 						'type'        => 'string',
76
-						'context'     => [ 'view', 'edit' ],
76
+						'context'     => ['view', 'edit'],
77 77
 						'readonly'    => true,
78 78
 					],
79 79
 					'country'   => [
80
-						'description' => __( 'ISO code for the country of the address being shipped to.', 'woocommerce' ),
80
+						'description' => __('ISO code for the country of the address being shipped to.', 'woocommerce'),
81 81
 						'type'        => 'string',
82
-						'context'     => [ 'view', 'edit' ],
82
+						'context'     => ['view', 'edit'],
83 83
 						'readonly'    => true,
84 84
 					],
85 85
 				],
86 86
 			],
87 87
 			'items'          => [
88
-				'description' => __( 'List of cart items the returned shipping rates apply to.', 'woocommerce' ),
88
+				'description' => __('List of cart items the returned shipping rates apply to.', 'woocommerce'),
89 89
 				'type'        => 'array',
90
-				'context'     => [ 'view', 'edit' ],
90
+				'context'     => ['view', 'edit'],
91 91
 				'readonly'    => true,
92 92
 				'items'       => [
93 93
 					'type'       => 'object',
94 94
 					'properties' => [
95 95
 						'key'      => [
96
-							'description' => __( 'Unique identifier for the item within the cart.', 'woocommerce' ),
96
+							'description' => __('Unique identifier for the item within the cart.', 'woocommerce'),
97 97
 							'type'        => 'string',
98
-							'context'     => [ 'view', 'edit' ],
98
+							'context'     => ['view', 'edit'],
99 99
 							'readonly'    => true,
100 100
 						],
101 101
 						'name'     => [
102
-							'description' => __( 'Name of the item.', 'woocommerce' ),
102
+							'description' => __('Name of the item.', 'woocommerce'),
103 103
 							'type'        => 'string',
104
-							'context'     => [ 'view', 'edit' ],
104
+							'context'     => ['view', 'edit'],
105 105
 							'readonly'    => true,
106 106
 						],
107 107
 						'quantity' => [
108
-							'description' => __( 'Quantity of the item in the current package.', 'woocommerce' ),
108
+							'description' => __('Quantity of the item in the current package.', 'woocommerce'),
109 109
 							'type'        => 'number',
110
-							'context'     => [ 'view', 'edit' ],
110
+							'context'     => ['view', 'edit'],
111 111
 							'readonly'    => true,
112 112
 						],
113 113
 					],
114 114
 				],
115 115
 			],
116 116
 			'shipping_rates' => [
117
-				'description' => __( 'List of shipping rates.', 'woocommerce' ),
117
+				'description' => __('List of shipping rates.', 'woocommerce'),
118 118
 				'type'        => 'array',
119
-				'context'     => [ 'view', 'edit' ],
119
+				'context'     => ['view', 'edit'],
120 120
 				'readonly'    => true,
121 121
 				'items'       => [
122 122
 					'type'       => 'object',
@@ -135,79 +135,79 @@  discard block
 block discarded – undo
135 135
 		return array_merge(
136 136
 			[
137 137
 				'rate_id'       => [
138
-					'description' => __( 'ID of the shipping rate.', 'woocommerce' ),
138
+					'description' => __('ID of the shipping rate.', 'woocommerce'),
139 139
 					'type'        => 'string',
140
-					'context'     => [ 'view', 'edit' ],
140
+					'context'     => ['view', 'edit'],
141 141
 					'readonly'    => true,
142 142
 				],
143 143
 				'name'          => [
144
-					'description' => __( 'Name of the shipping rate, e.g. Express shipping.', 'woocommerce' ),
144
+					'description' => __('Name of the shipping rate, e.g. Express shipping.', 'woocommerce'),
145 145
 					'type'        => 'string',
146
-					'context'     => [ 'view', 'edit' ],
146
+					'context'     => ['view', 'edit'],
147 147
 					'readonly'    => true,
148 148
 				],
149 149
 				'description'   => [
150
-					'description' => __( 'Description of the shipping rate, e.g. Dispatched via USPS.', 'woocommerce' ),
150
+					'description' => __('Description of the shipping rate, e.g. Dispatched via USPS.', 'woocommerce'),
151 151
 					'type'        => 'string',
152
-					'context'     => [ 'view', 'edit' ],
152
+					'context'     => ['view', 'edit'],
153 153
 					'readonly'    => true,
154 154
 				],
155 155
 				'delivery_time' => [
156
-					'description' => __( 'Delivery time estimate text, e.g. 3-5 business days.', 'woocommerce' ),
156
+					'description' => __('Delivery time estimate text, e.g. 3-5 business days.', 'woocommerce'),
157 157
 					'type'        => 'string',
158
-					'context'     => [ 'view', 'edit' ],
158
+					'context'     => ['view', 'edit'],
159 159
 					'readonly'    => true,
160 160
 				],
161 161
 				'price'         => [
162
-					'description' => __( 'Price of this shipping rate using the smallest unit of the currency.', 'woocommerce' ),
162
+					'description' => __('Price of this shipping rate using the smallest unit of the currency.', 'woocommerce'),
163 163
 					'type'        => 'string',
164
-					'context'     => [ 'view', 'edit' ],
164
+					'context'     => ['view', 'edit'],
165 165
 					'readonly'    => true,
166 166
 				],
167 167
 				'taxes'         => [
168
-					'description' => __( 'Taxes applied to this shipping rate using the smallest unit of the currency.', 'woocommerce' ),
168
+					'description' => __('Taxes applied to this shipping rate using the smallest unit of the currency.', 'woocommerce'),
169 169
 					'type'        => 'string',
170
-					'context'     => [ 'view', 'edit' ],
170
+					'context'     => ['view', 'edit'],
171 171
 					'readonly'    => true,
172 172
 				],
173 173
 				'method_id'     => [
174
-					'description' => __( 'ID of the shipping method that provided the rate.', 'woocommerce' ),
174
+					'description' => __('ID of the shipping method that provided the rate.', 'woocommerce'),
175 175
 					'type'        => 'string',
176
-					'context'     => [ 'view', 'edit' ],
176
+					'context'     => ['view', 'edit'],
177 177
 					'readonly'    => true,
178 178
 				],
179 179
 				'instance_id'   => [
180
-					'description' => __( 'Instance ID of the shipping method that provided the rate.', 'woocommerce' ),
180
+					'description' => __('Instance ID of the shipping method that provided the rate.', 'woocommerce'),
181 181
 					'type'        => 'integer',
182
-					'context'     => [ 'view', 'edit' ],
182
+					'context'     => ['view', 'edit'],
183 183
 					'readonly'    => true,
184 184
 				],
185 185
 				'meta_data'     => [
186
-					'description' => __( 'Meta data attached to the shipping rate.', 'woocommerce' ),
186
+					'description' => __('Meta data attached to the shipping rate.', 'woocommerce'),
187 187
 					'type'        => 'array',
188
-					'context'     => [ 'view', 'edit' ],
188
+					'context'     => ['view', 'edit'],
189 189
 					'items'       => [
190 190
 						'type'       => 'object',
191 191
 						'properties' => [
192 192
 							'key'   => [
193
-								'description' => __( 'Meta key.', 'woocommerce' ),
193
+								'description' => __('Meta key.', 'woocommerce'),
194 194
 								'type'        => 'string',
195
-								'context'     => [ 'view', 'edit' ],
195
+								'context'     => ['view', 'edit'],
196 196
 								'readonly'    => true,
197 197
 							],
198 198
 							'value' => [
199
-								'description' => __( 'Meta value.', 'woocommerce' ),
199
+								'description' => __('Meta value.', 'woocommerce'),
200 200
 								'type'        => 'string',
201
-								'context'     => [ 'view', 'edit' ],
201
+								'context'     => ['view', 'edit'],
202 202
 								'readonly'    => true,
203 203
 							],
204 204
 						],
205 205
 					],
206 206
 				],
207 207
 				'selected'      => [
208
-					'description' => __( 'True if this is the rate currently selected by the customer for the cart.', 'woocommerce' ),
208
+					'description' => __('True if this is the rate currently selected by the customer for the cart.', 'woocommerce'),
209 209
 					'type'        => 'boolean',
210
-					'context'     => [ 'view', 'edit' ],
210
+					'context'     => ['view', 'edit'],
211 211
 					'readonly'    => true,
212 212
 				],
213 213
 			],
@@ -221,13 +221,13 @@  discard block
 block discarded – undo
221 221
 	 * @param array $package Shipping package complete with rates from WooCommerce.
222 222
 	 * @return array
223 223
 	 */
224
-	public function get_item_response( $package ) {
224
+	public function get_item_response($package) {
225 225
 		return [
226 226
 			'package_id'     => $package['package_id'],
227 227
 			'name'           => $package['package_name'],
228
-			'destination'    => $this->prepare_package_destination_response( $package ),
229
-			'items'          => $this->prepare_package_items_response( $package ),
230
-			'shipping_rates' => $this->prepare_package_shipping_rates_response( $package ),
228
+			'destination'    => $this->prepare_package_destination_response($package),
229
+			'items'          => $this->prepare_package_items_response($package),
230
+			'shipping_rates' => $this->prepare_package_shipping_rates_response($package),
231 231
 		];
232 232
 	}
233 233
 
@@ -237,9 +237,9 @@  discard block
 block discarded – undo
237 237
 	 * @param array $package Shipping package complete with rates from WooCommerce.
238 238
 	 * @return object
239 239
 	 */
240
-	protected function prepare_package_destination_response( $package ) {
240
+	protected function prepare_package_destination_response($package) {
241 241
 		// If address_1 fails check address for back compatability.
242
-		$address = isset( $package['destination']['address_1'] ) ? $package['destination']['address_1'] : $package['destination']['address'];
242
+		$address = isset($package['destination']['address_1']) ? $package['destination']['address_1'] : $package['destination']['address'];
243 243
 		return (object) $this->prepare_html_response(
244 244
 			[
245 245
 				'address_1' => $address,
@@ -258,9 +258,9 @@  discard block
 block discarded – undo
258 258
 	 * @param array $package Shipping package complete with rates from WooCommerce.
259 259
 	 * @return array
260 260
 	 */
261
-	protected function prepare_package_items_response( $package ) {
261
+	protected function prepare_package_items_response($package) {
262 262
 		$items = array();
263
-		foreach ( $package['contents'] as $item_id => $values ) {
263
+		foreach ($package['contents'] as $item_id => $values) {
264 264
 			$items[] = [
265 265
 				'key'      => $item_id,
266 266
 				'name'     => $values['data']->get_name(),
@@ -276,19 +276,19 @@  discard block
 block discarded – undo
276 276
 	 * @param array $package Shipping package complete with rates from WooCommerce.
277 277
 	 * @return array
278 278
 	 */
279
-	protected function prepare_package_shipping_rates_response( $package ) {
279
+	protected function prepare_package_shipping_rates_response($package) {
280 280
 		$rates          = $package['rates'];
281
-		$selected_rates = wc()->session->get( 'chosen_shipping_methods', array() );
282
-		$selected_rate  = isset( $selected_rates[ $package['package_id'] ] ) ? $selected_rates[ $package['package_id'] ] : '';
281
+		$selected_rates = wc()->session->get('chosen_shipping_methods', array());
282
+		$selected_rate  = isset($selected_rates[$package['package_id']]) ? $selected_rates[$package['package_id']] : '';
283 283
 
284
-		if ( empty( $selected_rate ) && ! empty( $package['rates'] ) ) {
285
-			$selected_rate = wc_get_chosen_shipping_method_for_package( $package['package_id'], $package );
284
+		if (empty($selected_rate) && !empty($package['rates'])) {
285
+			$selected_rate = wc_get_chosen_shipping_method_for_package($package['package_id'], $package);
286 286
 		}
287 287
 
288 288
 		$response = [];
289 289
 
290
-		foreach ( $package['rates'] as $rate ) {
291
-			$response[] = $this->get_rate_response( $rate, $selected_rate );
290
+		foreach ($package['rates'] as $rate) {
291
+			$response[] = $this->get_rate_response($rate, $selected_rate);
292 292
 		}
293 293
 
294 294
 		return $response;
@@ -301,19 +301,19 @@  discard block
 block discarded – undo
301 301
 	 * @param string           $selected_rate Selected rate.
302 302
 	 * @return array
303 303
 	 */
304
-	protected function get_rate_response( $rate, $selected_rate = '' ) {
304
+	protected function get_rate_response($rate, $selected_rate = '') {
305 305
 		return $this->prepare_currency_response(
306 306
 			[
307
-				'rate_id'       => $this->get_rate_prop( $rate, 'id' ),
308
-				'name'          => $this->prepare_html_response( $this->get_rate_prop( $rate, 'label' ) ),
309
-				'description'   => $this->prepare_html_response( $this->get_rate_prop( $rate, 'description' ) ),
310
-				'delivery_time' => $this->prepare_html_response( $this->get_rate_prop( $rate, 'delivery_time' ) ),
311
-				'price'         => $this->prepare_money_response( $this->get_rate_prop( $rate, 'cost' ), wc_get_price_decimals() ),
312
-				'taxes'         => $this->prepare_money_response( array_sum( $this->get_rate_prop( $rate, 'taxes' ) ), wc_get_price_decimals() ),
313
-				'instance_id'   => $this->get_rate_prop( $rate, 'instance_id' ),
314
-				'method_id'     => $this->get_rate_prop( $rate, 'method_id' ),
315
-				'meta_data'     => $this->get_rate_meta_data( $rate ),
316
-				'selected'      => $selected_rate === $this->get_rate_prop( $rate, 'id' ),
307
+				'rate_id'       => $this->get_rate_prop($rate, 'id'),
308
+				'name'          => $this->prepare_html_response($this->get_rate_prop($rate, 'label')),
309
+				'description'   => $this->prepare_html_response($this->get_rate_prop($rate, 'description')),
310
+				'delivery_time' => $this->prepare_html_response($this->get_rate_prop($rate, 'delivery_time')),
311
+				'price'         => $this->prepare_money_response($this->get_rate_prop($rate, 'cost'), wc_get_price_decimals()),
312
+				'taxes'         => $this->prepare_money_response(array_sum($this->get_rate_prop($rate, 'taxes')), wc_get_price_decimals()),
313
+				'instance_id'   => $this->get_rate_prop($rate, 'instance_id'),
314
+				'method_id'     => $this->get_rate_prop($rate, 'method_id'),
315
+				'meta_data'     => $this->get_rate_meta_data($rate),
316
+				'selected'      => $selected_rate === $this->get_rate_prop($rate, 'id'),
317 317
 			]
318 318
 		);
319 319
 	}
@@ -325,9 +325,9 @@  discard block
 block discarded – undo
325 325
 	 * @param string           $prop Prop name.
326 326
 	 * @return string
327 327
 	 */
328
-	protected function get_rate_prop( $rate, $prop ) {
328
+	protected function get_rate_prop($rate, $prop) {
329 329
 		$getter = 'get_' . $prop;
330
-		return \is_callable( array( $rate, $getter ) ) ? $rate->$getter() : '';
330
+		return \is_callable(array($rate, $getter)) ? $rate->$getter() : '';
331 331
 	}
332 332
 
333 333
 	/**
@@ -336,15 +336,15 @@  discard block
 block discarded – undo
336 336
 	 * @param WC_Shipping_Rate $rate Rate object.
337 337
 	 * @return array
338 338
 	 */
339
-	protected function get_rate_meta_data( $rate ) {
339
+	protected function get_rate_meta_data($rate) {
340 340
 		$meta_data = $rate->get_meta_data();
341 341
 
342 342
 		return array_reduce(
343
-			array_keys( $meta_data ),
344
-			function( $return, $key ) use ( $meta_data ) {
343
+			array_keys($meta_data),
344
+			function($return, $key) use ($meta_data) {
345 345
 				$return[] = [
346 346
 					'key'   => $key,
347
-					'value' => $meta_data[ $key ],
347
+					'value' => $meta_data[$key],
348 348
 				];
349 349
 				return $return;
350 350
 			},
Please login to merge, or discard this patch.
packages/woocommerce-blocks/src/StoreApi/Schemas/V1/TermSchema.php 2 patches
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -5,80 +5,80 @@
 block discarded – undo
5 5
  * TermSchema class.
6 6
  */
7 7
 class TermSchema extends AbstractSchema {
8
-	/**
9
-	 * The schema item name.
10
-	 *
11
-	 * @var string
12
-	 */
13
-	protected $title = 'term';
8
+    /**
9
+     * The schema item name.
10
+     *
11
+     * @var string
12
+     */
13
+    protected $title = 'term';
14 14
 
15
-	/**
16
-	 * The schema item identifier.
17
-	 *
18
-	 * @var string
19
-	 */
20
-	const IDENTIFIER = 'term';
15
+    /**
16
+     * The schema item identifier.
17
+     *
18
+     * @var string
19
+     */
20
+    const IDENTIFIER = 'term';
21 21
 
22
-	/**
23
-	 * Term properties.
24
-	 *
25
-	 * @return array
26
-	 */
27
-	public function get_properties() {
28
-		return [
29
-			'id'          => array(
30
-				'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
31
-				'type'        => 'integer',
32
-				'context'     => array( 'view', 'edit' ),
33
-				'readonly'    => true,
34
-			),
35
-			'name'        => array(
36
-				'description' => __( 'Term name.', 'woocommerce' ),
37
-				'type'        => 'string',
38
-				'context'     => array( 'view', 'edit' ),
39
-				'readonly'    => true,
40
-			),
41
-			'slug'        => array(
42
-				'description' => __( 'String based identifier for the term.', 'woocommerce' ),
43
-				'type'        => 'string',
44
-				'context'     => array( 'view', 'edit' ),
45
-				'readonly'    => true,
46
-			),
47
-			'description' => array(
48
-				'description' => __( 'Term description.', 'woocommerce' ),
49
-				'type'        => 'string',
50
-				'context'     => array( 'view', 'edit' ),
51
-				'readonly'    => true,
52
-			),
53
-			'parent'      => array(
54
-				'description' => __( 'Parent term ID, if applicable.', 'woocommerce' ),
55
-				'type'        => 'integer',
56
-				'context'     => array( 'view', 'edit' ),
57
-				'readonly'    => true,
58
-			),
59
-			'count'       => array(
60
-				'description' => __( 'Number of objects (posts of any type) assigned to the term.', 'woocommerce' ),
61
-				'type'        => 'integer',
62
-				'context'     => array( 'view', 'edit' ),
63
-				'readonly'    => true,
64
-			),
65
-		];
66
-	}
22
+    /**
23
+     * Term properties.
24
+     *
25
+     * @return array
26
+     */
27
+    public function get_properties() {
28
+        return [
29
+            'id'          => array(
30
+                'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
31
+                'type'        => 'integer',
32
+                'context'     => array( 'view', 'edit' ),
33
+                'readonly'    => true,
34
+            ),
35
+            'name'        => array(
36
+                'description' => __( 'Term name.', 'woocommerce' ),
37
+                'type'        => 'string',
38
+                'context'     => array( 'view', 'edit' ),
39
+                'readonly'    => true,
40
+            ),
41
+            'slug'        => array(
42
+                'description' => __( 'String based identifier for the term.', 'woocommerce' ),
43
+                'type'        => 'string',
44
+                'context'     => array( 'view', 'edit' ),
45
+                'readonly'    => true,
46
+            ),
47
+            'description' => array(
48
+                'description' => __( 'Term description.', 'woocommerce' ),
49
+                'type'        => 'string',
50
+                'context'     => array( 'view', 'edit' ),
51
+                'readonly'    => true,
52
+            ),
53
+            'parent'      => array(
54
+                'description' => __( 'Parent term ID, if applicable.', 'woocommerce' ),
55
+                'type'        => 'integer',
56
+                'context'     => array( 'view', 'edit' ),
57
+                'readonly'    => true,
58
+            ),
59
+            'count'       => array(
60
+                'description' => __( 'Number of objects (posts of any type) assigned to the term.', 'woocommerce' ),
61
+                'type'        => 'integer',
62
+                'context'     => array( 'view', 'edit' ),
63
+                'readonly'    => true,
64
+            ),
65
+        ];
66
+    }
67 67
 
68
-	/**
69
-	 * Convert a term object into an object suitable for the response.
70
-	 *
71
-	 * @param \WP_Term $term Term object.
72
-	 * @return array
73
-	 */
74
-	public function get_item_response( $term ) {
75
-		return [
76
-			'id'          => (int) $term->term_id,
77
-			'name'        => $this->prepare_html_response( $term->name ),
78
-			'slug'        => $term->slug,
79
-			'description' => $this->prepare_html_response( $term->description ),
80
-			'parent'      => (int) $term->parent,
81
-			'count'       => (int) $term->count,
82
-		];
83
-	}
68
+    /**
69
+     * Convert a term object into an object suitable for the response.
70
+     *
71
+     * @param \WP_Term $term Term object.
72
+     * @return array
73
+     */
74
+    public function get_item_response( $term ) {
75
+        return [
76
+            'id'          => (int) $term->term_id,
77
+            'name'        => $this->prepare_html_response( $term->name ),
78
+            'slug'        => $term->slug,
79
+            'description' => $this->prepare_html_response( $term->description ),
80
+            'parent'      => (int) $term->parent,
81
+            'count'       => (int) $term->count,
82
+        ];
83
+    }
84 84
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -27,39 +27,39 @@  discard block
 block discarded – undo
27 27
 	public function get_properties() {
28 28
 		return [
29 29
 			'id'          => array(
30
-				'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
30
+				'description' => __('Unique identifier for the resource.', 'woocommerce'),
31 31
 				'type'        => 'integer',
32
-				'context'     => array( 'view', 'edit' ),
32
+				'context'     => array('view', 'edit'),
33 33
 				'readonly'    => true,
34 34
 			),
35 35
 			'name'        => array(
36
-				'description' => __( 'Term name.', 'woocommerce' ),
36
+				'description' => __('Term name.', 'woocommerce'),
37 37
 				'type'        => 'string',
38
-				'context'     => array( 'view', 'edit' ),
38
+				'context'     => array('view', 'edit'),
39 39
 				'readonly'    => true,
40 40
 			),
41 41
 			'slug'        => array(
42
-				'description' => __( 'String based identifier for the term.', 'woocommerce' ),
42
+				'description' => __('String based identifier for the term.', 'woocommerce'),
43 43
 				'type'        => 'string',
44
-				'context'     => array( 'view', 'edit' ),
44
+				'context'     => array('view', 'edit'),
45 45
 				'readonly'    => true,
46 46
 			),
47 47
 			'description' => array(
48
-				'description' => __( 'Term description.', 'woocommerce' ),
48
+				'description' => __('Term description.', 'woocommerce'),
49 49
 				'type'        => 'string',
50
-				'context'     => array( 'view', 'edit' ),
50
+				'context'     => array('view', 'edit'),
51 51
 				'readonly'    => true,
52 52
 			),
53 53
 			'parent'      => array(
54
-				'description' => __( 'Parent term ID, if applicable.', 'woocommerce' ),
54
+				'description' => __('Parent term ID, if applicable.', 'woocommerce'),
55 55
 				'type'        => 'integer',
56
-				'context'     => array( 'view', 'edit' ),
56
+				'context'     => array('view', 'edit'),
57 57
 				'readonly'    => true,
58 58
 			),
59 59
 			'count'       => array(
60
-				'description' => __( 'Number of objects (posts of any type) assigned to the term.', 'woocommerce' ),
60
+				'description' => __('Number of objects (posts of any type) assigned to the term.', 'woocommerce'),
61 61
 				'type'        => 'integer',
62
-				'context'     => array( 'view', 'edit' ),
62
+				'context'     => array('view', 'edit'),
63 63
 				'readonly'    => true,
64 64
 			),
65 65
 		];
@@ -71,12 +71,12 @@  discard block
 block discarded – undo
71 71
 	 * @param \WP_Term $term Term object.
72 72
 	 * @return array
73 73
 	 */
74
-	public function get_item_response( $term ) {
74
+	public function get_item_response($term) {
75 75
 		return [
76 76
 			'id'          => (int) $term->term_id,
77
-			'name'        => $this->prepare_html_response( $term->name ),
77
+			'name'        => $this->prepare_html_response($term->name),
78 78
 			'slug'        => $term->slug,
79
-			'description' => $this->prepare_html_response( $term->description ),
79
+			'description' => $this->prepare_html_response($term->description),
80 80
 			'parent'      => (int) $term->parent,
81 81
 			'count'       => (int) $term->count,
82 82
 		];
Please login to merge, or discard this patch.
woocommerce-blocks/src/StoreApi/Schemas/V1/ProductCollectionDataSchema.php 2 patches
Indentation   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -5,139 +5,139 @@
 block discarded – undo
5 5
  * ProductCollectionDataSchema class.
6 6
  */
7 7
 class ProductCollectionDataSchema extends AbstractSchema {
8
-	/**
9
-	 * The schema item name.
10
-	 *
11
-	 * @var string
12
-	 */
13
-	protected $title = 'product-collection-data';
8
+    /**
9
+     * The schema item name.
10
+     *
11
+     * @var string
12
+     */
13
+    protected $title = 'product-collection-data';
14 14
 
15
-	/**
16
-	 * The schema item identifier.
17
-	 *
18
-	 * @var string
19
-	 */
20
-	const IDENTIFIER = 'product-collection-data';
15
+    /**
16
+     * The schema item identifier.
17
+     *
18
+     * @var string
19
+     */
20
+    const IDENTIFIER = 'product-collection-data';
21 21
 
22
-	/**
23
-	 * Product collection data schema properties.
24
-	 *
25
-	 * @return array
26
-	 */
27
-	public function get_properties() {
28
-		return [
29
-			'price_range'         => [
30
-				'description' => __( 'Min and max prices found in collection of products, provided using the smallest unit of the currency.', 'woocommerce' ),
31
-				'type'        => [ 'object', 'null' ],
32
-				'context'     => [ 'view', 'edit' ],
33
-				'readonly'    => true,
34
-				'properties'  => array_merge(
35
-					$this->get_store_currency_properties(),
36
-					[
37
-						'min_price' => [
38
-							'description' => __( 'Min price found in collection of products.', 'woocommerce' ),
39
-							'type'        => 'string',
40
-							'context'     => [ 'view', 'edit' ],
41
-							'readonly'    => true,
42
-						],
43
-						'max_price' => [
44
-							'description' => __( 'Max price found in collection of products.', 'woocommerce' ),
45
-							'type'        => 'string',
46
-							'context'     => [ 'view', 'edit' ],
47
-							'readonly'    => true,
48
-						],
49
-					]
50
-				),
51
-			],
52
-			'attribute_counts'    => [
53
-				'description' => __( 'Returns number of products within attribute terms.', 'woocommerce' ),
54
-				'type'        => [ 'array', 'null' ],
55
-				'context'     => [ 'view', 'edit' ],
56
-				'readonly'    => true,
57
-				'items'       => [
58
-					'type'       => 'object',
59
-					'properties' => [
60
-						'term'  => [
61
-							'description' => __( 'Term ID', 'woocommerce' ),
62
-							'type'        => 'integer',
63
-							'context'     => [ 'view', 'edit' ],
64
-							'readonly'    => true,
65
-						],
66
-						'count' => [
67
-							'description' => __( 'Number of products.', 'woocommerce' ),
68
-							'type'        => 'integer',
69
-							'context'     => [ 'view', 'edit' ],
70
-							'readonly'    => true,
71
-						],
72
-					],
73
-				],
74
-			],
75
-			'rating_counts'       => [
76
-				'description' => __( 'Returns number of products with each average rating.', 'woocommerce' ),
77
-				'type'        => [ 'array', 'null' ],
78
-				'context'     => [ 'view', 'edit' ],
79
-				'readonly'    => true,
80
-				'items'       => [
81
-					'type'       => 'object',
82
-					'properties' => [
83
-						'rating' => [
84
-							'description' => __( 'Average rating', 'woocommerce' ),
85
-							'type'        => 'integer',
86
-							'context'     => [ 'view', 'edit' ],
87
-							'readonly'    => true,
88
-						],
89
-						'count'  => [
90
-							'description' => __( 'Number of products.', 'woocommerce' ),
91
-							'type'        => 'integer',
92
-							'context'     => [ 'view', 'edit' ],
93
-							'readonly'    => true,
94
-						],
95
-					],
96
-				],
97
-			],
98
-			'stock_status_counts' => [
99
-				'description' => __( 'Returns number of products with each stock status.', 'woocommerce' ),
100
-				'type'        => [ 'array', 'null' ],
101
-				'context'     => [ 'view', 'edit' ],
102
-				'readonly'    => true,
103
-				'items'       => [
104
-					'type'       => 'object',
105
-					'properties' => [
106
-						'status' => [
107
-							'description' => __( 'Status', 'woocommerce' ),
108
-							'type'        => 'string',
109
-							'context'     => [ 'view', 'edit' ],
110
-							'readonly'    => true,
111
-						],
112
-						'count'  => [
113
-							'description' => __( 'Number of products.', 'woocommerce' ),
114
-							'type'        => 'integer',
115
-							'context'     => [ 'view', 'edit' ],
116
-							'readonly'    => true,
117
-						],
118
-					],
119
-				],
120
-			],
121
-		];
122
-	}
22
+    /**
23
+     * Product collection data schema properties.
24
+     *
25
+     * @return array
26
+     */
27
+    public function get_properties() {
28
+        return [
29
+            'price_range'         => [
30
+                'description' => __( 'Min and max prices found in collection of products, provided using the smallest unit of the currency.', 'woocommerce' ),
31
+                'type'        => [ 'object', 'null' ],
32
+                'context'     => [ 'view', 'edit' ],
33
+                'readonly'    => true,
34
+                'properties'  => array_merge(
35
+                    $this->get_store_currency_properties(),
36
+                    [
37
+                        'min_price' => [
38
+                            'description' => __( 'Min price found in collection of products.', 'woocommerce' ),
39
+                            'type'        => 'string',
40
+                            'context'     => [ 'view', 'edit' ],
41
+                            'readonly'    => true,
42
+                        ],
43
+                        'max_price' => [
44
+                            'description' => __( 'Max price found in collection of products.', 'woocommerce' ),
45
+                            'type'        => 'string',
46
+                            'context'     => [ 'view', 'edit' ],
47
+                            'readonly'    => true,
48
+                        ],
49
+                    ]
50
+                ),
51
+            ],
52
+            'attribute_counts'    => [
53
+                'description' => __( 'Returns number of products within attribute terms.', 'woocommerce' ),
54
+                'type'        => [ 'array', 'null' ],
55
+                'context'     => [ 'view', 'edit' ],
56
+                'readonly'    => true,
57
+                'items'       => [
58
+                    'type'       => 'object',
59
+                    'properties' => [
60
+                        'term'  => [
61
+                            'description' => __( 'Term ID', 'woocommerce' ),
62
+                            'type'        => 'integer',
63
+                            'context'     => [ 'view', 'edit' ],
64
+                            'readonly'    => true,
65
+                        ],
66
+                        'count' => [
67
+                            'description' => __( 'Number of products.', 'woocommerce' ),
68
+                            'type'        => 'integer',
69
+                            'context'     => [ 'view', 'edit' ],
70
+                            'readonly'    => true,
71
+                        ],
72
+                    ],
73
+                ],
74
+            ],
75
+            'rating_counts'       => [
76
+                'description' => __( 'Returns number of products with each average rating.', 'woocommerce' ),
77
+                'type'        => [ 'array', 'null' ],
78
+                'context'     => [ 'view', 'edit' ],
79
+                'readonly'    => true,
80
+                'items'       => [
81
+                    'type'       => 'object',
82
+                    'properties' => [
83
+                        'rating' => [
84
+                            'description' => __( 'Average rating', 'woocommerce' ),
85
+                            'type'        => 'integer',
86
+                            'context'     => [ 'view', 'edit' ],
87
+                            'readonly'    => true,
88
+                        ],
89
+                        'count'  => [
90
+                            'description' => __( 'Number of products.', 'woocommerce' ),
91
+                            'type'        => 'integer',
92
+                            'context'     => [ 'view', 'edit' ],
93
+                            'readonly'    => true,
94
+                        ],
95
+                    ],
96
+                ],
97
+            ],
98
+            'stock_status_counts' => [
99
+                'description' => __( 'Returns number of products with each stock status.', 'woocommerce' ),
100
+                'type'        => [ 'array', 'null' ],
101
+                'context'     => [ 'view', 'edit' ],
102
+                'readonly'    => true,
103
+                'items'       => [
104
+                    'type'       => 'object',
105
+                    'properties' => [
106
+                        'status' => [
107
+                            'description' => __( 'Status', 'woocommerce' ),
108
+                            'type'        => 'string',
109
+                            'context'     => [ 'view', 'edit' ],
110
+                            'readonly'    => true,
111
+                        ],
112
+                        'count'  => [
113
+                            'description' => __( 'Number of products.', 'woocommerce' ),
114
+                            'type'        => 'integer',
115
+                            'context'     => [ 'view', 'edit' ],
116
+                            'readonly'    => true,
117
+                        ],
118
+                    ],
119
+                ],
120
+            ],
121
+        ];
122
+    }
123 123
 
124
-	/**
125
-	 * Format data.
126
-	 *
127
-	 * @param array $data Collection data to format and return.
128
-	 * @return array
129
-	 */
130
-	public function get_item_response( $data ) {
131
-		return [
132
-			'price_range'         => ! is_null( $data['min_price'] ) && ! is_null( $data['max_price'] ) ? (object) $this->prepare_currency_response(
133
-				[
134
-					'min_price' => $this->prepare_money_response( $data['min_price'], wc_get_price_decimals() ),
135
-					'max_price' => $this->prepare_money_response( $data['max_price'], wc_get_price_decimals() ),
136
-				]
137
-			) : null,
138
-			'attribute_counts'    => $data['attribute_counts'],
139
-			'rating_counts'       => $data['rating_counts'],
140
-			'stock_status_counts' => $data['stock_status_counts'],
141
-		];
142
-	}
124
+    /**
125
+     * Format data.
126
+     *
127
+     * @param array $data Collection data to format and return.
128
+     * @return array
129
+     */
130
+    public function get_item_response( $data ) {
131
+        return [
132
+            'price_range'         => ! is_null( $data['min_price'] ) && ! is_null( $data['max_price'] ) ? (object) $this->prepare_currency_response(
133
+                [
134
+                    'min_price' => $this->prepare_money_response( $data['min_price'], wc_get_price_decimals() ),
135
+                    'max_price' => $this->prepare_money_response( $data['max_price'], wc_get_price_decimals() ),
136
+                ]
137
+            ) : null,
138
+            'attribute_counts'    => $data['attribute_counts'],
139
+            'rating_counts'       => $data['rating_counts'],
140
+            'stock_status_counts' => $data['stock_status_counts'],
141
+        ];
142
+    }
143 143
 }
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -27,92 +27,92 @@  discard block
 block discarded – undo
27 27
 	public function get_properties() {
28 28
 		return [
29 29
 			'price_range'         => [
30
-				'description' => __( 'Min and max prices found in collection of products, provided using the smallest unit of the currency.', 'woocommerce' ),
31
-				'type'        => [ 'object', 'null' ],
32
-				'context'     => [ 'view', 'edit' ],
30
+				'description' => __('Min and max prices found in collection of products, provided using the smallest unit of the currency.', 'woocommerce'),
31
+				'type'        => ['object', 'null'],
32
+				'context'     => ['view', 'edit'],
33 33
 				'readonly'    => true,
34 34
 				'properties'  => array_merge(
35 35
 					$this->get_store_currency_properties(),
36 36
 					[
37 37
 						'min_price' => [
38
-							'description' => __( 'Min price found in collection of products.', 'woocommerce' ),
38
+							'description' => __('Min price found in collection of products.', 'woocommerce'),
39 39
 							'type'        => 'string',
40
-							'context'     => [ 'view', 'edit' ],
40
+							'context'     => ['view', 'edit'],
41 41
 							'readonly'    => true,
42 42
 						],
43 43
 						'max_price' => [
44
-							'description' => __( 'Max price found in collection of products.', 'woocommerce' ),
44
+							'description' => __('Max price found in collection of products.', 'woocommerce'),
45 45
 							'type'        => 'string',
46
-							'context'     => [ 'view', 'edit' ],
46
+							'context'     => ['view', 'edit'],
47 47
 							'readonly'    => true,
48 48
 						],
49 49
 					]
50 50
 				),
51 51
 			],
52 52
 			'attribute_counts'    => [
53
-				'description' => __( 'Returns number of products within attribute terms.', 'woocommerce' ),
54
-				'type'        => [ 'array', 'null' ],
55
-				'context'     => [ 'view', 'edit' ],
53
+				'description' => __('Returns number of products within attribute terms.', 'woocommerce'),
54
+				'type'        => ['array', 'null'],
55
+				'context'     => ['view', 'edit'],
56 56
 				'readonly'    => true,
57 57
 				'items'       => [
58 58
 					'type'       => 'object',
59 59
 					'properties' => [
60 60
 						'term'  => [
61
-							'description' => __( 'Term ID', 'woocommerce' ),
61
+							'description' => __('Term ID', 'woocommerce'),
62 62
 							'type'        => 'integer',
63
-							'context'     => [ 'view', 'edit' ],
63
+							'context'     => ['view', 'edit'],
64 64
 							'readonly'    => true,
65 65
 						],
66 66
 						'count' => [
67
-							'description' => __( 'Number of products.', 'woocommerce' ),
67
+							'description' => __('Number of products.', 'woocommerce'),
68 68
 							'type'        => 'integer',
69
-							'context'     => [ 'view', 'edit' ],
69
+							'context'     => ['view', 'edit'],
70 70
 							'readonly'    => true,
71 71
 						],
72 72
 					],
73 73
 				],
74 74
 			],
75 75
 			'rating_counts'       => [
76
-				'description' => __( 'Returns number of products with each average rating.', 'woocommerce' ),
77
-				'type'        => [ 'array', 'null' ],
78
-				'context'     => [ 'view', 'edit' ],
76
+				'description' => __('Returns number of products with each average rating.', 'woocommerce'),
77
+				'type'        => ['array', 'null'],
78
+				'context'     => ['view', 'edit'],
79 79
 				'readonly'    => true,
80 80
 				'items'       => [
81 81
 					'type'       => 'object',
82 82
 					'properties' => [
83 83
 						'rating' => [
84
-							'description' => __( 'Average rating', 'woocommerce' ),
84
+							'description' => __('Average rating', 'woocommerce'),
85 85
 							'type'        => 'integer',
86
-							'context'     => [ 'view', 'edit' ],
86
+							'context'     => ['view', 'edit'],
87 87
 							'readonly'    => true,
88 88
 						],
89 89
 						'count'  => [
90
-							'description' => __( 'Number of products.', 'woocommerce' ),
90
+							'description' => __('Number of products.', 'woocommerce'),
91 91
 							'type'        => 'integer',
92
-							'context'     => [ 'view', 'edit' ],
92
+							'context'     => ['view', 'edit'],
93 93
 							'readonly'    => true,
94 94
 						],
95 95
 					],
96 96
 				],
97 97
 			],
98 98
 			'stock_status_counts' => [
99
-				'description' => __( 'Returns number of products with each stock status.', 'woocommerce' ),
100
-				'type'        => [ 'array', 'null' ],
101
-				'context'     => [ 'view', 'edit' ],
99
+				'description' => __('Returns number of products with each stock status.', 'woocommerce'),
100
+				'type'        => ['array', 'null'],
101
+				'context'     => ['view', 'edit'],
102 102
 				'readonly'    => true,
103 103
 				'items'       => [
104 104
 					'type'       => 'object',
105 105
 					'properties' => [
106 106
 						'status' => [
107
-							'description' => __( 'Status', 'woocommerce' ),
107
+							'description' => __('Status', 'woocommerce'),
108 108
 							'type'        => 'string',
109
-							'context'     => [ 'view', 'edit' ],
109
+							'context'     => ['view', 'edit'],
110 110
 							'readonly'    => true,
111 111
 						],
112 112
 						'count'  => [
113
-							'description' => __( 'Number of products.', 'woocommerce' ),
113
+							'description' => __('Number of products.', 'woocommerce'),
114 114
 							'type'        => 'integer',
115
-							'context'     => [ 'view', 'edit' ],
115
+							'context'     => ['view', 'edit'],
116 116
 							'readonly'    => true,
117 117
 						],
118 118
 					],
@@ -127,12 +127,12 @@  discard block
 block discarded – undo
127 127
 	 * @param array $data Collection data to format and return.
128 128
 	 * @return array
129 129
 	 */
130
-	public function get_item_response( $data ) {
130
+	public function get_item_response($data) {
131 131
 		return [
132
-			'price_range'         => ! is_null( $data['min_price'] ) && ! is_null( $data['max_price'] ) ? (object) $this->prepare_currency_response(
132
+			'price_range'         => !is_null($data['min_price']) && !is_null($data['max_price']) ? (object) $this->prepare_currency_response(
133 133
 				[
134
-					'min_price' => $this->prepare_money_response( $data['min_price'], wc_get_price_decimals() ),
135
-					'max_price' => $this->prepare_money_response( $data['max_price'], wc_get_price_decimals() ),
134
+					'min_price' => $this->prepare_money_response($data['min_price'], wc_get_price_decimals()),
135
+					'max_price' => $this->prepare_money_response($data['max_price'], wc_get_price_decimals()),
136 136
 				]
137 137
 			) : null,
138 138
 			'attribute_counts'    => $data['attribute_counts'],
Please login to merge, or discard this patch.
packages/woocommerce-blocks/src/StoreApi/Schemas/V1/CartSchema.php 2 patches
Indentation   +368 added lines, -368 removed lines patch added patch discarded remove patch
@@ -12,394 +12,394 @@
 block discarded – undo
12 12
  * CartSchema class.
13 13
  */
14 14
 class CartSchema extends AbstractSchema {
15
-	/**
16
-	 * The schema item name.
17
-	 *
18
-	 * @var string
19
-	 */
20
-	protected $title = 'cart';
15
+    /**
16
+     * The schema item name.
17
+     *
18
+     * @var string
19
+     */
20
+    protected $title = 'cart';
21 21
 
22
-	/**
23
-	 * The schema item identifier.
24
-	 *
25
-	 * @var string
26
-	 */
27
-	const IDENTIFIER = 'cart';
22
+    /**
23
+     * The schema item identifier.
24
+     *
25
+     * @var string
26
+     */
27
+    const IDENTIFIER = 'cart';
28 28
 
29
-	/**
30
-	 * Item schema instance.
31
-	 *
32
-	 * @var CartItemSchema
33
-	 */
34
-	public $item_schema;
29
+    /**
30
+     * Item schema instance.
31
+     *
32
+     * @var CartItemSchema
33
+     */
34
+    public $item_schema;
35 35
 
36
-	/**
37
-	 * Coupon schema instance.
38
-	 *
39
-	 * @var CartCouponSchema
40
-	 */
41
-	public $coupon_schema;
36
+    /**
37
+     * Coupon schema instance.
38
+     *
39
+     * @var CartCouponSchema
40
+     */
41
+    public $coupon_schema;
42 42
 
43
-	/**
44
-	 * Fee schema instance.
45
-	 *
46
-	 * @var CartFeeSchema
47
-	 */
48
-	public $fee_schema;
43
+    /**
44
+     * Fee schema instance.
45
+     *
46
+     * @var CartFeeSchema
47
+     */
48
+    public $fee_schema;
49 49
 
50
-	/**
51
-	 * Shipping rates schema instance.
52
-	 *
53
-	 * @var CartShippingRateSchema
54
-	 */
55
-	public $shipping_rate_schema;
50
+    /**
51
+     * Shipping rates schema instance.
52
+     *
53
+     * @var CartShippingRateSchema
54
+     */
55
+    public $shipping_rate_schema;
56 56
 
57
-	/**
58
-	 * Shipping address schema instance.
59
-	 *
60
-	 * @var ShippingAddressSchema
61
-	 */
62
-	public $shipping_address_schema;
57
+    /**
58
+     * Shipping address schema instance.
59
+     *
60
+     * @var ShippingAddressSchema
61
+     */
62
+    public $shipping_address_schema;
63 63
 
64
-	/**
65
-	 * Billing address schema instance.
66
-	 *
67
-	 * @var BillingAddressSchema
68
-	 */
69
-	public $billing_address_schema;
64
+    /**
65
+     * Billing address schema instance.
66
+     *
67
+     * @var BillingAddressSchema
68
+     */
69
+    public $billing_address_schema;
70 70
 
71
-	/**
72
-	 * Error schema instance.
73
-	 *
74
-	 * @var ErrorSchema
75
-	 */
76
-	public $error_schema;
71
+    /**
72
+     * Error schema instance.
73
+     *
74
+     * @var ErrorSchema
75
+     */
76
+    public $error_schema;
77 77
 
78
-	/**
79
-	 * Constructor.
80
-	 *
81
-	 * @param ExtendSchema     $extend Rest Extending instance.
82
-	 * @param SchemaController $controller Schema Controller instance.
83
-	 */
84
-	public function __construct( ExtendSchema $extend, SchemaController $controller ) {
85
-		parent::__construct( $extend, $controller );
86
-		$this->item_schema             = $this->controller->get( CartItemSchema::IDENTIFIER );
87
-		$this->coupon_schema           = $this->controller->get( CartCouponSchema::IDENTIFIER );
88
-		$this->fee_schema              = $this->controller->get( CartFeeSchema::IDENTIFIER );
89
-		$this->shipping_rate_schema    = $this->controller->get( CartShippingRateSchema::IDENTIFIER );
90
-		$this->shipping_address_schema = $this->controller->get( ShippingAddressSchema::IDENTIFIER );
91
-		$this->billing_address_schema  = $this->controller->get( BillingAddressSchema::IDENTIFIER );
92
-		$this->error_schema            = $this->controller->get( ErrorSchema::IDENTIFIER );
93
-	}
78
+    /**
79
+     * Constructor.
80
+     *
81
+     * @param ExtendSchema     $extend Rest Extending instance.
82
+     * @param SchemaController $controller Schema Controller instance.
83
+     */
84
+    public function __construct( ExtendSchema $extend, SchemaController $controller ) {
85
+        parent::__construct( $extend, $controller );
86
+        $this->item_schema             = $this->controller->get( CartItemSchema::IDENTIFIER );
87
+        $this->coupon_schema           = $this->controller->get( CartCouponSchema::IDENTIFIER );
88
+        $this->fee_schema              = $this->controller->get( CartFeeSchema::IDENTIFIER );
89
+        $this->shipping_rate_schema    = $this->controller->get( CartShippingRateSchema::IDENTIFIER );
90
+        $this->shipping_address_schema = $this->controller->get( ShippingAddressSchema::IDENTIFIER );
91
+        $this->billing_address_schema  = $this->controller->get( BillingAddressSchema::IDENTIFIER );
92
+        $this->error_schema            = $this->controller->get( ErrorSchema::IDENTIFIER );
93
+    }
94 94
 
95
-	/**
96
-	 * Cart schema properties.
97
-	 *
98
-	 * @return array
99
-	 */
100
-	public function get_properties() {
101
-		return [
102
-			'coupons'                 => [
103
-				'description' => __( 'List of applied cart coupons.', 'woocommerce' ),
104
-				'type'        => 'array',
105
-				'context'     => [ 'view', 'edit' ],
106
-				'readonly'    => true,
107
-				'items'       => [
108
-					'type'       => 'object',
109
-					'properties' => $this->force_schema_readonly( $this->coupon_schema->get_properties() ),
110
-				],
111
-			],
112
-			'shipping_rates'          => [
113
-				'description' => __( 'List of available shipping rates for the cart.', 'woocommerce' ),
114
-				'type'        => 'array',
115
-				'context'     => [ 'view', 'edit' ],
116
-				'readonly'    => true,
117
-				'items'       => [
118
-					'type'       => 'object',
119
-					'properties' => $this->force_schema_readonly( $this->shipping_rate_schema->get_properties() ),
120
-				],
121
-			],
122
-			'shipping_address'        => [
123
-				'description' => __( 'Current set shipping address for the customer.', 'woocommerce' ),
124
-				'type'        => 'object',
125
-				'context'     => [ 'view', 'edit' ],
126
-				'readonly'    => true,
127
-				'properties'  => $this->force_schema_readonly( $this->shipping_address_schema->get_properties() ),
128
-			],
129
-			'billing_address'         => [
130
-				'description' => __( 'Current set billing address for the customer.', 'woocommerce' ),
131
-				'type'        => 'object',
132
-				'context'     => [ 'view', 'edit' ],
133
-				'readonly'    => true,
134
-				'properties'  => $this->force_schema_readonly( $this->billing_address_schema->get_properties() ),
135
-			],
136
-			'items'                   => [
137
-				'description' => __( 'List of cart items.', 'woocommerce' ),
138
-				'type'        => 'array',
139
-				'context'     => [ 'view', 'edit' ],
140
-				'readonly'    => true,
141
-				'items'       => [
142
-					'type'       => 'object',
143
-					'properties' => $this->force_schema_readonly( $this->item_schema->get_properties() ),
144
-				],
145
-			],
146
-			'items_count'             => [
147
-				'description' => __( 'Number of items in the cart.', 'woocommerce' ),
148
-				'type'        => 'integer',
149
-				'context'     => [ 'view', 'edit' ],
150
-				'readonly'    => true,
151
-			],
152
-			'items_weight'            => [
153
-				'description' => __( 'Total weight (in grams) of all products in the cart.', 'woocommerce' ),
154
-				'type'        => 'number',
155
-				'context'     => [ 'view', 'edit' ],
156
-				'readonly'    => true,
157
-			],
158
-			'needs_payment'           => [
159
-				'description' => __( 'True if the cart needs payment. False for carts with only free products and no shipping costs.', 'woocommerce' ),
160
-				'type'        => 'boolean',
161
-				'context'     => [ 'view', 'edit' ],
162
-				'readonly'    => true,
163
-			],
164
-			'needs_shipping'          => [
165
-				'description' => __( 'True if the cart needs shipping. False for carts with only digital goods or stores with no shipping methods set-up.', 'woocommerce' ),
166
-				'type'        => 'boolean',
167
-				'context'     => [ 'view', 'edit' ],
168
-				'readonly'    => true,
169
-			],
170
-			'has_calculated_shipping' => [
171
-				'description' => __( 'True if the cart meets the criteria for showing shipping costs, and rates have been calculated and included in the totals.', 'woocommerce' ),
172
-				'type'        => 'boolean',
173
-				'context'     => [ 'view', 'edit' ],
174
-				'readonly'    => true,
175
-			],
176
-			'fees'                    => [
177
-				'description' => __( 'List of cart fees.', 'woocommerce' ),
178
-				'type'        => 'array',
179
-				'context'     => [ 'view', 'edit' ],
180
-				'readonly'    => true,
181
-				'items'       => [
182
-					'type'       => 'object',
183
-					'properties' => $this->force_schema_readonly( $this->fee_schema->get_properties() ),
184
-				],
185
-			],
186
-			'totals'                  => [
187
-				'description' => __( 'Cart total amounts provided using the smallest unit of the currency.', 'woocommerce' ),
188
-				'type'        => 'object',
189
-				'context'     => [ 'view', 'edit' ],
190
-				'readonly'    => true,
191
-				'properties'  => array_merge(
192
-					$this->get_store_currency_properties(),
193
-					[
194
-						'total_items'        => [
195
-							'description' => __( 'Total price of items in the cart.', 'woocommerce' ),
196
-							'type'        => 'string',
197
-							'context'     => [ 'view', 'edit' ],
198
-							'readonly'    => true,
199
-						],
200
-						'total_items_tax'    => [
201
-							'description' => __( 'Total tax on items in the cart.', 'woocommerce' ),
202
-							'type'        => 'string',
203
-							'context'     => [ 'view', 'edit' ],
204
-							'readonly'    => true,
205
-						],
206
-						'total_fees'         => [
207
-							'description' => __( 'Total price of any applied fees.', 'woocommerce' ),
208
-							'type'        => 'string',
209
-							'context'     => [ 'view', 'edit' ],
210
-							'readonly'    => true,
211
-						],
212
-						'total_fees_tax'     => [
213
-							'description' => __( 'Total tax on fees.', 'woocommerce' ),
214
-							'type'        => 'string',
215
-							'context'     => [ 'view', 'edit' ],
216
-							'readonly'    => true,
217
-						],
218
-						'total_discount'     => [
219
-							'description' => __( 'Total discount from applied coupons.', 'woocommerce' ),
220
-							'type'        => 'string',
221
-							'context'     => [ 'view', 'edit' ],
222
-							'readonly'    => true,
223
-						],
224
-						'total_discount_tax' => [
225
-							'description' => __( 'Total tax removed due to discount from applied coupons.', 'woocommerce' ),
226
-							'type'        => 'string',
227
-							'context'     => [ 'view', 'edit' ],
228
-							'readonly'    => true,
229
-						],
230
-						'total_shipping'     => [
231
-							'description' => __( 'Total price of shipping. If shipping has not been calculated, a null response will be sent.', 'woocommerce' ),
232
-							'type'        => [ 'string', 'null' ],
233
-							'context'     => [ 'view', 'edit' ],
234
-							'readonly'    => true,
235
-						],
236
-						'total_shipping_tax' => [
237
-							'description' => __( 'Total tax on shipping. If shipping has not been calculated, a null response will be sent.', 'woocommerce' ),
238
-							'type'        => [ 'string', 'null' ],
239
-							'context'     => [ 'view', 'edit' ],
240
-							'readonly'    => true,
241
-						],
242
-						'total_price'        => [
243
-							'description' => __( 'Total price the customer will pay.', 'woocommerce' ),
244
-							'type'        => 'string',
245
-							'context'     => [ 'view', 'edit' ],
246
-							'readonly'    => true,
247
-						],
248
-						'total_tax'          => [
249
-							'description' => __( 'Total tax applied to items and shipping.', 'woocommerce' ),
250
-							'type'        => 'string',
251
-							'context'     => [ 'view', 'edit' ],
252
-							'readonly'    => true,
253
-						],
254
-						'tax_lines'          => [
255
-							'description' => __( 'Lines of taxes applied to items and shipping.', 'woocommerce' ),
256
-							'type'        => 'array',
257
-							'context'     => [ 'view', 'edit' ],
258
-							'readonly'    => true,
259
-							'items'       => [
260
-								'type'       => 'object',
261
-								'properties' => [
262
-									'name'  => [
263
-										'description' => __( 'The name of the tax.', 'woocommerce' ),
264
-										'type'        => 'string',
265
-										'context'     => [ 'view', 'edit' ],
266
-										'readonly'    => true,
267
-									],
268
-									'price' => [
269
-										'description' => __( 'The amount of tax charged.', 'woocommerce' ),
270
-										'type'        => 'string',
271
-										'context'     => [ 'view', 'edit' ],
272
-										'readonly'    => true,
273
-									],
274
-									'rate'  => [
275
-										'description' => __( 'The rate at which tax is applied.', 'woocommerce' ),
276
-										'type'        => 'string',
277
-										'context'     => [ 'view', 'edit' ],
278
-										'readonly'    => true,
279
-									],
280
-								],
281
-							],
282
-						],
283
-					]
284
-				),
285
-			],
286
-			'errors'                  => [
287
-				'description' => __( 'List of cart item errors, for example, items in the cart which are out of stock.', 'woocommerce' ),
288
-				'type'        => 'array',
289
-				'context'     => [ 'view', 'edit' ],
290
-				'readonly'    => true,
291
-				'items'       => [
292
-					'type'       => 'object',
293
-					'properties' => $this->force_schema_readonly( $this->error_schema->get_properties() ),
294
-				],
295
-			],
296
-			'payment_requirements'    => [
297
-				'description' => __( 'List of required payment gateway features to process the order.', 'woocommerce' ),
298
-				'type'        => 'array',
299
-				'context'     => [ 'view', 'edit' ],
300
-				'readonly'    => true,
301
-			],
302
-			self::EXTENDING_KEY       => $this->get_extended_schema( self::IDENTIFIER ),
303
-		];
304
-	}
95
+    /**
96
+     * Cart schema properties.
97
+     *
98
+     * @return array
99
+     */
100
+    public function get_properties() {
101
+        return [
102
+            'coupons'                 => [
103
+                'description' => __( 'List of applied cart coupons.', 'woocommerce' ),
104
+                'type'        => 'array',
105
+                'context'     => [ 'view', 'edit' ],
106
+                'readonly'    => true,
107
+                'items'       => [
108
+                    'type'       => 'object',
109
+                    'properties' => $this->force_schema_readonly( $this->coupon_schema->get_properties() ),
110
+                ],
111
+            ],
112
+            'shipping_rates'          => [
113
+                'description' => __( 'List of available shipping rates for the cart.', 'woocommerce' ),
114
+                'type'        => 'array',
115
+                'context'     => [ 'view', 'edit' ],
116
+                'readonly'    => true,
117
+                'items'       => [
118
+                    'type'       => 'object',
119
+                    'properties' => $this->force_schema_readonly( $this->shipping_rate_schema->get_properties() ),
120
+                ],
121
+            ],
122
+            'shipping_address'        => [
123
+                'description' => __( 'Current set shipping address for the customer.', 'woocommerce' ),
124
+                'type'        => 'object',
125
+                'context'     => [ 'view', 'edit' ],
126
+                'readonly'    => true,
127
+                'properties'  => $this->force_schema_readonly( $this->shipping_address_schema->get_properties() ),
128
+            ],
129
+            'billing_address'         => [
130
+                'description' => __( 'Current set billing address for the customer.', 'woocommerce' ),
131
+                'type'        => 'object',
132
+                'context'     => [ 'view', 'edit' ],
133
+                'readonly'    => true,
134
+                'properties'  => $this->force_schema_readonly( $this->billing_address_schema->get_properties() ),
135
+            ],
136
+            'items'                   => [
137
+                'description' => __( 'List of cart items.', 'woocommerce' ),
138
+                'type'        => 'array',
139
+                'context'     => [ 'view', 'edit' ],
140
+                'readonly'    => true,
141
+                'items'       => [
142
+                    'type'       => 'object',
143
+                    'properties' => $this->force_schema_readonly( $this->item_schema->get_properties() ),
144
+                ],
145
+            ],
146
+            'items_count'             => [
147
+                'description' => __( 'Number of items in the cart.', 'woocommerce' ),
148
+                'type'        => 'integer',
149
+                'context'     => [ 'view', 'edit' ],
150
+                'readonly'    => true,
151
+            ],
152
+            'items_weight'            => [
153
+                'description' => __( 'Total weight (in grams) of all products in the cart.', 'woocommerce' ),
154
+                'type'        => 'number',
155
+                'context'     => [ 'view', 'edit' ],
156
+                'readonly'    => true,
157
+            ],
158
+            'needs_payment'           => [
159
+                'description' => __( 'True if the cart needs payment. False for carts with only free products and no shipping costs.', 'woocommerce' ),
160
+                'type'        => 'boolean',
161
+                'context'     => [ 'view', 'edit' ],
162
+                'readonly'    => true,
163
+            ],
164
+            'needs_shipping'          => [
165
+                'description' => __( 'True if the cart needs shipping. False for carts with only digital goods or stores with no shipping methods set-up.', 'woocommerce' ),
166
+                'type'        => 'boolean',
167
+                'context'     => [ 'view', 'edit' ],
168
+                'readonly'    => true,
169
+            ],
170
+            'has_calculated_shipping' => [
171
+                'description' => __( 'True if the cart meets the criteria for showing shipping costs, and rates have been calculated and included in the totals.', 'woocommerce' ),
172
+                'type'        => 'boolean',
173
+                'context'     => [ 'view', 'edit' ],
174
+                'readonly'    => true,
175
+            ],
176
+            'fees'                    => [
177
+                'description' => __( 'List of cart fees.', 'woocommerce' ),
178
+                'type'        => 'array',
179
+                'context'     => [ 'view', 'edit' ],
180
+                'readonly'    => true,
181
+                'items'       => [
182
+                    'type'       => 'object',
183
+                    'properties' => $this->force_schema_readonly( $this->fee_schema->get_properties() ),
184
+                ],
185
+            ],
186
+            'totals'                  => [
187
+                'description' => __( 'Cart total amounts provided using the smallest unit of the currency.', 'woocommerce' ),
188
+                'type'        => 'object',
189
+                'context'     => [ 'view', 'edit' ],
190
+                'readonly'    => true,
191
+                'properties'  => array_merge(
192
+                    $this->get_store_currency_properties(),
193
+                    [
194
+                        'total_items'        => [
195
+                            'description' => __( 'Total price of items in the cart.', 'woocommerce' ),
196
+                            'type'        => 'string',
197
+                            'context'     => [ 'view', 'edit' ],
198
+                            'readonly'    => true,
199
+                        ],
200
+                        'total_items_tax'    => [
201
+                            'description' => __( 'Total tax on items in the cart.', 'woocommerce' ),
202
+                            'type'        => 'string',
203
+                            'context'     => [ 'view', 'edit' ],
204
+                            'readonly'    => true,
205
+                        ],
206
+                        'total_fees'         => [
207
+                            'description' => __( 'Total price of any applied fees.', 'woocommerce' ),
208
+                            'type'        => 'string',
209
+                            'context'     => [ 'view', 'edit' ],
210
+                            'readonly'    => true,
211
+                        ],
212
+                        'total_fees_tax'     => [
213
+                            'description' => __( 'Total tax on fees.', 'woocommerce' ),
214
+                            'type'        => 'string',
215
+                            'context'     => [ 'view', 'edit' ],
216
+                            'readonly'    => true,
217
+                        ],
218
+                        'total_discount'     => [
219
+                            'description' => __( 'Total discount from applied coupons.', 'woocommerce' ),
220
+                            'type'        => 'string',
221
+                            'context'     => [ 'view', 'edit' ],
222
+                            'readonly'    => true,
223
+                        ],
224
+                        'total_discount_tax' => [
225
+                            'description' => __( 'Total tax removed due to discount from applied coupons.', 'woocommerce' ),
226
+                            'type'        => 'string',
227
+                            'context'     => [ 'view', 'edit' ],
228
+                            'readonly'    => true,
229
+                        ],
230
+                        'total_shipping'     => [
231
+                            'description' => __( 'Total price of shipping. If shipping has not been calculated, a null response will be sent.', 'woocommerce' ),
232
+                            'type'        => [ 'string', 'null' ],
233
+                            'context'     => [ 'view', 'edit' ],
234
+                            'readonly'    => true,
235
+                        ],
236
+                        'total_shipping_tax' => [
237
+                            'description' => __( 'Total tax on shipping. If shipping has not been calculated, a null response will be sent.', 'woocommerce' ),
238
+                            'type'        => [ 'string', 'null' ],
239
+                            'context'     => [ 'view', 'edit' ],
240
+                            'readonly'    => true,
241
+                        ],
242
+                        'total_price'        => [
243
+                            'description' => __( 'Total price the customer will pay.', 'woocommerce' ),
244
+                            'type'        => 'string',
245
+                            'context'     => [ 'view', 'edit' ],
246
+                            'readonly'    => true,
247
+                        ],
248
+                        'total_tax'          => [
249
+                            'description' => __( 'Total tax applied to items and shipping.', 'woocommerce' ),
250
+                            'type'        => 'string',
251
+                            'context'     => [ 'view', 'edit' ],
252
+                            'readonly'    => true,
253
+                        ],
254
+                        'tax_lines'          => [
255
+                            'description' => __( 'Lines of taxes applied to items and shipping.', 'woocommerce' ),
256
+                            'type'        => 'array',
257
+                            'context'     => [ 'view', 'edit' ],
258
+                            'readonly'    => true,
259
+                            'items'       => [
260
+                                'type'       => 'object',
261
+                                'properties' => [
262
+                                    'name'  => [
263
+                                        'description' => __( 'The name of the tax.', 'woocommerce' ),
264
+                                        'type'        => 'string',
265
+                                        'context'     => [ 'view', 'edit' ],
266
+                                        'readonly'    => true,
267
+                                    ],
268
+                                    'price' => [
269
+                                        'description' => __( 'The amount of tax charged.', 'woocommerce' ),
270
+                                        'type'        => 'string',
271
+                                        'context'     => [ 'view', 'edit' ],
272
+                                        'readonly'    => true,
273
+                                    ],
274
+                                    'rate'  => [
275
+                                        'description' => __( 'The rate at which tax is applied.', 'woocommerce' ),
276
+                                        'type'        => 'string',
277
+                                        'context'     => [ 'view', 'edit' ],
278
+                                        'readonly'    => true,
279
+                                    ],
280
+                                ],
281
+                            ],
282
+                        ],
283
+                    ]
284
+                ),
285
+            ],
286
+            'errors'                  => [
287
+                'description' => __( 'List of cart item errors, for example, items in the cart which are out of stock.', 'woocommerce' ),
288
+                'type'        => 'array',
289
+                'context'     => [ 'view', 'edit' ],
290
+                'readonly'    => true,
291
+                'items'       => [
292
+                    'type'       => 'object',
293
+                    'properties' => $this->force_schema_readonly( $this->error_schema->get_properties() ),
294
+                ],
295
+            ],
296
+            'payment_requirements'    => [
297
+                'description' => __( 'List of required payment gateway features to process the order.', 'woocommerce' ),
298
+                'type'        => 'array',
299
+                'context'     => [ 'view', 'edit' ],
300
+                'readonly'    => true,
301
+            ],
302
+            self::EXTENDING_KEY       => $this->get_extended_schema( self::IDENTIFIER ),
303
+        ];
304
+    }
305 305
 
306
-	/**
307
-	 * Convert a woo cart into an object suitable for the response.
308
-	 *
309
-	 * @param \WC_Cart $cart Cart class instance.
310
-	 * @return array
311
-	 */
312
-	public function get_item_response( $cart ) {
313
-		$controller = new CartController();
306
+    /**
307
+     * Convert a woo cart into an object suitable for the response.
308
+     *
309
+     * @param \WC_Cart $cart Cart class instance.
310
+     * @return array
311
+     */
312
+    public function get_item_response( $cart ) {
313
+        $controller = new CartController();
314 314
 
315
-		// Get cart errors first so if recalculations are performed, it's reflected in the response.
316
-		$cart_errors = $this->get_cart_errors( $cart );
315
+        // Get cart errors first so if recalculations are performed, it's reflected in the response.
316
+        $cart_errors = $this->get_cart_errors( $cart );
317 317
 
318
-		// The core cart class will not include shipping in the cart totals if `show_shipping()` returns false. This can
319
-		// happen if an address is required, or through the use of hooks. This tracks if shipping has actually been
320
-		// calculated so we can avoid returning costs and rates prematurely.
321
-		$has_calculated_shipping = $cart->show_shipping();
318
+        // The core cart class will not include shipping in the cart totals if `show_shipping()` returns false. This can
319
+        // happen if an address is required, or through the use of hooks. This tracks if shipping has actually been
320
+        // calculated so we can avoid returning costs and rates prematurely.
321
+        $has_calculated_shipping = $cart->show_shipping();
322 322
 
323
-		// Get shipping packages to return in the response from the cart.
324
-		$shipping_packages = $has_calculated_shipping ? $controller->get_shipping_packages() : [];
323
+        // Get shipping packages to return in the response from the cart.
324
+        $shipping_packages = $has_calculated_shipping ? $controller->get_shipping_packages() : [];
325 325
 
326
-		return [
327
-			'coupons'                 => $this->get_item_responses_from_schema( $this->coupon_schema, $cart->get_applied_coupons() ),
328
-			'shipping_rates'          => $this->get_item_responses_from_schema( $this->shipping_rate_schema, $shipping_packages ),
329
-			'shipping_address'        => $this->shipping_address_schema->get_item_response( wc()->customer ),
330
-			'billing_address'         => $this->billing_address_schema->get_item_response( wc()->customer ),
331
-			'items'                   => $this->get_item_responses_from_schema( $this->item_schema, $cart->get_cart() ),
332
-			'items_count'             => $cart->get_cart_contents_count(),
333
-			'items_weight'            => wc_get_weight( $cart->get_cart_contents_weight(), 'g' ),
334
-			'needs_payment'           => $cart->needs_payment(),
335
-			'needs_shipping'          => $cart->needs_shipping(),
336
-			'has_calculated_shipping' => $has_calculated_shipping,
337
-			'fees'                    => $this->get_item_responses_from_schema( $this->fee_schema, $cart->get_fees() ),
338
-			'totals'                  => (object) $this->prepare_currency_response(
339
-				[
340
-					'total_items'        => $this->prepare_money_response( $cart->get_subtotal(), wc_get_price_decimals() ),
341
-					'total_items_tax'    => $this->prepare_money_response( $cart->get_subtotal_tax(), wc_get_price_decimals() ),
342
-					'total_fees'         => $this->prepare_money_response( $cart->get_fee_total(), wc_get_price_decimals() ),
343
-					'total_fees_tax'     => $this->prepare_money_response( $cart->get_fee_tax(), wc_get_price_decimals() ),
344
-					'total_discount'     => $this->prepare_money_response( $cart->get_discount_total(), wc_get_price_decimals() ),
345
-					'total_discount_tax' => $this->prepare_money_response( $cart->get_discount_tax(), wc_get_price_decimals() ),
346
-					'total_shipping'     => $has_calculated_shipping ? $this->prepare_money_response( $cart->get_shipping_total(), wc_get_price_decimals() ) : null,
347
-					'total_shipping_tax' => $has_calculated_shipping ? $this->prepare_money_response( $cart->get_shipping_tax(), wc_get_price_decimals() ) : null,
326
+        return [
327
+            'coupons'                 => $this->get_item_responses_from_schema( $this->coupon_schema, $cart->get_applied_coupons() ),
328
+            'shipping_rates'          => $this->get_item_responses_from_schema( $this->shipping_rate_schema, $shipping_packages ),
329
+            'shipping_address'        => $this->shipping_address_schema->get_item_response( wc()->customer ),
330
+            'billing_address'         => $this->billing_address_schema->get_item_response( wc()->customer ),
331
+            'items'                   => $this->get_item_responses_from_schema( $this->item_schema, $cart->get_cart() ),
332
+            'items_count'             => $cart->get_cart_contents_count(),
333
+            'items_weight'            => wc_get_weight( $cart->get_cart_contents_weight(), 'g' ),
334
+            'needs_payment'           => $cart->needs_payment(),
335
+            'needs_shipping'          => $cart->needs_shipping(),
336
+            'has_calculated_shipping' => $has_calculated_shipping,
337
+            'fees'                    => $this->get_item_responses_from_schema( $this->fee_schema, $cart->get_fees() ),
338
+            'totals'                  => (object) $this->prepare_currency_response(
339
+                [
340
+                    'total_items'        => $this->prepare_money_response( $cart->get_subtotal(), wc_get_price_decimals() ),
341
+                    'total_items_tax'    => $this->prepare_money_response( $cart->get_subtotal_tax(), wc_get_price_decimals() ),
342
+                    'total_fees'         => $this->prepare_money_response( $cart->get_fee_total(), wc_get_price_decimals() ),
343
+                    'total_fees_tax'     => $this->prepare_money_response( $cart->get_fee_tax(), wc_get_price_decimals() ),
344
+                    'total_discount'     => $this->prepare_money_response( $cart->get_discount_total(), wc_get_price_decimals() ),
345
+                    'total_discount_tax' => $this->prepare_money_response( $cart->get_discount_tax(), wc_get_price_decimals() ),
346
+                    'total_shipping'     => $has_calculated_shipping ? $this->prepare_money_response( $cart->get_shipping_total(), wc_get_price_decimals() ) : null,
347
+                    'total_shipping_tax' => $has_calculated_shipping ? $this->prepare_money_response( $cart->get_shipping_tax(), wc_get_price_decimals() ) : null,
348 348
 
349
-					// Explicitly request context='edit'; default ('view') will render total as markup.
350
-					'total_price'        => $this->prepare_money_response( $cart->get_total( 'edit' ), wc_get_price_decimals() ),
351
-					'total_tax'          => $this->prepare_money_response( $cart->get_total_tax(), wc_get_price_decimals() ),
352
-					'tax_lines'          => $this->get_tax_lines( $cart ),
353
-				]
354
-			),
355
-			'errors'                  => $cart_errors,
356
-			'payment_requirements'    => $this->extend->get_payment_requirements(),
357
-			self::EXTENDING_KEY       => $this->get_extended_data( self::IDENTIFIER ),
358
-		];
359
-	}
349
+                    // Explicitly request context='edit'; default ('view') will render total as markup.
350
+                    'total_price'        => $this->prepare_money_response( $cart->get_total( 'edit' ), wc_get_price_decimals() ),
351
+                    'total_tax'          => $this->prepare_money_response( $cart->get_total_tax(), wc_get_price_decimals() ),
352
+                    'tax_lines'          => $this->get_tax_lines( $cart ),
353
+                ]
354
+            ),
355
+            'errors'                  => $cart_errors,
356
+            'payment_requirements'    => $this->extend->get_payment_requirements(),
357
+            self::EXTENDING_KEY       => $this->get_extended_data( self::IDENTIFIER ),
358
+        ];
359
+    }
360 360
 
361
-	/**
362
-	 * Get tax lines from the cart and format to match schema.
363
-	 *
364
-	 * @param \WC_Cart $cart Cart class instance.
365
-	 * @return array
366
-	 */
367
-	protected function get_tax_lines( $cart ) {
368
-		$cart_tax_totals = $cart->get_tax_totals();
369
-		$tax_lines       = [];
361
+    /**
362
+     * Get tax lines from the cart and format to match schema.
363
+     *
364
+     * @param \WC_Cart $cart Cart class instance.
365
+     * @return array
366
+     */
367
+    protected function get_tax_lines( $cart ) {
368
+        $cart_tax_totals = $cart->get_tax_totals();
369
+        $tax_lines       = [];
370 370
 
371
-		foreach ( $cart_tax_totals as $cart_tax_total ) {
372
-			$tax_lines[] = array(
373
-				'name'  => $cart_tax_total->label,
374
-				'price' => $this->prepare_money_response( $cart_tax_total->amount, wc_get_price_decimals() ),
375
-				'rate'  => WC_Tax::get_rate_percent( $cart_tax_total->tax_rate_id ),
376
-			);
377
-		}
371
+        foreach ( $cart_tax_totals as $cart_tax_total ) {
372
+            $tax_lines[] = array(
373
+                'name'  => $cart_tax_total->label,
374
+                'price' => $this->prepare_money_response( $cart_tax_total->amount, wc_get_price_decimals() ),
375
+                'rate'  => WC_Tax::get_rate_percent( $cart_tax_total->tax_rate_id ),
376
+            );
377
+        }
378 378
 
379
-		return $tax_lines;
380
-	}
379
+        return $tax_lines;
380
+    }
381 381
 
382
-	/**
383
-	 * Get cart validation errors.
384
-	 *
385
-	 * @param \WC_Cart $cart Cart class instance.
386
-	 * @return array
387
-	 */
388
-	protected function get_cart_errors( $cart ) {
389
-		$controller  = new CartController();
390
-		$errors      = $controller->get_cart_errors();
391
-		$cart_errors = [];
382
+    /**
383
+     * Get cart validation errors.
384
+     *
385
+     * @param \WC_Cart $cart Cart class instance.
386
+     * @return array
387
+     */
388
+    protected function get_cart_errors( $cart ) {
389
+        $controller  = new CartController();
390
+        $errors      = $controller->get_cart_errors();
391
+        $cart_errors = [];
392 392
 
393
-		foreach ( (array) $errors->errors as $code => $messages ) {
394
-			foreach ( (array) $messages as $message ) {
395
-				$cart_errors[] = new \WP_Error(
396
-					$code,
397
-					$message,
398
-					$errors->get_error_data( $code )
399
-				);
400
-			}
401
-		}
393
+        foreach ( (array) $errors->errors as $code => $messages ) {
394
+            foreach ( (array) $messages as $message ) {
395
+                $cart_errors[] = new \WP_Error(
396
+                    $code,
397
+                    $message,
398
+                    $errors->get_error_data( $code )
399
+                );
400
+            }
401
+        }
402 402
 
403
-		return array_values( array_map( [ $this->error_schema, 'get_item_response' ], $cart_errors ) );
404
-	}
403
+        return array_values( array_map( [ $this->error_schema, 'get_item_response' ], $cart_errors ) );
404
+    }
405 405
 }
Please login to merge, or discard this patch.
Spacing   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -81,15 +81,15 @@  discard block
 block discarded – undo
81 81
 	 * @param ExtendSchema     $extend Rest Extending instance.
82 82
 	 * @param SchemaController $controller Schema Controller instance.
83 83
 	 */
84
-	public function __construct( ExtendSchema $extend, SchemaController $controller ) {
85
-		parent::__construct( $extend, $controller );
86
-		$this->item_schema             = $this->controller->get( CartItemSchema::IDENTIFIER );
87
-		$this->coupon_schema           = $this->controller->get( CartCouponSchema::IDENTIFIER );
88
-		$this->fee_schema              = $this->controller->get( CartFeeSchema::IDENTIFIER );
89
-		$this->shipping_rate_schema    = $this->controller->get( CartShippingRateSchema::IDENTIFIER );
90
-		$this->shipping_address_schema = $this->controller->get( ShippingAddressSchema::IDENTIFIER );
91
-		$this->billing_address_schema  = $this->controller->get( BillingAddressSchema::IDENTIFIER );
92
-		$this->error_schema            = $this->controller->get( ErrorSchema::IDENTIFIER );
84
+	public function __construct(ExtendSchema $extend, SchemaController $controller) {
85
+		parent::__construct($extend, $controller);
86
+		$this->item_schema             = $this->controller->get(CartItemSchema::IDENTIFIER);
87
+		$this->coupon_schema           = $this->controller->get(CartCouponSchema::IDENTIFIER);
88
+		$this->fee_schema              = $this->controller->get(CartFeeSchema::IDENTIFIER);
89
+		$this->shipping_rate_schema    = $this->controller->get(CartShippingRateSchema::IDENTIFIER);
90
+		$this->shipping_address_schema = $this->controller->get(ShippingAddressSchema::IDENTIFIER);
91
+		$this->billing_address_schema  = $this->controller->get(BillingAddressSchema::IDENTIFIER);
92
+		$this->error_schema            = $this->controller->get(ErrorSchema::IDENTIFIER);
93 93
 	}
94 94
 
95 95
 	/**
@@ -100,181 +100,181 @@  discard block
 block discarded – undo
100 100
 	public function get_properties() {
101 101
 		return [
102 102
 			'coupons'                 => [
103
-				'description' => __( 'List of applied cart coupons.', 'woocommerce' ),
103
+				'description' => __('List of applied cart coupons.', 'woocommerce'),
104 104
 				'type'        => 'array',
105
-				'context'     => [ 'view', 'edit' ],
105
+				'context'     => ['view', 'edit'],
106 106
 				'readonly'    => true,
107 107
 				'items'       => [
108 108
 					'type'       => 'object',
109
-					'properties' => $this->force_schema_readonly( $this->coupon_schema->get_properties() ),
109
+					'properties' => $this->force_schema_readonly($this->coupon_schema->get_properties()),
110 110
 				],
111 111
 			],
112 112
 			'shipping_rates'          => [
113
-				'description' => __( 'List of available shipping rates for the cart.', 'woocommerce' ),
113
+				'description' => __('List of available shipping rates for the cart.', 'woocommerce'),
114 114
 				'type'        => 'array',
115
-				'context'     => [ 'view', 'edit' ],
115
+				'context'     => ['view', 'edit'],
116 116
 				'readonly'    => true,
117 117
 				'items'       => [
118 118
 					'type'       => 'object',
119
-					'properties' => $this->force_schema_readonly( $this->shipping_rate_schema->get_properties() ),
119
+					'properties' => $this->force_schema_readonly($this->shipping_rate_schema->get_properties()),
120 120
 				],
121 121
 			],
122 122
 			'shipping_address'        => [
123
-				'description' => __( 'Current set shipping address for the customer.', 'woocommerce' ),
123
+				'description' => __('Current set shipping address for the customer.', 'woocommerce'),
124 124
 				'type'        => 'object',
125
-				'context'     => [ 'view', 'edit' ],
125
+				'context'     => ['view', 'edit'],
126 126
 				'readonly'    => true,
127
-				'properties'  => $this->force_schema_readonly( $this->shipping_address_schema->get_properties() ),
127
+				'properties'  => $this->force_schema_readonly($this->shipping_address_schema->get_properties()),
128 128
 			],
129 129
 			'billing_address'         => [
130
-				'description' => __( 'Current set billing address for the customer.', 'woocommerce' ),
130
+				'description' => __('Current set billing address for the customer.', 'woocommerce'),
131 131
 				'type'        => 'object',
132
-				'context'     => [ 'view', 'edit' ],
132
+				'context'     => ['view', 'edit'],
133 133
 				'readonly'    => true,
134
-				'properties'  => $this->force_schema_readonly( $this->billing_address_schema->get_properties() ),
134
+				'properties'  => $this->force_schema_readonly($this->billing_address_schema->get_properties()),
135 135
 			],
136 136
 			'items'                   => [
137
-				'description' => __( 'List of cart items.', 'woocommerce' ),
137
+				'description' => __('List of cart items.', 'woocommerce'),
138 138
 				'type'        => 'array',
139
-				'context'     => [ 'view', 'edit' ],
139
+				'context'     => ['view', 'edit'],
140 140
 				'readonly'    => true,
141 141
 				'items'       => [
142 142
 					'type'       => 'object',
143
-					'properties' => $this->force_schema_readonly( $this->item_schema->get_properties() ),
143
+					'properties' => $this->force_schema_readonly($this->item_schema->get_properties()),
144 144
 				],
145 145
 			],
146 146
 			'items_count'             => [
147
-				'description' => __( 'Number of items in the cart.', 'woocommerce' ),
147
+				'description' => __('Number of items in the cart.', 'woocommerce'),
148 148
 				'type'        => 'integer',
149
-				'context'     => [ 'view', 'edit' ],
149
+				'context'     => ['view', 'edit'],
150 150
 				'readonly'    => true,
151 151
 			],
152 152
 			'items_weight'            => [
153
-				'description' => __( 'Total weight (in grams) of all products in the cart.', 'woocommerce' ),
153
+				'description' => __('Total weight (in grams) of all products in the cart.', 'woocommerce'),
154 154
 				'type'        => 'number',
155
-				'context'     => [ 'view', 'edit' ],
155
+				'context'     => ['view', 'edit'],
156 156
 				'readonly'    => true,
157 157
 			],
158 158
 			'needs_payment'           => [
159
-				'description' => __( 'True if the cart needs payment. False for carts with only free products and no shipping costs.', 'woocommerce' ),
159
+				'description' => __('True if the cart needs payment. False for carts with only free products and no shipping costs.', 'woocommerce'),
160 160
 				'type'        => 'boolean',
161
-				'context'     => [ 'view', 'edit' ],
161
+				'context'     => ['view', 'edit'],
162 162
 				'readonly'    => true,
163 163
 			],
164 164
 			'needs_shipping'          => [
165
-				'description' => __( 'True if the cart needs shipping. False for carts with only digital goods or stores with no shipping methods set-up.', 'woocommerce' ),
165
+				'description' => __('True if the cart needs shipping. False for carts with only digital goods or stores with no shipping methods set-up.', 'woocommerce'),
166 166
 				'type'        => 'boolean',
167
-				'context'     => [ 'view', 'edit' ],
167
+				'context'     => ['view', 'edit'],
168 168
 				'readonly'    => true,
169 169
 			],
170 170
 			'has_calculated_shipping' => [
171
-				'description' => __( 'True if the cart meets the criteria for showing shipping costs, and rates have been calculated and included in the totals.', 'woocommerce' ),
171
+				'description' => __('True if the cart meets the criteria for showing shipping costs, and rates have been calculated and included in the totals.', 'woocommerce'),
172 172
 				'type'        => 'boolean',
173
-				'context'     => [ 'view', 'edit' ],
173
+				'context'     => ['view', 'edit'],
174 174
 				'readonly'    => true,
175 175
 			],
176 176
 			'fees'                    => [
177
-				'description' => __( 'List of cart fees.', 'woocommerce' ),
177
+				'description' => __('List of cart fees.', 'woocommerce'),
178 178
 				'type'        => 'array',
179
-				'context'     => [ 'view', 'edit' ],
179
+				'context'     => ['view', 'edit'],
180 180
 				'readonly'    => true,
181 181
 				'items'       => [
182 182
 					'type'       => 'object',
183
-					'properties' => $this->force_schema_readonly( $this->fee_schema->get_properties() ),
183
+					'properties' => $this->force_schema_readonly($this->fee_schema->get_properties()),
184 184
 				],
185 185
 			],
186 186
 			'totals'                  => [
187
-				'description' => __( 'Cart total amounts provided using the smallest unit of the currency.', 'woocommerce' ),
187
+				'description' => __('Cart total amounts provided using the smallest unit of the currency.', 'woocommerce'),
188 188
 				'type'        => 'object',
189
-				'context'     => [ 'view', 'edit' ],
189
+				'context'     => ['view', 'edit'],
190 190
 				'readonly'    => true,
191 191
 				'properties'  => array_merge(
192 192
 					$this->get_store_currency_properties(),
193 193
 					[
194 194
 						'total_items'        => [
195
-							'description' => __( 'Total price of items in the cart.', 'woocommerce' ),
195
+							'description' => __('Total price of items in the cart.', 'woocommerce'),
196 196
 							'type'        => 'string',
197
-							'context'     => [ 'view', 'edit' ],
197
+							'context'     => ['view', 'edit'],
198 198
 							'readonly'    => true,
199 199
 						],
200 200
 						'total_items_tax'    => [
201
-							'description' => __( 'Total tax on items in the cart.', 'woocommerce' ),
201
+							'description' => __('Total tax on items in the cart.', 'woocommerce'),
202 202
 							'type'        => 'string',
203
-							'context'     => [ 'view', 'edit' ],
203
+							'context'     => ['view', 'edit'],
204 204
 							'readonly'    => true,
205 205
 						],
206 206
 						'total_fees'         => [
207
-							'description' => __( 'Total price of any applied fees.', 'woocommerce' ),
207
+							'description' => __('Total price of any applied fees.', 'woocommerce'),
208 208
 							'type'        => 'string',
209
-							'context'     => [ 'view', 'edit' ],
209
+							'context'     => ['view', 'edit'],
210 210
 							'readonly'    => true,
211 211
 						],
212 212
 						'total_fees_tax'     => [
213
-							'description' => __( 'Total tax on fees.', 'woocommerce' ),
213
+							'description' => __('Total tax on fees.', 'woocommerce'),
214 214
 							'type'        => 'string',
215
-							'context'     => [ 'view', 'edit' ],
215
+							'context'     => ['view', 'edit'],
216 216
 							'readonly'    => true,
217 217
 						],
218 218
 						'total_discount'     => [
219
-							'description' => __( 'Total discount from applied coupons.', 'woocommerce' ),
219
+							'description' => __('Total discount from applied coupons.', 'woocommerce'),
220 220
 							'type'        => 'string',
221
-							'context'     => [ 'view', 'edit' ],
221
+							'context'     => ['view', 'edit'],
222 222
 							'readonly'    => true,
223 223
 						],
224 224
 						'total_discount_tax' => [
225
-							'description' => __( 'Total tax removed due to discount from applied coupons.', 'woocommerce' ),
225
+							'description' => __('Total tax removed due to discount from applied coupons.', 'woocommerce'),
226 226
 							'type'        => 'string',
227
-							'context'     => [ 'view', 'edit' ],
227
+							'context'     => ['view', 'edit'],
228 228
 							'readonly'    => true,
229 229
 						],
230 230
 						'total_shipping'     => [
231
-							'description' => __( 'Total price of shipping. If shipping has not been calculated, a null response will be sent.', 'woocommerce' ),
232
-							'type'        => [ 'string', 'null' ],
233
-							'context'     => [ 'view', 'edit' ],
231
+							'description' => __('Total price of shipping. If shipping has not been calculated, a null response will be sent.', 'woocommerce'),
232
+							'type'        => ['string', 'null'],
233
+							'context'     => ['view', 'edit'],
234 234
 							'readonly'    => true,
235 235
 						],
236 236
 						'total_shipping_tax' => [
237
-							'description' => __( 'Total tax on shipping. If shipping has not been calculated, a null response will be sent.', 'woocommerce' ),
238
-							'type'        => [ 'string', 'null' ],
239
-							'context'     => [ 'view', 'edit' ],
237
+							'description' => __('Total tax on shipping. If shipping has not been calculated, a null response will be sent.', 'woocommerce'),
238
+							'type'        => ['string', 'null'],
239
+							'context'     => ['view', 'edit'],
240 240
 							'readonly'    => true,
241 241
 						],
242 242
 						'total_price'        => [
243
-							'description' => __( 'Total price the customer will pay.', 'woocommerce' ),
243
+							'description' => __('Total price the customer will pay.', 'woocommerce'),
244 244
 							'type'        => 'string',
245
-							'context'     => [ 'view', 'edit' ],
245
+							'context'     => ['view', 'edit'],
246 246
 							'readonly'    => true,
247 247
 						],
248 248
 						'total_tax'          => [
249
-							'description' => __( 'Total tax applied to items and shipping.', 'woocommerce' ),
249
+							'description' => __('Total tax applied to items and shipping.', 'woocommerce'),
250 250
 							'type'        => 'string',
251
-							'context'     => [ 'view', 'edit' ],
251
+							'context'     => ['view', 'edit'],
252 252
 							'readonly'    => true,
253 253
 						],
254 254
 						'tax_lines'          => [
255
-							'description' => __( 'Lines of taxes applied to items and shipping.', 'woocommerce' ),
255
+							'description' => __('Lines of taxes applied to items and shipping.', 'woocommerce'),
256 256
 							'type'        => 'array',
257
-							'context'     => [ 'view', 'edit' ],
257
+							'context'     => ['view', 'edit'],
258 258
 							'readonly'    => true,
259 259
 							'items'       => [
260 260
 								'type'       => 'object',
261 261
 								'properties' => [
262 262
 									'name'  => [
263
-										'description' => __( 'The name of the tax.', 'woocommerce' ),
263
+										'description' => __('The name of the tax.', 'woocommerce'),
264 264
 										'type'        => 'string',
265
-										'context'     => [ 'view', 'edit' ],
265
+										'context'     => ['view', 'edit'],
266 266
 										'readonly'    => true,
267 267
 									],
268 268
 									'price' => [
269
-										'description' => __( 'The amount of tax charged.', 'woocommerce' ),
269
+										'description' => __('The amount of tax charged.', 'woocommerce'),
270 270
 										'type'        => 'string',
271
-										'context'     => [ 'view', 'edit' ],
271
+										'context'     => ['view', 'edit'],
272 272
 										'readonly'    => true,
273 273
 									],
274 274
 									'rate'  => [
275
-										'description' => __( 'The rate at which tax is applied.', 'woocommerce' ),
275
+										'description' => __('The rate at which tax is applied.', 'woocommerce'),
276 276
 										'type'        => 'string',
277
-										'context'     => [ 'view', 'edit' ],
277
+										'context'     => ['view', 'edit'],
278 278
 										'readonly'    => true,
279 279
 									],
280 280
 								],
@@ -284,22 +284,22 @@  discard block
 block discarded – undo
284 284
 				),
285 285
 			],
286 286
 			'errors'                  => [
287
-				'description' => __( 'List of cart item errors, for example, items in the cart which are out of stock.', 'woocommerce' ),
287
+				'description' => __('List of cart item errors, for example, items in the cart which are out of stock.', 'woocommerce'),
288 288
 				'type'        => 'array',
289
-				'context'     => [ 'view', 'edit' ],
289
+				'context'     => ['view', 'edit'],
290 290
 				'readonly'    => true,
291 291
 				'items'       => [
292 292
 					'type'       => 'object',
293
-					'properties' => $this->force_schema_readonly( $this->error_schema->get_properties() ),
293
+					'properties' => $this->force_schema_readonly($this->error_schema->get_properties()),
294 294
 				],
295 295
 			],
296 296
 			'payment_requirements'    => [
297
-				'description' => __( 'List of required payment gateway features to process the order.', 'woocommerce' ),
297
+				'description' => __('List of required payment gateway features to process the order.', 'woocommerce'),
298 298
 				'type'        => 'array',
299
-				'context'     => [ 'view', 'edit' ],
299
+				'context'     => ['view', 'edit'],
300 300
 				'readonly'    => true,
301 301
 			],
302
-			self::EXTENDING_KEY       => $this->get_extended_schema( self::IDENTIFIER ),
302
+			self::EXTENDING_KEY       => $this->get_extended_schema(self::IDENTIFIER),
303 303
 		];
304 304
 	}
305 305
 
@@ -309,11 +309,11 @@  discard block
 block discarded – undo
309 309
 	 * @param \WC_Cart $cart Cart class instance.
310 310
 	 * @return array
311 311
 	 */
312
-	public function get_item_response( $cart ) {
312
+	public function get_item_response($cart) {
313 313
 		$controller = new CartController();
314 314
 
315 315
 		// Get cart errors first so if recalculations are performed, it's reflected in the response.
316
-		$cart_errors = $this->get_cart_errors( $cart );
316
+		$cart_errors = $this->get_cart_errors($cart);
317 317
 
318 318
 		// The core cart class will not include shipping in the cart totals if `show_shipping()` returns false. This can
319 319
 		// happen if an address is required, or through the use of hooks. This tracks if shipping has actually been
@@ -324,37 +324,37 @@  discard block
 block discarded – undo
324 324
 		$shipping_packages = $has_calculated_shipping ? $controller->get_shipping_packages() : [];
325 325
 
326 326
 		return [
327
-			'coupons'                 => $this->get_item_responses_from_schema( $this->coupon_schema, $cart->get_applied_coupons() ),
328
-			'shipping_rates'          => $this->get_item_responses_from_schema( $this->shipping_rate_schema, $shipping_packages ),
329
-			'shipping_address'        => $this->shipping_address_schema->get_item_response( wc()->customer ),
330
-			'billing_address'         => $this->billing_address_schema->get_item_response( wc()->customer ),
331
-			'items'                   => $this->get_item_responses_from_schema( $this->item_schema, $cart->get_cart() ),
327
+			'coupons'                 => $this->get_item_responses_from_schema($this->coupon_schema, $cart->get_applied_coupons()),
328
+			'shipping_rates'          => $this->get_item_responses_from_schema($this->shipping_rate_schema, $shipping_packages),
329
+			'shipping_address'        => $this->shipping_address_schema->get_item_response(wc()->customer),
330
+			'billing_address'         => $this->billing_address_schema->get_item_response(wc()->customer),
331
+			'items'                   => $this->get_item_responses_from_schema($this->item_schema, $cart->get_cart()),
332 332
 			'items_count'             => $cart->get_cart_contents_count(),
333
-			'items_weight'            => wc_get_weight( $cart->get_cart_contents_weight(), 'g' ),
333
+			'items_weight'            => wc_get_weight($cart->get_cart_contents_weight(), 'g'),
334 334
 			'needs_payment'           => $cart->needs_payment(),
335 335
 			'needs_shipping'          => $cart->needs_shipping(),
336 336
 			'has_calculated_shipping' => $has_calculated_shipping,
337
-			'fees'                    => $this->get_item_responses_from_schema( $this->fee_schema, $cart->get_fees() ),
337
+			'fees'                    => $this->get_item_responses_from_schema($this->fee_schema, $cart->get_fees()),
338 338
 			'totals'                  => (object) $this->prepare_currency_response(
339 339
 				[
340
-					'total_items'        => $this->prepare_money_response( $cart->get_subtotal(), wc_get_price_decimals() ),
341
-					'total_items_tax'    => $this->prepare_money_response( $cart->get_subtotal_tax(), wc_get_price_decimals() ),
342
-					'total_fees'         => $this->prepare_money_response( $cart->get_fee_total(), wc_get_price_decimals() ),
343
-					'total_fees_tax'     => $this->prepare_money_response( $cart->get_fee_tax(), wc_get_price_decimals() ),
344
-					'total_discount'     => $this->prepare_money_response( $cart->get_discount_total(), wc_get_price_decimals() ),
345
-					'total_discount_tax' => $this->prepare_money_response( $cart->get_discount_tax(), wc_get_price_decimals() ),
346
-					'total_shipping'     => $has_calculated_shipping ? $this->prepare_money_response( $cart->get_shipping_total(), wc_get_price_decimals() ) : null,
347
-					'total_shipping_tax' => $has_calculated_shipping ? $this->prepare_money_response( $cart->get_shipping_tax(), wc_get_price_decimals() ) : null,
340
+					'total_items'        => $this->prepare_money_response($cart->get_subtotal(), wc_get_price_decimals()),
341
+					'total_items_tax'    => $this->prepare_money_response($cart->get_subtotal_tax(), wc_get_price_decimals()),
342
+					'total_fees'         => $this->prepare_money_response($cart->get_fee_total(), wc_get_price_decimals()),
343
+					'total_fees_tax'     => $this->prepare_money_response($cart->get_fee_tax(), wc_get_price_decimals()),
344
+					'total_discount'     => $this->prepare_money_response($cart->get_discount_total(), wc_get_price_decimals()),
345
+					'total_discount_tax' => $this->prepare_money_response($cart->get_discount_tax(), wc_get_price_decimals()),
346
+					'total_shipping'     => $has_calculated_shipping ? $this->prepare_money_response($cart->get_shipping_total(), wc_get_price_decimals()) : null,
347
+					'total_shipping_tax' => $has_calculated_shipping ? $this->prepare_money_response($cart->get_shipping_tax(), wc_get_price_decimals()) : null,
348 348
 
349 349
 					// Explicitly request context='edit'; default ('view') will render total as markup.
350
-					'total_price'        => $this->prepare_money_response( $cart->get_total( 'edit' ), wc_get_price_decimals() ),
351
-					'total_tax'          => $this->prepare_money_response( $cart->get_total_tax(), wc_get_price_decimals() ),
352
-					'tax_lines'          => $this->get_tax_lines( $cart ),
350
+					'total_price'        => $this->prepare_money_response($cart->get_total('edit'), wc_get_price_decimals()),
351
+					'total_tax'          => $this->prepare_money_response($cart->get_total_tax(), wc_get_price_decimals()),
352
+					'tax_lines'          => $this->get_tax_lines($cart),
353 353
 				]
354 354
 			),
355 355
 			'errors'                  => $cart_errors,
356 356
 			'payment_requirements'    => $this->extend->get_payment_requirements(),
357
-			self::EXTENDING_KEY       => $this->get_extended_data( self::IDENTIFIER ),
357
+			self::EXTENDING_KEY       => $this->get_extended_data(self::IDENTIFIER),
358 358
 		];
359 359
 	}
360 360
 
@@ -364,15 +364,15 @@  discard block
 block discarded – undo
364 364
 	 * @param \WC_Cart $cart Cart class instance.
365 365
 	 * @return array
366 366
 	 */
367
-	protected function get_tax_lines( $cart ) {
367
+	protected function get_tax_lines($cart) {
368 368
 		$cart_tax_totals = $cart->get_tax_totals();
369 369
 		$tax_lines       = [];
370 370
 
371
-		foreach ( $cart_tax_totals as $cart_tax_total ) {
371
+		foreach ($cart_tax_totals as $cart_tax_total) {
372 372
 			$tax_lines[] = array(
373 373
 				'name'  => $cart_tax_total->label,
374
-				'price' => $this->prepare_money_response( $cart_tax_total->amount, wc_get_price_decimals() ),
375
-				'rate'  => WC_Tax::get_rate_percent( $cart_tax_total->tax_rate_id ),
374
+				'price' => $this->prepare_money_response($cart_tax_total->amount, wc_get_price_decimals()),
375
+				'rate'  => WC_Tax::get_rate_percent($cart_tax_total->tax_rate_id),
376 376
 			);
377 377
 		}
378 378
 
@@ -385,21 +385,21 @@  discard block
 block discarded – undo
385 385
 	 * @param \WC_Cart $cart Cart class instance.
386 386
 	 * @return array
387 387
 	 */
388
-	protected function get_cart_errors( $cart ) {
388
+	protected function get_cart_errors($cart) {
389 389
 		$controller  = new CartController();
390 390
 		$errors      = $controller->get_cart_errors();
391 391
 		$cart_errors = [];
392 392
 
393
-		foreach ( (array) $errors->errors as $code => $messages ) {
394
-			foreach ( (array) $messages as $message ) {
393
+		foreach ((array) $errors->errors as $code => $messages) {
394
+			foreach ((array) $messages as $message) {
395 395
 				$cart_errors[] = new \WP_Error(
396 396
 					$code,
397 397
 					$message,
398
-					$errors->get_error_data( $code )
398
+					$errors->get_error_data($code)
399 399
 				);
400 400
 			}
401 401
 		}
402 402
 
403
-		return array_values( array_map( [ $this->error_schema, 'get_item_response' ], $cart_errors ) );
403
+		return array_values(array_map([$this->error_schema, 'get_item_response'], $cart_errors));
404 404
 	}
405 405
 }
Please login to merge, or discard this patch.