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rc.2 3.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / src / StoreApi / Schemas / V1 / CartShippingRateSchema.php
woocommerce / src / StoreApi / Schemas / V1 Last commit date
AI 1 year ago Agentic 7 months ago AbstractAddressSchema.php 1 year ago AbstractSchema.php 1 month ago BatchSchema.php 2 years ago BillingAddressSchema.php 2 years ago CartCouponSchema.php 1 year ago CartExtensionsSchema.php 1 year ago CartFeeSchema.php 2 years ago CartItemSchema.php 1 month ago CartSchema.php 2 months ago CartShippingRateSchema.php 1 month ago CheckoutOrderSchema.php 2 years ago CheckoutSchema.php 1 month ago ErrorSchema.php 2 years ago ImageAttachmentSchema.php 3 months ago ItemSchema.php 11 months ago OrderCouponSchema.php 2 years ago OrderFeeSchema.php 2 years ago OrderItemSchema.php 1 month ago OrderSchema.php 2 months ago PatternsSchema.php 1 year ago ProductAttributeSchema.php 2 years ago ProductAttributeTermSchema.php 1 month ago ProductBrandSchema.php 1 year ago ProductCategorySchema.php 2 years ago ProductCollectionDataSchema.php 11 months ago ProductReviewSchema.php 2 years ago ProductSchema.php 1 month ago ShippingAddressSchema.php 2 years ago ShopperListItemSchema.php 1 month ago ShopperListSchema.php 1 month ago TermSchema.php 2 years ago
CartShippingRateSchema.php
355 lines
1 <?php
2 namespace Automattic\WooCommerce\StoreApi\Schemas\V1;
3
4 use WC_Shipping_Rate as ShippingRate;
5
6 /**
7 * CartShippingRateSchema class.
8 */
9 class CartShippingRateSchema extends AbstractSchema {
10 /**
11 * The schema item name.
12 *
13 * @var string
14 */
15 protected $title = 'cart-shipping-rate';
16
17 /**
18 * The schema item identifier.
19 *
20 * @var string
21 */
22 const IDENTIFIER = 'cart-shipping-rate';
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 }
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 }
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 }
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 compatibility.
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
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 $values ) {
264 $items[] = [
265 'key' => $values['key'],
266 'name' => $values['data']->get_name(),
267 'quantity' => $values['quantity'],
268 ];
269 }
270 return $items;
271 }
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'] ] : '';
283
284 if ( empty( $selected_rate ) && ! empty( $package['rates'] ) ) {
285 $selected_rate = wc_get_chosen_shipping_method_for_package( $package['package_id'], $package );
286 }
287
288 $response = [];
289
290 foreach ( $package['rates'] as $rate ) {
291 $response[] = $this->get_rate_response( $rate, $selected_rate );
292 }
293
294 return $response;
295 }
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( (array) $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
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
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
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 }
355