Passed
Push — main ( aaef5c...e4c121 )
by TARIQ
71:39
created
packages/woocommerce-blocks/src/StoreApi/Schemas/V1/CartFeeSchema.php 2 patches
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -5,81 +5,81 @@
 block discarded – undo
5 5
  * CartFeeSchema class.
6 6
  */
7 7
 class CartFeeSchema extends AbstractSchema {
8
-	/**
9
-	 * The schema item name.
10
-	 *
11
-	 * @var string
12
-	 */
13
-	protected $title = 'cart_fee';
8
+    /**
9
+     * The schema item name.
10
+     *
11
+     * @var string
12
+     */
13
+    protected $title = 'cart_fee';
14 14
 
15
-	/**
16
-	 * The schema item identifier.
17
-	 *
18
-	 * @var string
19
-	 */
20
-	const IDENTIFIER = 'cart-fee';
15
+    /**
16
+     * The schema item identifier.
17
+     *
18
+     * @var string
19
+     */
20
+    const IDENTIFIER = 'cart-fee';
21 21
 
22
-	/**
23
-	 * Cart schema properties.
24
-	 *
25
-	 * @return array
26
-	 */
27
-	public function get_properties() {
28
-		return [
29
-			'id'     => [
30
-				'description' => __( 'Unique identifier for the fee within the cart.', 'woocommerce' ),
31
-				'type'        => 'string',
32
-				'context'     => [ 'view', 'edit' ],
33
-				'readonly'    => true,
34
-			],
35
-			'name'   => [
36
-				'description' => __( 'Fee name.', 'woocommerce' ),
37
-				'type'        => 'string',
38
-				'context'     => [ 'view', 'edit' ],
39
-				'readonly'    => true,
40
-			],
41
-			'totals' => [
42
-				'description' => __( 'Fee total amounts provided using the smallest unit of the currency.', 'woocommerce' ),
43
-				'type'        => 'object',
44
-				'context'     => [ 'view', 'edit' ],
45
-				'readonly'    => true,
46
-				'properties'  => array_merge(
47
-					$this->get_store_currency_properties(),
48
-					[
49
-						'total'     => [
50
-							'description' => __( 'Total amount for this fee.', 'woocommerce' ),
51
-							'type'        => 'string',
52
-							'context'     => [ 'view', 'edit' ],
53
-							'readonly'    => true,
54
-						],
55
-						'total_tax' => [
56
-							'description' => __( 'Total tax amount for this fee.', 'woocommerce' ),
57
-							'type'        => 'string',
58
-							'context'     => [ 'view', 'edit' ],
59
-							'readonly'    => true,
60
-						],
61
-					]
62
-				),
63
-			],
64
-		];
65
-	}
22
+    /**
23
+     * Cart schema properties.
24
+     *
25
+     * @return array
26
+     */
27
+    public function get_properties() {
28
+        return [
29
+            'id'     => [
30
+                'description' => __( 'Unique identifier for the fee within the cart.', 'woocommerce' ),
31
+                'type'        => 'string',
32
+                'context'     => [ 'view', 'edit' ],
33
+                'readonly'    => true,
34
+            ],
35
+            'name'   => [
36
+                'description' => __( 'Fee name.', 'woocommerce' ),
37
+                'type'        => 'string',
38
+                'context'     => [ 'view', 'edit' ],
39
+                'readonly'    => true,
40
+            ],
41
+            'totals' => [
42
+                'description' => __( 'Fee total amounts provided using the smallest unit of the currency.', 'woocommerce' ),
43
+                'type'        => 'object',
44
+                'context'     => [ 'view', 'edit' ],
45
+                'readonly'    => true,
46
+                'properties'  => array_merge(
47
+                    $this->get_store_currency_properties(),
48
+                    [
49
+                        'total'     => [
50
+                            'description' => __( 'Total amount for this fee.', 'woocommerce' ),
51
+                            'type'        => 'string',
52
+                            'context'     => [ 'view', 'edit' ],
53
+                            'readonly'    => true,
54
+                        ],
55
+                        'total_tax' => [
56
+                            'description' => __( 'Total tax amount for this fee.', 'woocommerce' ),
57
+                            'type'        => 'string',
58
+                            'context'     => [ 'view', 'edit' ],
59
+                            'readonly'    => true,
60
+                        ],
61
+                    ]
62
+                ),
63
+            ],
64
+        ];
65
+    }
66 66
 
67
-	/**
68
-	 * Convert a WooCommerce cart fee to an object suitable for the response.
69
-	 *
70
-	 * @param array $fee Cart fee data.
71
-	 * @return array
72
-	 */
73
-	public function get_item_response( $fee ) {
74
-		return [
75
-			'key'    => $fee->id,
76
-			'name'   => $this->prepare_html_response( $fee->name ),
77
-			'totals' => (object) $this->prepare_currency_response(
78
-				[
79
-					'total'     => $this->prepare_money_response( $fee->total, wc_get_price_decimals() ),
80
-					'total_tax' => $this->prepare_money_response( $fee->tax, wc_get_price_decimals(), PHP_ROUND_HALF_DOWN ),
81
-				]
82
-			),
83
-		];
84
-	}
67
+    /**
68
+     * Convert a WooCommerce cart fee to an object suitable for the response.
69
+     *
70
+     * @param array $fee Cart fee data.
71
+     * @return array
72
+     */
73
+    public function get_item_response( $fee ) {
74
+        return [
75
+            'key'    => $fee->id,
76
+            'name'   => $this->prepare_html_response( $fee->name ),
77
+            'totals' => (object) $this->prepare_currency_response(
78
+                [
79
+                    'total'     => $this->prepare_money_response( $fee->total, wc_get_price_decimals() ),
80
+                    'total_tax' => $this->prepare_money_response( $fee->tax, wc_get_price_decimals(), PHP_ROUND_HALF_DOWN ),
81
+                ]
82
+            ),
83
+        ];
84
+    }
85 85
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -27,35 +27,35 @@  discard block
 block discarded – undo
27 27
 	public function get_properties() {
28 28
 		return [
29 29
 			'id'     => [
30
-				'description' => __( 'Unique identifier for the fee within the cart.', 'woocommerce' ),
30
+				'description' => __('Unique identifier for the fee within the cart.', 'woocommerce'),
31 31
 				'type'        => 'string',
32
-				'context'     => [ 'view', 'edit' ],
32
+				'context'     => ['view', 'edit'],
33 33
 				'readonly'    => true,
34 34
 			],
35 35
 			'name'   => [
36
-				'description' => __( 'Fee name.', 'woocommerce' ),
36
+				'description' => __('Fee name.', 'woocommerce'),
37 37
 				'type'        => 'string',
38
-				'context'     => [ 'view', 'edit' ],
38
+				'context'     => ['view', 'edit'],
39 39
 				'readonly'    => true,
40 40
 			],
41 41
 			'totals' => [
42
-				'description' => __( 'Fee total amounts provided using the smallest unit of the currency.', 'woocommerce' ),
42
+				'description' => __('Fee total amounts provided using the smallest unit of the currency.', 'woocommerce'),
43 43
 				'type'        => 'object',
44
-				'context'     => [ 'view', 'edit' ],
44
+				'context'     => ['view', 'edit'],
45 45
 				'readonly'    => true,
46 46
 				'properties'  => array_merge(
47 47
 					$this->get_store_currency_properties(),
48 48
 					[
49 49
 						'total'     => [
50
-							'description' => __( 'Total amount for this fee.', 'woocommerce' ),
50
+							'description' => __('Total amount for this fee.', 'woocommerce'),
51 51
 							'type'        => 'string',
52
-							'context'     => [ 'view', 'edit' ],
52
+							'context'     => ['view', 'edit'],
53 53
 							'readonly'    => true,
54 54
 						],
55 55
 						'total_tax' => [
56
-							'description' => __( 'Total tax amount for this fee.', 'woocommerce' ),
56
+							'description' => __('Total tax amount for this fee.', 'woocommerce'),
57 57
 							'type'        => 'string',
58
-							'context'     => [ 'view', 'edit' ],
58
+							'context'     => ['view', 'edit'],
59 59
 							'readonly'    => true,
60 60
 						],
61 61
 					]
@@ -70,14 +70,14 @@  discard block
 block discarded – undo
70 70
 	 * @param array $fee Cart fee data.
71 71
 	 * @return array
72 72
 	 */
73
-	public function get_item_response( $fee ) {
73
+	public function get_item_response($fee) {
74 74
 		return [
75 75
 			'key'    => $fee->id,
76
-			'name'   => $this->prepare_html_response( $fee->name ),
76
+			'name'   => $this->prepare_html_response($fee->name),
77 77
 			'totals' => (object) $this->prepare_currency_response(
78 78
 				[
79
-					'total'     => $this->prepare_money_response( $fee->total, wc_get_price_decimals() ),
80
-					'total_tax' => $this->prepare_money_response( $fee->tax, wc_get_price_decimals(), PHP_ROUND_HALF_DOWN ),
79
+					'total'     => $this->prepare_money_response($fee->total, wc_get_price_decimals()),
80
+					'total_tax' => $this->prepare_money_response($fee->tax, wc_get_price_decimals(), PHP_ROUND_HALF_DOWN),
81 81
 				]
82 82
 			),
83 83
 		];
Please login to merge, or discard this patch.
woocommerce-blocks/src/StoreApi/Schemas/V1/ShippingAddressSchema.php 2 patches
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -9,62 +9,62 @@
 block discarded – undo
9 9
  * Provides a generic shipping address schema for composition in other schemas.
10 10
  */
11 11
 class ShippingAddressSchema extends AbstractAddressSchema {
12
-	/**
13
-	 * The schema item name.
14
-	 *
15
-	 * @var string
16
-	 */
17
-	protected $title = 'shipping_address';
12
+    /**
13
+     * The schema item name.
14
+     *
15
+     * @var string
16
+     */
17
+    protected $title = 'shipping_address';
18 18
 
19
-	/**
20
-	 * The schema item identifier.
21
-	 *
22
-	 * @var string
23
-	 */
24
-	const IDENTIFIER = 'shipping-address';
19
+    /**
20
+     * The schema item identifier.
21
+     *
22
+     * @var string
23
+     */
24
+    const IDENTIFIER = 'shipping-address';
25 25
 
26
-	/**
27
-	 * Convert a term object into an object suitable for the response.
28
-	 *
29
-	 * @param \WC_Order|\WC_Customer $address An object with shipping address.
30
-	 *
31
-	 * @throws RouteException When the invalid object types are provided.
32
-	 * @return stdClass
33
-	 */
34
-	public function get_item_response( $address ) {
35
-		if ( ( $address instanceof \WC_Customer || $address instanceof \WC_Order ) ) {
36
-			$shipping_country = $address->get_shipping_country();
37
-			$shipping_state   = $address->get_shipping_state();
26
+    /**
27
+     * Convert a term object into an object suitable for the response.
28
+     *
29
+     * @param \WC_Order|\WC_Customer $address An object with shipping address.
30
+     *
31
+     * @throws RouteException When the invalid object types are provided.
32
+     * @return stdClass
33
+     */
34
+    public function get_item_response( $address ) {
35
+        if ( ( $address instanceof \WC_Customer || $address instanceof \WC_Order ) ) {
36
+            $shipping_country = $address->get_shipping_country();
37
+            $shipping_state   = $address->get_shipping_state();
38 38
 
39
-			if ( ! $this->validate_state( $shipping_state, $shipping_country ) ) {
40
-				$shipping_state = '';
41
-			}
39
+            if ( ! $this->validate_state( $shipping_state, $shipping_country ) ) {
40
+                $shipping_state = '';
41
+            }
42 42
 
43
-			return (object) $this->prepare_html_response(
44
-				[
45
-					'first_name' => $address->get_shipping_first_name(),
46
-					'last_name'  => $address->get_shipping_last_name(),
47
-					'company'    => $address->get_shipping_company(),
48
-					'address_1'  => $address->get_shipping_address_1(),
49
-					'address_2'  => $address->get_shipping_address_2(),
50
-					'city'       => $address->get_shipping_city(),
51
-					'state'      => $shipping_state,
52
-					'postcode'   => $address->get_shipping_postcode(),
53
-					'country'    => $shipping_country,
54
-					'phone'      => $address->get_shipping_phone(),
55
-				]
56
-			);
57
-		}
58
-		throw new RouteException(
59
-			'invalid_object_type',
60
-			sprintf(
61
-				/* translators: Placeholders are class and method names */
62
-				__( '%1$s requires an instance of %2$s or %3$s for the address', 'woocommerce' ),
63
-				'ShippingAddressSchema::get_item_response',
64
-				'WC_Customer',
65
-				'WC_Order'
66
-			),
67
-			500
68
-		);
69
-	}
43
+            return (object) $this->prepare_html_response(
44
+                [
45
+                    'first_name' => $address->get_shipping_first_name(),
46
+                    'last_name'  => $address->get_shipping_last_name(),
47
+                    'company'    => $address->get_shipping_company(),
48
+                    'address_1'  => $address->get_shipping_address_1(),
49
+                    'address_2'  => $address->get_shipping_address_2(),
50
+                    'city'       => $address->get_shipping_city(),
51
+                    'state'      => $shipping_state,
52
+                    'postcode'   => $address->get_shipping_postcode(),
53
+                    'country'    => $shipping_country,
54
+                    'phone'      => $address->get_shipping_phone(),
55
+                ]
56
+            );
57
+        }
58
+        throw new RouteException(
59
+            'invalid_object_type',
60
+            sprintf(
61
+                /* translators: Placeholders are class and method names */
62
+                __( '%1$s requires an instance of %2$s or %3$s for the address', 'woocommerce' ),
63
+                'ShippingAddressSchema::get_item_response',
64
+                'WC_Customer',
65
+                'WC_Order'
66
+            ),
67
+            500
68
+        );
69
+    }
70 70
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -31,12 +31,12 @@  discard block
 block discarded – undo
31 31
 	 * @throws RouteException When the invalid object types are provided.
32 32
 	 * @return stdClass
33 33
 	 */
34
-	public function get_item_response( $address ) {
35
-		if ( ( $address instanceof \WC_Customer || $address instanceof \WC_Order ) ) {
34
+	public function get_item_response($address) {
35
+		if (($address instanceof \WC_Customer || $address instanceof \WC_Order)) {
36 36
 			$shipping_country = $address->get_shipping_country();
37 37
 			$shipping_state   = $address->get_shipping_state();
38 38
 
39
-			if ( ! $this->validate_state( $shipping_state, $shipping_country ) ) {
39
+			if (!$this->validate_state($shipping_state, $shipping_country)) {
40 40
 				$shipping_state = '';
41 41
 			}
42 42
 
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 			'invalid_object_type',
60 60
 			sprintf(
61 61
 				/* translators: Placeholders are class and method names */
62
-				__( '%1$s requires an instance of %2$s or %3$s for the address', 'woocommerce' ),
62
+				__('%1$s requires an instance of %2$s or %3$s for the address', 'woocommerce'),
63 63
 				'ShippingAddressSchema::get_item_response',
64 64
 				'WC_Customer',
65 65
 				'WC_Order'
Please login to merge, or discard this patch.
woocommerce-blocks/src/StoreApi/Schemas/V1/ImageAttachmentSchema.php 2 patches
Indentation   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -5,95 +5,95 @@
 block discarded – undo
5 5
  * ImageAttachmentSchema class.
6 6
  */
7 7
 class ImageAttachmentSchema extends AbstractSchema {
8
-	/**
9
-	 * The schema item name.
10
-	 *
11
-	 * @var string
12
-	 */
13
-	protected $title = 'image';
8
+    /**
9
+     * The schema item name.
10
+     *
11
+     * @var string
12
+     */
13
+    protected $title = 'image';
14 14
 
15
-	/**
16
-	 * The schema item identifier.
17
-	 *
18
-	 * @var string
19
-	 */
20
-	const IDENTIFIER = 'image';
15
+    /**
16
+     * The schema item identifier.
17
+     *
18
+     * @var string
19
+     */
20
+    const IDENTIFIER = 'image';
21 21
 
22
-	/**
23
-	 * Product schema properties.
24
-	 *
25
-	 * @return array
26
-	 */
27
-	public function get_properties() {
28
-		return [
29
-			'id'        => [
30
-				'description' => __( 'Image ID.', 'woocommerce' ),
31
-				'type'        => 'integer',
32
-				'context'     => [ 'view', 'edit' ],
33
-			],
34
-			'src'       => [
35
-				'description' => __( 'Full size image URL.', 'woocommerce' ),
36
-				'type'        => 'string',
37
-				'format'      => 'uri',
38
-				'context'     => [ 'view', 'edit' ],
39
-			],
40
-			'thumbnail' => [
41
-				'description' => __( 'Thumbnail URL.', 'woocommerce' ),
42
-				'type'        => 'string',
43
-				'format'      => 'uri',
44
-				'context'     => [ 'view', 'edit' ],
45
-			],
46
-			'srcset'    => [
47
-				'description' => __( 'Thumbnail srcset for responsive images.', 'woocommerce' ),
48
-				'type'        => 'string',
49
-				'context'     => [ 'view', 'edit' ],
50
-			],
51
-			'sizes'     => [
52
-				'description' => __( 'Thumbnail sizes for responsive images.', 'woocommerce' ),
53
-				'type'        => 'string',
54
-				'context'     => [ 'view', 'edit' ],
55
-			],
56
-			'name'      => [
57
-				'description' => __( 'Image name.', 'woocommerce' ),
58
-				'type'        => 'string',
59
-				'context'     => [ 'view', 'edit' ],
60
-			],
61
-			'alt'       => [
62
-				'description' => __( 'Image alternative text.', 'woocommerce' ),
63
-				'type'        => 'string',
64
-				'context'     => [ 'view', 'edit' ],
65
-			],
66
-		];
67
-	}
22
+    /**
23
+     * Product schema properties.
24
+     *
25
+     * @return array
26
+     */
27
+    public function get_properties() {
28
+        return [
29
+            'id'        => [
30
+                'description' => __( 'Image ID.', 'woocommerce' ),
31
+                'type'        => 'integer',
32
+                'context'     => [ 'view', 'edit' ],
33
+            ],
34
+            'src'       => [
35
+                'description' => __( 'Full size image URL.', 'woocommerce' ),
36
+                'type'        => 'string',
37
+                'format'      => 'uri',
38
+                'context'     => [ 'view', 'edit' ],
39
+            ],
40
+            'thumbnail' => [
41
+                'description' => __( 'Thumbnail URL.', 'woocommerce' ),
42
+                'type'        => 'string',
43
+                'format'      => 'uri',
44
+                'context'     => [ 'view', 'edit' ],
45
+            ],
46
+            'srcset'    => [
47
+                'description' => __( 'Thumbnail srcset for responsive images.', 'woocommerce' ),
48
+                'type'        => 'string',
49
+                'context'     => [ 'view', 'edit' ],
50
+            ],
51
+            'sizes'     => [
52
+                'description' => __( 'Thumbnail sizes for responsive images.', 'woocommerce' ),
53
+                'type'        => 'string',
54
+                'context'     => [ 'view', 'edit' ],
55
+            ],
56
+            'name'      => [
57
+                'description' => __( 'Image name.', 'woocommerce' ),
58
+                'type'        => 'string',
59
+                'context'     => [ 'view', 'edit' ],
60
+            ],
61
+            'alt'       => [
62
+                'description' => __( 'Image alternative text.', 'woocommerce' ),
63
+                'type'        => 'string',
64
+                'context'     => [ 'view', 'edit' ],
65
+            ],
66
+        ];
67
+    }
68 68
 
69
-	/**
70
-	 * Convert a WooCommerce product into an object suitable for the response.
71
-	 *
72
-	 * @param int $attachment_id Image attachment ID.
73
-	 * @return array|null
74
-	 */
75
-	public function get_item_response( $attachment_id ) {
76
-		if ( ! $attachment_id ) {
77
-			return null;
78
-		}
69
+    /**
70
+     * Convert a WooCommerce product into an object suitable for the response.
71
+     *
72
+     * @param int $attachment_id Image attachment ID.
73
+     * @return array|null
74
+     */
75
+    public function get_item_response( $attachment_id ) {
76
+        if ( ! $attachment_id ) {
77
+            return null;
78
+        }
79 79
 
80
-		$attachment = wp_get_attachment_image_src( $attachment_id, 'full' );
80
+        $attachment = wp_get_attachment_image_src( $attachment_id, 'full' );
81 81
 
82
-		if ( ! is_array( $attachment ) ) {
83
-			return [];
84
-		}
82
+        if ( ! is_array( $attachment ) ) {
83
+            return [];
84
+        }
85 85
 
86
-		$thumbnail = wp_get_attachment_image_src( $attachment_id, 'woocommerce_thumbnail' );
86
+        $thumbnail = wp_get_attachment_image_src( $attachment_id, 'woocommerce_thumbnail' );
87 87
 
88
-		return [
89
-			'id'        => (int) $attachment_id,
90
-			'src'       => current( $attachment ),
91
-			'thumbnail' => current( $thumbnail ),
92
-			'srcset'    => (string) wp_get_attachment_image_srcset( $attachment_id, 'full' ),
93
-			'sizes'     => (string) wp_get_attachment_image_sizes( $attachment_id, 'full' ),
94
-			'name'      => get_the_title( $attachment_id ),
95
-			'alt'       => get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ),
96
-		];
97
-	}
88
+        return [
89
+            'id'        => (int) $attachment_id,
90
+            'src'       => current( $attachment ),
91
+            'thumbnail' => current( $thumbnail ),
92
+            'srcset'    => (string) wp_get_attachment_image_srcset( $attachment_id, 'full' ),
93
+            'sizes'     => (string) wp_get_attachment_image_sizes( $attachment_id, 'full' ),
94
+            'name'      => get_the_title( $attachment_id ),
95
+            'alt'       => get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ),
96
+        ];
97
+    }
98 98
 
99 99
 }
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -27,41 +27,41 @@  discard block
 block discarded – undo
27 27
 	public function get_properties() {
28 28
 		return [
29 29
 			'id'        => [
30
-				'description' => __( 'Image ID.', 'woocommerce' ),
30
+				'description' => __('Image ID.', 'woocommerce'),
31 31
 				'type'        => 'integer',
32
-				'context'     => [ 'view', 'edit' ],
32
+				'context'     => ['view', 'edit'],
33 33
 			],
34 34
 			'src'       => [
35
-				'description' => __( 'Full size image URL.', 'woocommerce' ),
35
+				'description' => __('Full size image URL.', 'woocommerce'),
36 36
 				'type'        => 'string',
37 37
 				'format'      => 'uri',
38
-				'context'     => [ 'view', 'edit' ],
38
+				'context'     => ['view', 'edit'],
39 39
 			],
40 40
 			'thumbnail' => [
41
-				'description' => __( 'Thumbnail URL.', 'woocommerce' ),
41
+				'description' => __('Thumbnail URL.', 'woocommerce'),
42 42
 				'type'        => 'string',
43 43
 				'format'      => 'uri',
44
-				'context'     => [ 'view', 'edit' ],
44
+				'context'     => ['view', 'edit'],
45 45
 			],
46 46
 			'srcset'    => [
47
-				'description' => __( 'Thumbnail srcset for responsive images.', 'woocommerce' ),
47
+				'description' => __('Thumbnail srcset for responsive images.', 'woocommerce'),
48 48
 				'type'        => 'string',
49
-				'context'     => [ 'view', 'edit' ],
49
+				'context'     => ['view', 'edit'],
50 50
 			],
51 51
 			'sizes'     => [
52
-				'description' => __( 'Thumbnail sizes for responsive images.', 'woocommerce' ),
52
+				'description' => __('Thumbnail sizes for responsive images.', 'woocommerce'),
53 53
 				'type'        => 'string',
54
-				'context'     => [ 'view', 'edit' ],
54
+				'context'     => ['view', 'edit'],
55 55
 			],
56 56
 			'name'      => [
57
-				'description' => __( 'Image name.', 'woocommerce' ),
57
+				'description' => __('Image name.', 'woocommerce'),
58 58
 				'type'        => 'string',
59
-				'context'     => [ 'view', 'edit' ],
59
+				'context'     => ['view', 'edit'],
60 60
 			],
61 61
 			'alt'       => [
62
-				'description' => __( 'Image alternative text.', 'woocommerce' ),
62
+				'description' => __('Image alternative text.', 'woocommerce'),
63 63
 				'type'        => 'string',
64
-				'context'     => [ 'view', 'edit' ],
64
+				'context'     => ['view', 'edit'],
65 65
 			],
66 66
 		];
67 67
 	}
@@ -72,27 +72,27 @@  discard block
 block discarded – undo
72 72
 	 * @param int $attachment_id Image attachment ID.
73 73
 	 * @return array|null
74 74
 	 */
75
-	public function get_item_response( $attachment_id ) {
76
-		if ( ! $attachment_id ) {
75
+	public function get_item_response($attachment_id) {
76
+		if (!$attachment_id) {
77 77
 			return null;
78 78
 		}
79 79
 
80
-		$attachment = wp_get_attachment_image_src( $attachment_id, 'full' );
80
+		$attachment = wp_get_attachment_image_src($attachment_id, 'full');
81 81
 
82
-		if ( ! is_array( $attachment ) ) {
82
+		if (!is_array($attachment)) {
83 83
 			return [];
84 84
 		}
85 85
 
86
-		$thumbnail = wp_get_attachment_image_src( $attachment_id, 'woocommerce_thumbnail' );
86
+		$thumbnail = wp_get_attachment_image_src($attachment_id, 'woocommerce_thumbnail');
87 87
 
88 88
 		return [
89 89
 			'id'        => (int) $attachment_id,
90
-			'src'       => current( $attachment ),
91
-			'thumbnail' => current( $thumbnail ),
92
-			'srcset'    => (string) wp_get_attachment_image_srcset( $attachment_id, 'full' ),
93
-			'sizes'     => (string) wp_get_attachment_image_sizes( $attachment_id, 'full' ),
94
-			'name'      => get_the_title( $attachment_id ),
95
-			'alt'       => get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ),
90
+			'src'       => current($attachment),
91
+			'thumbnail' => current($thumbnail),
92
+			'srcset'    => (string) wp_get_attachment_image_srcset($attachment_id, 'full'),
93
+			'sizes'     => (string) wp_get_attachment_image_sizes($attachment_id, 'full'),
94
+			'name'      => get_the_title($attachment_id),
95
+			'alt'       => get_post_meta($attachment_id, '_wp_attachment_image_alt', true),
96 96
 		];
97 97
 	}
98 98
 
Please login to merge, or discard this patch.
packages/woocommerce-blocks/src/StoreApi/Schemas/V1/ProductReviewSchema.php 2 patches
Indentation   +165 added lines, -165 removed lines patch added patch discarded remove patch
@@ -8,179 +8,179 @@
 block discarded – undo
8 8
  * ProductReviewSchema class.
9 9
  */
10 10
 class ProductReviewSchema extends AbstractSchema {
11
-	/**
12
-	 * The schema item name.
13
-	 *
14
-	 * @var string
15
-	 */
16
-	protected $title = 'product_review';
11
+    /**
12
+     * The schema item name.
13
+     *
14
+     * @var string
15
+     */
16
+    protected $title = 'product_review';
17 17
 
18
-	/**
19
-	 * The schema item identifier.
20
-	 *
21
-	 * @var string
22
-	 */
23
-	const IDENTIFIER = 'product-review';
18
+    /**
19
+     * The schema item identifier.
20
+     *
21
+     * @var string
22
+     */
23
+    const IDENTIFIER = 'product-review';
24 24
 
25
-	/**
26
-	 * Image attachment schema instance.
27
-	 *
28
-	 * @var ImageAttachmentSchema
29
-	 */
30
-	protected $image_attachment_schema;
25
+    /**
26
+     * Image attachment schema instance.
27
+     *
28
+     * @var ImageAttachmentSchema
29
+     */
30
+    protected $image_attachment_schema;
31 31
 
32
-	/**
33
-	 * Constructor.
34
-	 *
35
-	 * @param ExtendSchema     $extend Rest Extending instance.
36
-	 * @param SchemaController $controller Schema Controller instance.
37
-	 */
38
-	public function __construct( ExtendSchema $extend, SchemaController $controller ) {
39
-		parent::__construct( $extend, $controller );
40
-		$this->image_attachment_schema = $this->controller->get( ImageAttachmentSchema::IDENTIFIER );
41
-	}
32
+    /**
33
+     * Constructor.
34
+     *
35
+     * @param ExtendSchema     $extend Rest Extending instance.
36
+     * @param SchemaController $controller Schema Controller instance.
37
+     */
38
+    public function __construct( ExtendSchema $extend, SchemaController $controller ) {
39
+        parent::__construct( $extend, $controller );
40
+        $this->image_attachment_schema = $this->controller->get( ImageAttachmentSchema::IDENTIFIER );
41
+    }
42 42
 
43
-	/**
44
-	 * Product review schema properties.
45
-	 *
46
-	 * @return array
47
-	 */
48
-	public function get_properties() {
49
-		$properties = [
50
-			'id'                     => [
51
-				'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
52
-				'type'        => 'integer',
53
-				'context'     => [ 'view', 'edit' ],
54
-				'readonly'    => true,
55
-			],
56
-			'date_created'           => [
57
-				'description' => __( "The date the review was created, in the site's timezone.", 'woocommerce' ),
58
-				'type'        => 'string',
59
-				'format'      => 'date-time',
60
-				'context'     => [ 'view', 'edit' ],
61
-				'readonly'    => true,
62
-			],
63
-			'formatted_date_created' => [
64
-				'description' => __( "The date the review was created, in the site's timezone in human-readable format.", 'woocommerce' ),
65
-				'type'        => 'string',
66
-				'context'     => [ 'view', 'edit' ],
67
-				'readonly'    => true,
68
-			],
69
-			'date_created_gmt'       => [
70
-				'description' => __( 'The date the review was created, as GMT.', 'woocommerce' ),
71
-				'type'        => 'string',
72
-				'format'      => 'date-time',
73
-				'context'     => [ 'view', 'edit' ],
74
-				'readonly'    => true,
75
-			],
76
-			'product_id'             => [
77
-				'description' => __( 'Unique identifier for the product that the review belongs to.', 'woocommerce' ),
78
-				'type'        => 'integer',
79
-				'context'     => [ 'view', 'edit' ],
80
-				'readonly'    => true,
81
-			],
82
-			'product_name'           => [
83
-				'description' => __( 'Name of the product that the review belongs to.', 'woocommerce' ),
84
-				'type'        => 'string',
85
-				'context'     => [ 'view', 'edit' ],
86
-				'readonly'    => true,
87
-			],
88
-			'product_permalink'      => [
89
-				'description' => __( 'Permalink of the product that the review belongs to.', 'woocommerce' ),
90
-				'type'        => 'string',
91
-				'context'     => [ 'view', 'edit' ],
92
-				'readonly'    => true,
93
-			],
94
-			'product_image'          => [
95
-				'description' => __( 'Image of the product that the review belongs to.', 'woocommerce' ),
96
-				'type'        => 'object',
97
-				'context'     => [ 'view', 'edit' ],
98
-				'readonly'    => true,
99
-				'properties'  => $this->image_attachment_schema->get_properties(),
100
-			],
101
-			'reviewer'               => [
102
-				'description' => __( 'Reviewer name.', 'woocommerce' ),
103
-				'type'        => 'string',
104
-				'context'     => [ 'view', 'edit' ],
105
-				'readonly'    => true,
106
-			],
107
-			'review'                 => [
108
-				'description' => __( 'The content of the review.', 'woocommerce' ),
109
-				'type'        => 'string',
110
-				'context'     => [ 'view', 'edit' ],
111
-				'arg_options' => [
112
-					'sanitize_callback' => 'wp_filter_post_kses',
113
-				],
114
-				'readonly'    => true,
115
-			],
116
-			'rating'                 => [
117
-				'description' => __( 'Review rating (0 to 5).', 'woocommerce' ),
118
-				'type'        => 'integer',
119
-				'context'     => [ 'view', 'edit' ],
120
-				'readonly'    => true,
121
-			],
122
-			'verified'               => [
123
-				'description' => __( 'Shows if the reviewer bought the product or not.', 'woocommerce' ),
124
-				'type'        => 'boolean',
125
-				'context'     => [ 'view', 'edit' ],
126
-				'readonly'    => true,
127
-			],
128
-		];
43
+    /**
44
+     * Product review schema properties.
45
+     *
46
+     * @return array
47
+     */
48
+    public function get_properties() {
49
+        $properties = [
50
+            'id'                     => [
51
+                'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
52
+                'type'        => 'integer',
53
+                'context'     => [ 'view', 'edit' ],
54
+                'readonly'    => true,
55
+            ],
56
+            'date_created'           => [
57
+                'description' => __( "The date the review was created, in the site's timezone.", 'woocommerce' ),
58
+                'type'        => 'string',
59
+                'format'      => 'date-time',
60
+                'context'     => [ 'view', 'edit' ],
61
+                'readonly'    => true,
62
+            ],
63
+            'formatted_date_created' => [
64
+                'description' => __( "The date the review was created, in the site's timezone in human-readable format.", 'woocommerce' ),
65
+                'type'        => 'string',
66
+                'context'     => [ 'view', 'edit' ],
67
+                'readonly'    => true,
68
+            ],
69
+            'date_created_gmt'       => [
70
+                'description' => __( 'The date the review was created, as GMT.', 'woocommerce' ),
71
+                'type'        => 'string',
72
+                'format'      => 'date-time',
73
+                'context'     => [ 'view', 'edit' ],
74
+                'readonly'    => true,
75
+            ],
76
+            'product_id'             => [
77
+                'description' => __( 'Unique identifier for the product that the review belongs to.', 'woocommerce' ),
78
+                'type'        => 'integer',
79
+                'context'     => [ 'view', 'edit' ],
80
+                'readonly'    => true,
81
+            ],
82
+            'product_name'           => [
83
+                'description' => __( 'Name of the product that the review belongs to.', 'woocommerce' ),
84
+                'type'        => 'string',
85
+                'context'     => [ 'view', 'edit' ],
86
+                'readonly'    => true,
87
+            ],
88
+            'product_permalink'      => [
89
+                'description' => __( 'Permalink of the product that the review belongs to.', 'woocommerce' ),
90
+                'type'        => 'string',
91
+                'context'     => [ 'view', 'edit' ],
92
+                'readonly'    => true,
93
+            ],
94
+            'product_image'          => [
95
+                'description' => __( 'Image of the product that the review belongs to.', 'woocommerce' ),
96
+                'type'        => 'object',
97
+                'context'     => [ 'view', 'edit' ],
98
+                'readonly'    => true,
99
+                'properties'  => $this->image_attachment_schema->get_properties(),
100
+            ],
101
+            'reviewer'               => [
102
+                'description' => __( 'Reviewer name.', 'woocommerce' ),
103
+                'type'        => 'string',
104
+                'context'     => [ 'view', 'edit' ],
105
+                'readonly'    => true,
106
+            ],
107
+            'review'                 => [
108
+                'description' => __( 'The content of the review.', 'woocommerce' ),
109
+                'type'        => 'string',
110
+                'context'     => [ 'view', 'edit' ],
111
+                'arg_options' => [
112
+                    'sanitize_callback' => 'wp_filter_post_kses',
113
+                ],
114
+                'readonly'    => true,
115
+            ],
116
+            'rating'                 => [
117
+                'description' => __( 'Review rating (0 to 5).', 'woocommerce' ),
118
+                'type'        => 'integer',
119
+                'context'     => [ 'view', 'edit' ],
120
+                'readonly'    => true,
121
+            ],
122
+            'verified'               => [
123
+                'description' => __( 'Shows if the reviewer bought the product or not.', 'woocommerce' ),
124
+                'type'        => 'boolean',
125
+                'context'     => [ 'view', 'edit' ],
126
+                'readonly'    => true,
127
+            ],
128
+        ];
129 129
 
130
-		if ( get_option( 'show_avatars' ) ) {
131
-			$avatar_properties = array();
132
-			$avatar_sizes      = rest_get_avatar_sizes();
130
+        if ( get_option( 'show_avatars' ) ) {
131
+            $avatar_properties = array();
132
+            $avatar_sizes      = rest_get_avatar_sizes();
133 133
 
134
-			foreach ( $avatar_sizes as $size ) {
135
-				$avatar_properties[ $size ] = array(
136
-					/* translators: %d: avatar image size in pixels */
137
-					'description' => sprintf( __( 'Avatar URL with image size of %d pixels.', 'woocommerce' ), $size ),
138
-					'type'        => 'string',
139
-					'format'      => 'uri',
140
-					'context'     => array( 'embed', 'view', 'edit' ),
141
-				);
142
-			}
143
-			$properties['reviewer_avatar_urls'] = array(
144
-				'description' => __( 'Avatar URLs for the object reviewer.', 'woocommerce' ),
145
-				'type'        => 'object',
146
-				'context'     => array( 'view', 'edit' ),
147
-				'readonly'    => true,
148
-				'properties'  => $avatar_properties,
149
-			);
150
-		}
134
+            foreach ( $avatar_sizes as $size ) {
135
+                $avatar_properties[ $size ] = array(
136
+                    /* translators: %d: avatar image size in pixels */
137
+                    'description' => sprintf( __( 'Avatar URL with image size of %d pixels.', 'woocommerce' ), $size ),
138
+                    'type'        => 'string',
139
+                    'format'      => 'uri',
140
+                    'context'     => array( 'embed', 'view', 'edit' ),
141
+                );
142
+            }
143
+            $properties['reviewer_avatar_urls'] = array(
144
+                'description' => __( 'Avatar URLs for the object reviewer.', 'woocommerce' ),
145
+                'type'        => 'object',
146
+                'context'     => array( 'view', 'edit' ),
147
+                'readonly'    => true,
148
+                'properties'  => $avatar_properties,
149
+            );
150
+        }
151 151
 
152
-		return $properties;
153
-	}
152
+        return $properties;
153
+    }
154 154
 
155
-	/**
156
-	 * Convert a WooCommerce product into an object suitable for the response.
157
-	 *
158
-	 * @param \WP_Comment $review Product review object.
159
-	 * @return array
160
-	 */
161
-	public function get_item_response( \WP_Comment $review ) {
162
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
163
-		$rating  = get_comment_meta( $review->comment_ID, 'rating', true ) === '' ? null : (int) get_comment_meta( $review->comment_ID, 'rating', true );
164
-		$data    = [
165
-			'id'                     => (int) $review->comment_ID,
166
-			'date_created'           => wc_rest_prepare_date_response( $review->comment_date ),
167
-			'formatted_date_created' => get_comment_date( 'F j, Y', $review->comment_ID ),
168
-			'date_created_gmt'       => wc_rest_prepare_date_response( $review->comment_date_gmt ),
169
-			'product_id'             => (int) $review->comment_post_ID,
170
-			'product_name'           => get_the_title( (int) $review->comment_post_ID ),
171
-			'product_permalink'      => get_permalink( (int) $review->comment_post_ID ),
172
-			'product_image'          => $this->image_attachment_schema->get_item_response( get_post_thumbnail_id( (int) $review->comment_post_ID ) ),
173
-			'reviewer'               => $review->comment_author,
174
-			'review'                 => $review->comment_content,
175
-			'rating'                 => $rating,
176
-			'verified'               => wc_review_is_from_verified_owner( $review->comment_ID ),
177
-			'reviewer_avatar_urls'   => rest_get_avatar_urls( $review->comment_author_email ),
178
-		];
155
+    /**
156
+     * Convert a WooCommerce product into an object suitable for the response.
157
+     *
158
+     * @param \WP_Comment $review Product review object.
159
+     * @return array
160
+     */
161
+    public function get_item_response( \WP_Comment $review ) {
162
+        $context = ! empty( $request['context'] ) ? $request['context'] : 'view';
163
+        $rating  = get_comment_meta( $review->comment_ID, 'rating', true ) === '' ? null : (int) get_comment_meta( $review->comment_ID, 'rating', true );
164
+        $data    = [
165
+            'id'                     => (int) $review->comment_ID,
166
+            'date_created'           => wc_rest_prepare_date_response( $review->comment_date ),
167
+            'formatted_date_created' => get_comment_date( 'F j, Y', $review->comment_ID ),
168
+            'date_created_gmt'       => wc_rest_prepare_date_response( $review->comment_date_gmt ),
169
+            'product_id'             => (int) $review->comment_post_ID,
170
+            'product_name'           => get_the_title( (int) $review->comment_post_ID ),
171
+            'product_permalink'      => get_permalink( (int) $review->comment_post_ID ),
172
+            'product_image'          => $this->image_attachment_schema->get_item_response( get_post_thumbnail_id( (int) $review->comment_post_ID ) ),
173
+            'reviewer'               => $review->comment_author,
174
+            'review'                 => $review->comment_content,
175
+            'rating'                 => $rating,
176
+            'verified'               => wc_review_is_from_verified_owner( $review->comment_ID ),
177
+            'reviewer_avatar_urls'   => rest_get_avatar_urls( $review->comment_author_email ),
178
+        ];
179 179
 
180
-		if ( 'view' === $context ) {
181
-			$data['review'] = wpautop( $data['review'] );
182
-		}
180
+        if ( 'view' === $context ) {
181
+            $data['review'] = wpautop( $data['review'] );
182
+        }
183 183
 
184
-		return $data;
185
-	}
184
+        return $data;
185
+    }
186 186
 }
Please login to merge, or discard this patch.
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -35,9 +35,9 @@  discard block
 block discarded – undo
35 35
 	 * @param ExtendSchema     $extend Rest Extending instance.
36 36
 	 * @param SchemaController $controller Schema Controller instance.
37 37
 	 */
38
-	public function __construct( ExtendSchema $extend, SchemaController $controller ) {
39
-		parent::__construct( $extend, $controller );
40
-		$this->image_attachment_schema = $this->controller->get( ImageAttachmentSchema::IDENTIFIER );
38
+	public function __construct(ExtendSchema $extend, SchemaController $controller) {
39
+		parent::__construct($extend, $controller);
40
+		$this->image_attachment_schema = $this->controller->get(ImageAttachmentSchema::IDENTIFIER);
41 41
 	}
42 42
 
43 43
 	/**
@@ -48,102 +48,102 @@  discard block
 block discarded – undo
48 48
 	public function get_properties() {
49 49
 		$properties = [
50 50
 			'id'                     => [
51
-				'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
51
+				'description' => __('Unique identifier for the resource.', 'woocommerce'),
52 52
 				'type'        => 'integer',
53
-				'context'     => [ 'view', 'edit' ],
53
+				'context'     => ['view', 'edit'],
54 54
 				'readonly'    => true,
55 55
 			],
56 56
 			'date_created'           => [
57
-				'description' => __( "The date the review was created, in the site's timezone.", 'woocommerce' ),
57
+				'description' => __("The date the review was created, in the site's timezone.", 'woocommerce'),
58 58
 				'type'        => 'string',
59 59
 				'format'      => 'date-time',
60
-				'context'     => [ 'view', 'edit' ],
60
+				'context'     => ['view', 'edit'],
61 61
 				'readonly'    => true,
62 62
 			],
63 63
 			'formatted_date_created' => [
64
-				'description' => __( "The date the review was created, in the site's timezone in human-readable format.", 'woocommerce' ),
64
+				'description' => __("The date the review was created, in the site's timezone in human-readable format.", 'woocommerce'),
65 65
 				'type'        => 'string',
66
-				'context'     => [ 'view', 'edit' ],
66
+				'context'     => ['view', 'edit'],
67 67
 				'readonly'    => true,
68 68
 			],
69 69
 			'date_created_gmt'       => [
70
-				'description' => __( 'The date the review was created, as GMT.', 'woocommerce' ),
70
+				'description' => __('The date the review was created, as GMT.', 'woocommerce'),
71 71
 				'type'        => 'string',
72 72
 				'format'      => 'date-time',
73
-				'context'     => [ 'view', 'edit' ],
73
+				'context'     => ['view', 'edit'],
74 74
 				'readonly'    => true,
75 75
 			],
76 76
 			'product_id'             => [
77
-				'description' => __( 'Unique identifier for the product that the review belongs to.', 'woocommerce' ),
77
+				'description' => __('Unique identifier for the product that the review belongs to.', 'woocommerce'),
78 78
 				'type'        => 'integer',
79
-				'context'     => [ 'view', 'edit' ],
79
+				'context'     => ['view', 'edit'],
80 80
 				'readonly'    => true,
81 81
 			],
82 82
 			'product_name'           => [
83
-				'description' => __( 'Name of the product that the review belongs to.', 'woocommerce' ),
83
+				'description' => __('Name of the product that the review belongs to.', 'woocommerce'),
84 84
 				'type'        => 'string',
85
-				'context'     => [ 'view', 'edit' ],
85
+				'context'     => ['view', 'edit'],
86 86
 				'readonly'    => true,
87 87
 			],
88 88
 			'product_permalink'      => [
89
-				'description' => __( 'Permalink of the product that the review belongs to.', 'woocommerce' ),
89
+				'description' => __('Permalink of the product that the review belongs to.', 'woocommerce'),
90 90
 				'type'        => 'string',
91
-				'context'     => [ 'view', 'edit' ],
91
+				'context'     => ['view', 'edit'],
92 92
 				'readonly'    => true,
93 93
 			],
94 94
 			'product_image'          => [
95
-				'description' => __( 'Image of the product that the review belongs to.', 'woocommerce' ),
95
+				'description' => __('Image of the product that the review belongs to.', 'woocommerce'),
96 96
 				'type'        => 'object',
97
-				'context'     => [ 'view', 'edit' ],
97
+				'context'     => ['view', 'edit'],
98 98
 				'readonly'    => true,
99 99
 				'properties'  => $this->image_attachment_schema->get_properties(),
100 100
 			],
101 101
 			'reviewer'               => [
102
-				'description' => __( 'Reviewer name.', 'woocommerce' ),
102
+				'description' => __('Reviewer name.', 'woocommerce'),
103 103
 				'type'        => 'string',
104
-				'context'     => [ 'view', 'edit' ],
104
+				'context'     => ['view', 'edit'],
105 105
 				'readonly'    => true,
106 106
 			],
107 107
 			'review'                 => [
108
-				'description' => __( 'The content of the review.', 'woocommerce' ),
108
+				'description' => __('The content of the review.', 'woocommerce'),
109 109
 				'type'        => 'string',
110
-				'context'     => [ 'view', 'edit' ],
110
+				'context'     => ['view', 'edit'],
111 111
 				'arg_options' => [
112 112
 					'sanitize_callback' => 'wp_filter_post_kses',
113 113
 				],
114 114
 				'readonly'    => true,
115 115
 			],
116 116
 			'rating'                 => [
117
-				'description' => __( 'Review rating (0 to 5).', 'woocommerce' ),
117
+				'description' => __('Review rating (0 to 5).', 'woocommerce'),
118 118
 				'type'        => 'integer',
119
-				'context'     => [ 'view', 'edit' ],
119
+				'context'     => ['view', 'edit'],
120 120
 				'readonly'    => true,
121 121
 			],
122 122
 			'verified'               => [
123
-				'description' => __( 'Shows if the reviewer bought the product or not.', 'woocommerce' ),
123
+				'description' => __('Shows if the reviewer bought the product or not.', 'woocommerce'),
124 124
 				'type'        => 'boolean',
125
-				'context'     => [ 'view', 'edit' ],
125
+				'context'     => ['view', 'edit'],
126 126
 				'readonly'    => true,
127 127
 			],
128 128
 		];
129 129
 
130
-		if ( get_option( 'show_avatars' ) ) {
130
+		if (get_option('show_avatars')) {
131 131
 			$avatar_properties = array();
132 132
 			$avatar_sizes      = rest_get_avatar_sizes();
133 133
 
134
-			foreach ( $avatar_sizes as $size ) {
135
-				$avatar_properties[ $size ] = array(
134
+			foreach ($avatar_sizes as $size) {
135
+				$avatar_properties[$size] = array(
136 136
 					/* translators: %d: avatar image size in pixels */
137
-					'description' => sprintf( __( 'Avatar URL with image size of %d pixels.', 'woocommerce' ), $size ),
137
+					'description' => sprintf(__('Avatar URL with image size of %d pixels.', 'woocommerce'), $size),
138 138
 					'type'        => 'string',
139 139
 					'format'      => 'uri',
140
-					'context'     => array( 'embed', 'view', 'edit' ),
140
+					'context'     => array('embed', 'view', 'edit'),
141 141
 				);
142 142
 			}
143 143
 			$properties['reviewer_avatar_urls'] = array(
144
-				'description' => __( 'Avatar URLs for the object reviewer.', 'woocommerce' ),
144
+				'description' => __('Avatar URLs for the object reviewer.', 'woocommerce'),
145 145
 				'type'        => 'object',
146
-				'context'     => array( 'view', 'edit' ),
146
+				'context'     => array('view', 'edit'),
147 147
 				'readonly'    => true,
148 148
 				'properties'  => $avatar_properties,
149 149
 			);
@@ -158,27 +158,27 @@  discard block
 block discarded – undo
158 158
 	 * @param \WP_Comment $review Product review object.
159 159
 	 * @return array
160 160
 	 */
161
-	public function get_item_response( \WP_Comment $review ) {
162
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
163
-		$rating  = get_comment_meta( $review->comment_ID, 'rating', true ) === '' ? null : (int) get_comment_meta( $review->comment_ID, 'rating', true );
161
+	public function get_item_response(\WP_Comment $review) {
162
+		$context = !empty($request['context']) ? $request['context'] : 'view';
163
+		$rating  = get_comment_meta($review->comment_ID, 'rating', true) === '' ? null : (int) get_comment_meta($review->comment_ID, 'rating', true);
164 164
 		$data    = [
165 165
 			'id'                     => (int) $review->comment_ID,
166
-			'date_created'           => wc_rest_prepare_date_response( $review->comment_date ),
167
-			'formatted_date_created' => get_comment_date( 'F j, Y', $review->comment_ID ),
168
-			'date_created_gmt'       => wc_rest_prepare_date_response( $review->comment_date_gmt ),
166
+			'date_created'           => wc_rest_prepare_date_response($review->comment_date),
167
+			'formatted_date_created' => get_comment_date('F j, Y', $review->comment_ID),
168
+			'date_created_gmt'       => wc_rest_prepare_date_response($review->comment_date_gmt),
169 169
 			'product_id'             => (int) $review->comment_post_ID,
170
-			'product_name'           => get_the_title( (int) $review->comment_post_ID ),
171
-			'product_permalink'      => get_permalink( (int) $review->comment_post_ID ),
172
-			'product_image'          => $this->image_attachment_schema->get_item_response( get_post_thumbnail_id( (int) $review->comment_post_ID ) ),
170
+			'product_name'           => get_the_title((int) $review->comment_post_ID),
171
+			'product_permalink'      => get_permalink((int) $review->comment_post_ID),
172
+			'product_image'          => $this->image_attachment_schema->get_item_response(get_post_thumbnail_id((int) $review->comment_post_ID)),
173 173
 			'reviewer'               => $review->comment_author,
174 174
 			'review'                 => $review->comment_content,
175 175
 			'rating'                 => $rating,
176
-			'verified'               => wc_review_is_from_verified_owner( $review->comment_ID ),
177
-			'reviewer_avatar_urls'   => rest_get_avatar_urls( $review->comment_author_email ),
176
+			'verified'               => wc_review_is_from_verified_owner($review->comment_ID),
177
+			'reviewer_avatar_urls'   => rest_get_avatar_urls($review->comment_author_email),
178 178
 		];
179 179
 
180
-		if ( 'view' === $context ) {
181
-			$data['review'] = wpautop( $data['review'] );
180
+		if ('view' === $context) {
181
+			$data['review'] = wpautop($data['review']);
182 182
 		}
183 183
 
184 184
 		return $data;
Please login to merge, or discard this patch.
packages/woocommerce-blocks/src/StoreApi/Schemas/V1/ProductSchema.php 2 patches
Indentation   +840 added lines, -840 removed lines patch added patch discarded remove patch
@@ -9,849 +9,849 @@
 block discarded – undo
9 9
  * ProductSchema class.
10 10
  */
11 11
 class ProductSchema extends AbstractSchema {
12
-	/**
13
-	 * The schema item name.
14
-	 *
15
-	 * @var string
16
-	 */
17
-	protected $title = 'product';
18
-
19
-	/**
20
-	 * The schema item identifier.
21
-	 *
22
-	 * @var string
23
-	 */
24
-	const IDENTIFIER = 'product';
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
-	 * Product schema properties.
46
-	 *
47
-	 * @return array
48
-	 */
49
-	public function get_properties() {
50
-		return [
51
-			'id'                  => [
52
-				'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
53
-				'type'        => 'integer',
54
-				'context'     => [ 'view', 'edit' ],
55
-				'readonly'    => true,
56
-			],
57
-			'name'                => [
58
-				'description' => __( 'Product name.', 'woocommerce' ),
59
-				'type'        => 'string',
60
-				'context'     => [ 'view', 'edit' ],
61
-			],
62
-			'parent'              => [
63
-				'description' => __( 'ID of the parent product, if applicable.', 'woocommerce' ),
64
-				'type'        => 'integer',
65
-				'context'     => [ 'view', 'edit' ],
66
-				'readonly'    => true,
67
-			],
68
-			'type'                => [
69
-				'description' => __( 'Product type.', 'woocommerce' ),
70
-				'type'        => 'string',
71
-				'context'     => [ 'view', 'edit' ],
72
-				'readonly'    => true,
73
-			],
74
-			'variation'           => [
75
-				'description' => __( 'Product variation attributes, if applicable.', 'woocommerce' ),
76
-				'type'        => 'string',
77
-				'context'     => [ 'view', 'edit' ],
78
-			],
79
-			'permalink'           => [
80
-				'description' => __( 'Product URL.', 'woocommerce' ),
81
-				'type'        => 'string',
82
-				'format'      => 'uri',
83
-				'context'     => [ 'view', 'edit' ],
84
-				'readonly'    => true,
85
-			],
86
-			'short_description'   => [
87
-				'description' => __( 'Product short description in HTML format.', 'woocommerce' ),
88
-				'type'        => 'string',
89
-				'context'     => [ 'view', 'edit' ],
90
-			],
91
-			'description'         => [
92
-				'description' => __( 'Product full description in HTML format.', 'woocommerce' ),
93
-				'type'        => 'string',
94
-				'context'     => [ 'view', 'edit' ],
95
-			],
96
-			'on_sale'             => [
97
-				'description' => __( 'Is the product on sale?', 'woocommerce' ),
98
-				'type'        => 'boolean',
99
-				'context'     => [ 'view', 'edit' ],
100
-				'readonly'    => true,
101
-			],
102
-			'sku'                 => [
103
-				'description' => __( 'Unique identifier.', 'woocommerce' ),
104
-				'type'        => 'string',
105
-				'context'     => [ 'view', 'edit' ],
106
-			],
107
-			'prices'              => [
108
-				'description' => __( 'Price data provided using the smallest unit of the currency.', 'woocommerce' ),
109
-				'type'        => 'object',
110
-				'context'     => [ 'view', 'edit' ],
111
-				'readonly'    => true,
112
-				'properties'  => array_merge(
113
-					$this->get_store_currency_properties(),
114
-					[
115
-						'price'         => [
116
-							'description' => __( 'Current product price.', 'woocommerce' ),
117
-							'type'        => 'string',
118
-							'context'     => [ 'view', 'edit' ],
119
-							'readonly'    => true,
120
-						],
121
-						'regular_price' => [
122
-							'description' => __( 'Regular product price.', 'woocommerce' ),
123
-							'type'        => 'string',
124
-							'context'     => [ 'view', 'edit' ],
125
-							'readonly'    => true,
126
-						],
127
-						'sale_price'    => [
128
-							'description' => __( 'Sale product price, if applicable.', 'woocommerce' ),
129
-							'type'        => 'string',
130
-							'context'     => [ 'view', 'edit' ],
131
-							'readonly'    => true,
132
-						],
133
-						'price_range'   => [
134
-							'description' => __( 'Price range, if applicable.', 'woocommerce' ),
135
-							'type'        => [ 'object', 'null' ],
136
-							'context'     => [ 'view', 'edit' ],
137
-							'readonly'    => true,
138
-							'properties'  => [
139
-								'min_amount' => [
140
-									'description' => __( 'Price amount.', 'woocommerce' ),
141
-									'type'        => 'string',
142
-									'context'     => [ 'view', 'edit' ],
143
-									'readonly'    => true,
144
-								],
145
-								'max_amount' => [
146
-									'description' => __( 'Price amount.', 'woocommerce' ),
147
-									'type'        => 'string',
148
-									'context'     => [ 'view', 'edit' ],
149
-									'readonly'    => true,
150
-								],
151
-							],
152
-						],
153
-					]
154
-				),
155
-			],
156
-			'price_html'          => array(
157
-				'description' => __( 'Price string formatted as HTML.', 'woocommerce' ),
158
-				'type'        => 'string',
159
-				'context'     => array( 'view', 'edit' ),
160
-				'readonly'    => true,
161
-			),
162
-			'average_rating'      => [
163
-				'description' => __( 'Reviews average rating.', 'woocommerce' ),
164
-				'type'        => 'string',
165
-				'context'     => [ 'view', 'edit' ],
166
-				'readonly'    => true,
167
-			],
168
-			'review_count'        => [
169
-				'description' => __( 'Amount of reviews that the product has.', 'woocommerce' ),
170
-				'type'        => 'integer',
171
-				'context'     => [ 'view', 'edit' ],
172
-				'readonly'    => true,
173
-			],
174
-			'images'              => [
175
-				'description' => __( 'List of images.', 'woocommerce' ),
176
-				'type'        => 'array',
177
-				'context'     => [ 'view', 'edit' ],
178
-				'items'       => [
179
-					'type'       => 'object',
180
-					'properties' => $this->image_attachment_schema->get_properties(),
181
-				],
182
-			],
183
-			'categories'          => [
184
-				'description' => __( 'List of categories, if applicable.', 'woocommerce' ),
185
-				'type'        => 'array',
186
-				'context'     => [ 'view', 'edit' ],
187
-				'items'       => [
188
-					'type'       => 'object',
189
-					'properties' => [
190
-						'id'   => [
191
-							'description' => __( 'Category ID', 'woocommerce' ),
192
-							'type'        => 'number',
193
-							'context'     => [ 'view', 'edit' ],
194
-							'readonly'    => true,
195
-						],
196
-						'name' => [
197
-							'description' => __( 'Category name', 'woocommerce' ),
198
-							'type'        => 'string',
199
-							'context'     => [ 'view', 'edit' ],
200
-							'readonly'    => true,
201
-						],
202
-						'slug' => [
203
-							'description' => __( 'Category slug', 'woocommerce' ),
204
-							'type'        => 'string',
205
-							'context'     => [ 'view', 'edit' ],
206
-							'readonly'    => true,
207
-						],
208
-						'link' => [
209
-							'description' => __( 'Category link', 'woocommerce' ),
210
-							'type'        => 'string',
211
-							'context'     => [ 'view', 'edit' ],
212
-							'readonly'    => true,
213
-						],
214
-					],
215
-				],
216
-			],
217
-			'tags'                => [
218
-				'description' => __( 'List of tags, if applicable.', 'woocommerce' ),
219
-				'type'        => 'array',
220
-				'context'     => [ 'view', 'edit' ],
221
-				'items'       => [
222
-					'type'       => 'object',
223
-					'properties' => [
224
-						'id'   => [
225
-							'description' => __( 'Tag ID', 'woocommerce' ),
226
-							'type'        => 'number',
227
-							'context'     => [ 'view', 'edit' ],
228
-							'readonly'    => true,
229
-						],
230
-						'name' => [
231
-							'description' => __( 'Tag name', 'woocommerce' ),
232
-							'type'        => 'string',
233
-							'context'     => [ 'view', 'edit' ],
234
-							'readonly'    => true,
235
-						],
236
-						'slug' => [
237
-							'description' => __( 'Tag slug', 'woocommerce' ),
238
-							'type'        => 'string',
239
-							'context'     => [ 'view', 'edit' ],
240
-							'readonly'    => true,
241
-						],
242
-						'link' => [
243
-							'description' => __( 'Tag link', 'woocommerce' ),
244
-							'type'        => 'string',
245
-							'context'     => [ 'view', 'edit' ],
246
-							'readonly'    => true,
247
-						],
248
-					],
249
-				],
250
-			],
251
-			'attributes'          => [
252
-				'description' => __( 'List of attributes assigned to the product/variation that are visible or used for variations.', 'woocommerce' ),
253
-				'type'        => 'array',
254
-				'context'     => [ 'view', 'edit' ],
255
-				'items'       => [
256
-					'type'       => 'object',
257
-					'properties' => [
258
-						'id'             => [
259
-							'description' => __( 'The attribute ID, or 0 if the attribute is not taxonomy based.', 'woocommerce' ),
260
-							'type'        => 'integer',
261
-							'context'     => [ 'view', 'edit' ],
262
-							'readonly'    => true,
263
-						],
264
-						'name'           => [
265
-							'description' => __( 'The attribute name.', 'woocommerce' ),
266
-							'type'        => 'string',
267
-							'context'     => [ 'view', 'edit' ],
268
-							'readonly'    => true,
269
-						],
270
-						'taxonomy'       => [
271
-							'description' => __( 'The attribute taxonomy, or null if the attribute is not taxonomy based.', 'woocommerce' ),
272
-							'type'        => 'string',
273
-							'context'     => [ 'view', 'edit' ],
274
-							'readonly'    => true,
275
-						],
276
-						'has_variations' => [
277
-							'description' => __( 'True if this attribute is used by product variations.', 'woocommerce' ),
278
-							'type'        => 'boolean',
279
-							'context'     => [ 'view', 'edit' ],
280
-							'readonly'    => true,
281
-						],
282
-						'terms'          => [
283
-							'description' => __( 'List of assigned attribute terms.', 'woocommerce' ),
284
-							'type'        => 'array',
285
-							'context'     => [ 'view', 'edit' ],
286
-							'items'       => [
287
-								'type'       => 'object',
288
-								'properties' => [
289
-									'id'      => [
290
-										'description' => __( 'The term ID, or 0 if the attribute is not a global attribute.', 'woocommerce' ),
291
-										'type'        => 'integer',
292
-										'context'     => [ 'view', 'edit' ],
293
-										'readonly'    => true,
294
-									],
295
-									'name'    => [
296
-										'description' => __( 'The term name.', 'woocommerce' ),
297
-										'type'        => 'string',
298
-										'context'     => [ 'view', 'edit' ],
299
-										'readonly'    => true,
300
-									],
301
-									'slug'    => [
302
-										'description' => __( 'The term slug.', 'woocommerce' ),
303
-										'type'        => 'string',
304
-										'context'     => [ 'view', 'edit' ],
305
-										'readonly'    => true,
306
-									],
307
-									'default' => [
308
-										'description' => __( 'If this is a default attribute', 'woocommerce' ),
309
-										'type'        => 'boolean',
310
-										'context'     => [ 'view', 'edit' ],
311
-										'readonly'    => true,
312
-									],
313
-								],
314
-							],
315
-						],
316
-					],
317
-				],
318
-			],
319
-			'variations'          => [
320
-				'description' => __( 'List of variation IDs, if applicable.', 'woocommerce' ),
321
-				'type'        => 'array',
322
-				'context'     => [ 'view', 'edit' ],
323
-				'items'       => [
324
-					'type'       => 'object',
325
-					'properties' => [
326
-						'id'         => [
327
-							'description' => __( 'The attribute ID, or 0 if the attribute is not taxonomy based.', 'woocommerce' ),
328
-							'type'        => 'integer',
329
-							'context'     => [ 'view', 'edit' ],
330
-							'readonly'    => true,
331
-						],
332
-						'attributes' => [
333
-							'description' => __( 'List of variation attributes.', 'woocommerce' ),
334
-							'type'        => 'array',
335
-							'context'     => [ 'view', 'edit' ],
336
-							'items'       => [
337
-								'type'       => 'object',
338
-								'properties' => [
339
-									'name'  => [
340
-										'description' => __( 'The attribute name.', 'woocommerce' ),
341
-										'type'        => 'string',
342
-										'context'     => [ 'view', 'edit' ],
343
-										'readonly'    => true,
344
-									],
345
-									'value' => [
346
-										'description' => __( 'The assigned attribute.', 'woocommerce' ),
347
-										'type'        => 'string',
348
-										'context'     => [ 'view', 'edit' ],
349
-										'readonly'    => true,
350
-									],
351
-								],
352
-							],
353
-						],
354
-					],
355
-				],
356
-			],
357
-			'has_options'         => [
358
-				'description' => __( 'Does the product have additional options before it can be added to the cart?', 'woocommerce' ),
359
-				'type'        => 'boolean',
360
-				'context'     => [ 'view', 'edit' ],
361
-				'readonly'    => true,
362
-			],
363
-			'is_purchasable'      => [
364
-				'description' => __( 'Is the product purchasable?', 'woocommerce' ),
365
-				'type'        => 'boolean',
366
-				'context'     => [ 'view', 'edit' ],
367
-				'readonly'    => true,
368
-			],
369
-			'is_in_stock'         => [
370
-				'description' => __( 'Is the product in stock?', 'woocommerce' ),
371
-				'type'        => 'boolean',
372
-				'context'     => [ 'view', 'edit' ],
373
-				'readonly'    => true,
374
-			],
375
-			'is_on_backorder'     => [
376
-				'description' => __( 'Is the product stock backordered? This will also return false if backorder notifications are turned off.', 'woocommerce' ),
377
-				'type'        => 'boolean',
378
-				'context'     => [ 'view', 'edit' ],
379
-				'readonly'    => true,
380
-			],
381
-			'low_stock_remaining' => [
382
-				'description' => __( 'Quantity left in stock if stock is low, or null if not applicable.', 'woocommerce' ),
383
-				'type'        => [ 'integer', 'null' ],
384
-				'context'     => [ 'view', 'edit' ],
385
-				'readonly'    => true,
386
-			],
387
-			'sold_individually'   => [
388
-				'description' => __( 'If true, only one item of this product is allowed for purchase in a single order.', 'woocommerce' ),
389
-				'type'        => 'boolean',
390
-				'context'     => [ 'view', 'edit' ],
391
-				'readonly'    => true,
392
-			],
393
-			'add_to_cart'         => [
394
-				'description' => __( 'Add to cart button parameters.', 'woocommerce' ),
395
-				'type'        => 'object',
396
-				'context'     => [ 'view', 'edit' ],
397
-				'readonly'    => true,
398
-				'properties'  => [
399
-					'text'        => [
400
-						'description' => __( 'Button text.', 'woocommerce' ),
401
-						'type'        => 'string',
402
-						'context'     => [ 'view', 'edit' ],
403
-						'readonly'    => true,
404
-					],
405
-					'description' => [
406
-						'description' => __( 'Button description.', 'woocommerce' ),
407
-						'type'        => 'string',
408
-						'context'     => [ 'view', 'edit' ],
409
-						'readonly'    => true,
410
-					],
411
-					'url'         => [
412
-						'description' => __( 'Add to cart URL.', 'woocommerce' ),
413
-						'type'        => 'string',
414
-						'context'     => [ 'view', 'edit' ],
415
-						'readonly'    => true,
416
-					],
417
-					'minimum'     => [
418
-						'description' => __( 'The minimum quantity that can be added to the cart.', 'woocommerce' ),
419
-						'type'        => 'integer',
420
-						'context'     => [ 'view', 'edit' ],
421
-						'readonly'    => true,
422
-					],
423
-					'maximum'     => [
424
-						'description' => __( 'The maximum quantity that can be added to the cart.', 'woocommerce' ),
425
-						'type'        => 'integer',
426
-						'context'     => [ 'view', 'edit' ],
427
-						'readonly'    => true,
428
-					],
429
-					'multiple_of' => [
430
-						'description' => __( 'The amount that quantities increment by. Quantity must be an multiple of this value.', 'woocommerce' ),
431
-						'type'        => 'integer',
432
-						'context'     => [ 'view', 'edit' ],
433
-						'readonly'    => true,
434
-						'default'     => 1,
435
-					],
436
-				],
437
-			],
438
-			self::EXTENDING_KEY   => $this->get_extended_schema( self::IDENTIFIER ),
439
-		];
440
-	}
441
-
442
-	/**
443
-	 * Convert a WooCommerce product into an object suitable for the response.
444
-	 *
445
-	 * @param \WC_Product $product Product instance.
446
-	 * @return array
447
-	 */
448
-	public function get_item_response( $product ) {
449
-		return [
450
-			'id'                  => $product->get_id(),
451
-			'name'                => $this->prepare_html_response( $product->get_title() ),
452
-			'parent'              => $product->get_parent_id(),
453
-			'type'                => $product->get_type(),
454
-			'variation'           => $this->prepare_html_response( $product->is_type( 'variation' ) ? wc_get_formatted_variation( $product, true, true, false ) : '' ),
455
-			'permalink'           => $product->get_permalink(),
456
-			'sku'                 => $this->prepare_html_response( $product->get_sku() ),
457
-			'short_description'   => $this->prepare_html_response( wc_format_content( wp_kses_post( $product->get_short_description() ) ) ),
458
-			'description'         => $this->prepare_html_response( wc_format_content( wp_kses_post( $product->get_description() ) ) ),
459
-			'on_sale'             => $product->is_on_sale(),
460
-			'prices'              => (object) $this->prepare_product_price_response( $product ),
461
-			'price_html'          => $this->prepare_html_response( $product->get_price_html() ),
462
-			'average_rating'      => (string) $product->get_average_rating(),
463
-			'review_count'        => $product->get_review_count(),
464
-			'images'              => $this->get_images( $product ),
465
-			'categories'          => $this->get_term_list( $product, 'product_cat' ),
466
-			'tags'                => $this->get_term_list( $product, 'product_tag' ),
467
-			'attributes'          => $this->get_attributes( $product ),
468
-			'variations'          => $this->get_variations( $product ),
469
-			'has_options'         => $product->has_options(),
470
-			'is_purchasable'      => $product->is_purchasable(),
471
-			'is_in_stock'         => $product->is_in_stock(),
472
-			'is_on_backorder'     => 'onbackorder' === $product->get_stock_status(),
473
-			'low_stock_remaining' => $this->get_low_stock_remaining( $product ),
474
-			'sold_individually'   => $product->is_sold_individually(),
475
-			'add_to_cart'         => (object) array_merge(
476
-				[
477
-					'text'        => $this->prepare_html_response( $product->add_to_cart_text() ),
478
-					'description' => $this->prepare_html_response( $product->add_to_cart_description() ),
479
-					'url'         => $this->prepare_html_response( $product->add_to_cart_url() ),
480
-				],
481
-				( new QuantityLimits() )->get_add_to_cart_limits( $product )
482
-			),
483
-			self::EXTENDING_KEY   => $this->get_extended_data( self::IDENTIFIER, $product ),
484
-
485
-		];
486
-	}
487
-
488
-	/**
489
-	 * Get list of product images.
490
-	 *
491
-	 * @param \WC_Product $product Product instance.
492
-	 * @return array
493
-	 */
494
-	protected function get_images( \WC_Product $product ) {
495
-		$attachment_ids = array_merge( [ $product->get_image_id() ], $product->get_gallery_image_ids() );
496
-
497
-		return array_filter( array_map( [ $this->image_attachment_schema, 'get_item_response' ], $attachment_ids ) );
498
-	}
499
-
500
-	/**
501
-	 * Gets remaining stock amount for a product.
502
-	 *
503
-	 * @param \WC_Product $product Product instance.
504
-	 * @return integer|null
505
-	 */
506
-	protected function get_remaining_stock( \WC_Product $product ) {
507
-		if ( is_null( $product->get_stock_quantity() ) ) {
508
-			return null;
509
-		}
510
-		return $product->get_stock_quantity();
511
-	}
512
-
513
-	/**
514
-	 * If a product has low stock, return the remaining stock amount for display.
515
-	 *
516
-	 * @param \WC_Product $product Product instance.
517
-	 * @return integer|null
518
-	 */
519
-	protected function get_low_stock_remaining( \WC_Product $product ) {
520
-		$remaining_stock = $this->get_remaining_stock( $product );
521
-		$stock_format    = get_option( 'woocommerce_stock_format' );
522
-
523
-		// Don't show the low stock badge if the settings doesn't allow it.
524
-		if ( 'no_amount' === $stock_format ) {
525
-			return null;
526
-		}
527
-
528
-		// Show the low stock badge if the remaining stock is below or equal to the threshold.
529
-		if ( ! is_null( $remaining_stock ) && $remaining_stock <= wc_get_low_stock_amount( $product ) ) {
530
-			return max( $remaining_stock, 0 );
531
-		}
532
-
533
-		return null;
534
-	}
535
-
536
-	/**
537
-	 * Returns true if the given attribute is valid.
538
-	 *
539
-	 * @param mixed $attribute Object or variable to check.
540
-	 * @return boolean
541
-	 */
542
-	protected function filter_valid_attribute( $attribute ) {
543
-		return is_a( $attribute, '\WC_Product_Attribute' );
544
-	}
545
-
546
-	/**
547
-	 * Returns true if the given attribute is valid and used for variations.
548
-	 *
549
-	 * @param mixed $attribute Object or variable to check.
550
-	 * @return boolean
551
-	 */
552
-	protected function filter_variation_attribute( $attribute ) {
553
-		return $this->filter_valid_attribute( $attribute ) && $attribute->get_variation();
554
-	}
555
-
556
-	/**
557
-	 * Get variation IDs and attributes from the DB.
558
-	 *
559
-	 * @param \WC_Product $product Product instance.
560
-	 * @returns array
561
-	 */
562
-	protected function get_variations( \WC_Product $product ) {
563
-		$variation_ids = $product->is_type( 'variable' ) ? $product->get_visible_children() : [];
564
-
565
-		if ( ! count( $variation_ids ) ) {
566
-			return [];
567
-		}
568
-
569
-		/**
570
-		 * Gets default variation data which applies to all of this products variations.
571
-		 */
572
-		$attributes                  = array_filter( $product->get_attributes(), [ $this, 'filter_variation_attribute' ] );
573
-		$default_variation_meta_data = array_reduce(
574
-			$attributes,
575
-			function( $defaults, $attribute ) use ( $product ) {
576
-				$meta_key              = wc_variation_attribute_name( $attribute->get_name() );
577
-				$defaults[ $meta_key ] = [
578
-					'name'  => wc_attribute_label( $attribute->get_name(), $product ),
579
-					'value' => null,
580
-				];
581
-				return $defaults;
582
-			},
583
-			[]
584
-		);
585
-		$default_variation_meta_keys = array_keys( $default_variation_meta_data );
586
-
587
-		/**
588
-		 * Gets individual variation data from the database, using cache where possible.
589
-		 */
590
-		$cache_group   = 'product_variation_meta_data';
591
-		$cache_value   = wp_cache_get( $product->get_id(), $cache_group );
592
-		$last_modified = get_the_modified_date( 'U', $product->get_id() );
593
-
594
-		if ( false === $cache_value || $last_modified !== $cache_value['last_modified'] ) {
595
-			global $wpdb;
596
-			// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared
597
-			$variation_meta_data = $wpdb->get_results(
598
-				"
12
+    /**
13
+     * The schema item name.
14
+     *
15
+     * @var string
16
+     */
17
+    protected $title = 'product';
18
+
19
+    /**
20
+     * The schema item identifier.
21
+     *
22
+     * @var string
23
+     */
24
+    const IDENTIFIER = 'product';
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
+     * Product schema properties.
46
+     *
47
+     * @return array
48
+     */
49
+    public function get_properties() {
50
+        return [
51
+            'id'                  => [
52
+                'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
53
+                'type'        => 'integer',
54
+                'context'     => [ 'view', 'edit' ],
55
+                'readonly'    => true,
56
+            ],
57
+            'name'                => [
58
+                'description' => __( 'Product name.', 'woocommerce' ),
59
+                'type'        => 'string',
60
+                'context'     => [ 'view', 'edit' ],
61
+            ],
62
+            'parent'              => [
63
+                'description' => __( 'ID of the parent product, if applicable.', 'woocommerce' ),
64
+                'type'        => 'integer',
65
+                'context'     => [ 'view', 'edit' ],
66
+                'readonly'    => true,
67
+            ],
68
+            'type'                => [
69
+                'description' => __( 'Product type.', 'woocommerce' ),
70
+                'type'        => 'string',
71
+                'context'     => [ 'view', 'edit' ],
72
+                'readonly'    => true,
73
+            ],
74
+            'variation'           => [
75
+                'description' => __( 'Product variation attributes, if applicable.', 'woocommerce' ),
76
+                'type'        => 'string',
77
+                'context'     => [ 'view', 'edit' ],
78
+            ],
79
+            'permalink'           => [
80
+                'description' => __( 'Product URL.', 'woocommerce' ),
81
+                'type'        => 'string',
82
+                'format'      => 'uri',
83
+                'context'     => [ 'view', 'edit' ],
84
+                'readonly'    => true,
85
+            ],
86
+            'short_description'   => [
87
+                'description' => __( 'Product short description in HTML format.', 'woocommerce' ),
88
+                'type'        => 'string',
89
+                'context'     => [ 'view', 'edit' ],
90
+            ],
91
+            'description'         => [
92
+                'description' => __( 'Product full description in HTML format.', 'woocommerce' ),
93
+                'type'        => 'string',
94
+                'context'     => [ 'view', 'edit' ],
95
+            ],
96
+            'on_sale'             => [
97
+                'description' => __( 'Is the product on sale?', 'woocommerce' ),
98
+                'type'        => 'boolean',
99
+                'context'     => [ 'view', 'edit' ],
100
+                'readonly'    => true,
101
+            ],
102
+            'sku'                 => [
103
+                'description' => __( 'Unique identifier.', 'woocommerce' ),
104
+                'type'        => 'string',
105
+                'context'     => [ 'view', 'edit' ],
106
+            ],
107
+            'prices'              => [
108
+                'description' => __( 'Price data provided using the smallest unit of the currency.', 'woocommerce' ),
109
+                'type'        => 'object',
110
+                'context'     => [ 'view', 'edit' ],
111
+                'readonly'    => true,
112
+                'properties'  => array_merge(
113
+                    $this->get_store_currency_properties(),
114
+                    [
115
+                        'price'         => [
116
+                            'description' => __( 'Current product price.', 'woocommerce' ),
117
+                            'type'        => 'string',
118
+                            'context'     => [ 'view', 'edit' ],
119
+                            'readonly'    => true,
120
+                        ],
121
+                        'regular_price' => [
122
+                            'description' => __( 'Regular product price.', 'woocommerce' ),
123
+                            'type'        => 'string',
124
+                            'context'     => [ 'view', 'edit' ],
125
+                            'readonly'    => true,
126
+                        ],
127
+                        'sale_price'    => [
128
+                            'description' => __( 'Sale product price, if applicable.', 'woocommerce' ),
129
+                            'type'        => 'string',
130
+                            'context'     => [ 'view', 'edit' ],
131
+                            'readonly'    => true,
132
+                        ],
133
+                        'price_range'   => [
134
+                            'description' => __( 'Price range, if applicable.', 'woocommerce' ),
135
+                            'type'        => [ 'object', 'null' ],
136
+                            'context'     => [ 'view', 'edit' ],
137
+                            'readonly'    => true,
138
+                            'properties'  => [
139
+                                'min_amount' => [
140
+                                    'description' => __( 'Price amount.', 'woocommerce' ),
141
+                                    'type'        => 'string',
142
+                                    'context'     => [ 'view', 'edit' ],
143
+                                    'readonly'    => true,
144
+                                ],
145
+                                'max_amount' => [
146
+                                    'description' => __( 'Price amount.', 'woocommerce' ),
147
+                                    'type'        => 'string',
148
+                                    'context'     => [ 'view', 'edit' ],
149
+                                    'readonly'    => true,
150
+                                ],
151
+                            ],
152
+                        ],
153
+                    ]
154
+                ),
155
+            ],
156
+            'price_html'          => array(
157
+                'description' => __( 'Price string formatted as HTML.', 'woocommerce' ),
158
+                'type'        => 'string',
159
+                'context'     => array( 'view', 'edit' ),
160
+                'readonly'    => true,
161
+            ),
162
+            'average_rating'      => [
163
+                'description' => __( 'Reviews average rating.', 'woocommerce' ),
164
+                'type'        => 'string',
165
+                'context'     => [ 'view', 'edit' ],
166
+                'readonly'    => true,
167
+            ],
168
+            'review_count'        => [
169
+                'description' => __( 'Amount of reviews that the product has.', 'woocommerce' ),
170
+                'type'        => 'integer',
171
+                'context'     => [ 'view', 'edit' ],
172
+                'readonly'    => true,
173
+            ],
174
+            'images'              => [
175
+                'description' => __( 'List of images.', 'woocommerce' ),
176
+                'type'        => 'array',
177
+                'context'     => [ 'view', 'edit' ],
178
+                'items'       => [
179
+                    'type'       => 'object',
180
+                    'properties' => $this->image_attachment_schema->get_properties(),
181
+                ],
182
+            ],
183
+            'categories'          => [
184
+                'description' => __( 'List of categories, if applicable.', 'woocommerce' ),
185
+                'type'        => 'array',
186
+                'context'     => [ 'view', 'edit' ],
187
+                'items'       => [
188
+                    'type'       => 'object',
189
+                    'properties' => [
190
+                        'id'   => [
191
+                            'description' => __( 'Category ID', 'woocommerce' ),
192
+                            'type'        => 'number',
193
+                            'context'     => [ 'view', 'edit' ],
194
+                            'readonly'    => true,
195
+                        ],
196
+                        'name' => [
197
+                            'description' => __( 'Category name', 'woocommerce' ),
198
+                            'type'        => 'string',
199
+                            'context'     => [ 'view', 'edit' ],
200
+                            'readonly'    => true,
201
+                        ],
202
+                        'slug' => [
203
+                            'description' => __( 'Category slug', 'woocommerce' ),
204
+                            'type'        => 'string',
205
+                            'context'     => [ 'view', 'edit' ],
206
+                            'readonly'    => true,
207
+                        ],
208
+                        'link' => [
209
+                            'description' => __( 'Category link', 'woocommerce' ),
210
+                            'type'        => 'string',
211
+                            'context'     => [ 'view', 'edit' ],
212
+                            'readonly'    => true,
213
+                        ],
214
+                    ],
215
+                ],
216
+            ],
217
+            'tags'                => [
218
+                'description' => __( 'List of tags, if applicable.', 'woocommerce' ),
219
+                'type'        => 'array',
220
+                'context'     => [ 'view', 'edit' ],
221
+                'items'       => [
222
+                    'type'       => 'object',
223
+                    'properties' => [
224
+                        'id'   => [
225
+                            'description' => __( 'Tag ID', 'woocommerce' ),
226
+                            'type'        => 'number',
227
+                            'context'     => [ 'view', 'edit' ],
228
+                            'readonly'    => true,
229
+                        ],
230
+                        'name' => [
231
+                            'description' => __( 'Tag name', 'woocommerce' ),
232
+                            'type'        => 'string',
233
+                            'context'     => [ 'view', 'edit' ],
234
+                            'readonly'    => true,
235
+                        ],
236
+                        'slug' => [
237
+                            'description' => __( 'Tag slug', 'woocommerce' ),
238
+                            'type'        => 'string',
239
+                            'context'     => [ 'view', 'edit' ],
240
+                            'readonly'    => true,
241
+                        ],
242
+                        'link' => [
243
+                            'description' => __( 'Tag link', 'woocommerce' ),
244
+                            'type'        => 'string',
245
+                            'context'     => [ 'view', 'edit' ],
246
+                            'readonly'    => true,
247
+                        ],
248
+                    ],
249
+                ],
250
+            ],
251
+            'attributes'          => [
252
+                'description' => __( 'List of attributes assigned to the product/variation that are visible or used for variations.', 'woocommerce' ),
253
+                'type'        => 'array',
254
+                'context'     => [ 'view', 'edit' ],
255
+                'items'       => [
256
+                    'type'       => 'object',
257
+                    'properties' => [
258
+                        'id'             => [
259
+                            'description' => __( 'The attribute ID, or 0 if the attribute is not taxonomy based.', 'woocommerce' ),
260
+                            'type'        => 'integer',
261
+                            'context'     => [ 'view', 'edit' ],
262
+                            'readonly'    => true,
263
+                        ],
264
+                        'name'           => [
265
+                            'description' => __( 'The attribute name.', 'woocommerce' ),
266
+                            'type'        => 'string',
267
+                            'context'     => [ 'view', 'edit' ],
268
+                            'readonly'    => true,
269
+                        ],
270
+                        'taxonomy'       => [
271
+                            'description' => __( 'The attribute taxonomy, or null if the attribute is not taxonomy based.', 'woocommerce' ),
272
+                            'type'        => 'string',
273
+                            'context'     => [ 'view', 'edit' ],
274
+                            'readonly'    => true,
275
+                        ],
276
+                        'has_variations' => [
277
+                            'description' => __( 'True if this attribute is used by product variations.', 'woocommerce' ),
278
+                            'type'        => 'boolean',
279
+                            'context'     => [ 'view', 'edit' ],
280
+                            'readonly'    => true,
281
+                        ],
282
+                        'terms'          => [
283
+                            'description' => __( 'List of assigned attribute terms.', 'woocommerce' ),
284
+                            'type'        => 'array',
285
+                            'context'     => [ 'view', 'edit' ],
286
+                            'items'       => [
287
+                                'type'       => 'object',
288
+                                'properties' => [
289
+                                    'id'      => [
290
+                                        'description' => __( 'The term ID, or 0 if the attribute is not a global attribute.', 'woocommerce' ),
291
+                                        'type'        => 'integer',
292
+                                        'context'     => [ 'view', 'edit' ],
293
+                                        'readonly'    => true,
294
+                                    ],
295
+                                    'name'    => [
296
+                                        'description' => __( 'The term name.', 'woocommerce' ),
297
+                                        'type'        => 'string',
298
+                                        'context'     => [ 'view', 'edit' ],
299
+                                        'readonly'    => true,
300
+                                    ],
301
+                                    'slug'    => [
302
+                                        'description' => __( 'The term slug.', 'woocommerce' ),
303
+                                        'type'        => 'string',
304
+                                        'context'     => [ 'view', 'edit' ],
305
+                                        'readonly'    => true,
306
+                                    ],
307
+                                    'default' => [
308
+                                        'description' => __( 'If this is a default attribute', 'woocommerce' ),
309
+                                        'type'        => 'boolean',
310
+                                        'context'     => [ 'view', 'edit' ],
311
+                                        'readonly'    => true,
312
+                                    ],
313
+                                ],
314
+                            ],
315
+                        ],
316
+                    ],
317
+                ],
318
+            ],
319
+            'variations'          => [
320
+                'description' => __( 'List of variation IDs, if applicable.', 'woocommerce' ),
321
+                'type'        => 'array',
322
+                'context'     => [ 'view', 'edit' ],
323
+                'items'       => [
324
+                    'type'       => 'object',
325
+                    'properties' => [
326
+                        'id'         => [
327
+                            'description' => __( 'The attribute ID, or 0 if the attribute is not taxonomy based.', 'woocommerce' ),
328
+                            'type'        => 'integer',
329
+                            'context'     => [ 'view', 'edit' ],
330
+                            'readonly'    => true,
331
+                        ],
332
+                        'attributes' => [
333
+                            'description' => __( 'List of variation attributes.', 'woocommerce' ),
334
+                            'type'        => 'array',
335
+                            'context'     => [ 'view', 'edit' ],
336
+                            'items'       => [
337
+                                'type'       => 'object',
338
+                                'properties' => [
339
+                                    'name'  => [
340
+                                        'description' => __( 'The attribute name.', 'woocommerce' ),
341
+                                        'type'        => 'string',
342
+                                        'context'     => [ 'view', 'edit' ],
343
+                                        'readonly'    => true,
344
+                                    ],
345
+                                    'value' => [
346
+                                        'description' => __( 'The assigned attribute.', 'woocommerce' ),
347
+                                        'type'        => 'string',
348
+                                        'context'     => [ 'view', 'edit' ],
349
+                                        'readonly'    => true,
350
+                                    ],
351
+                                ],
352
+                            ],
353
+                        ],
354
+                    ],
355
+                ],
356
+            ],
357
+            'has_options'         => [
358
+                'description' => __( 'Does the product have additional options before it can be added to the cart?', 'woocommerce' ),
359
+                'type'        => 'boolean',
360
+                'context'     => [ 'view', 'edit' ],
361
+                'readonly'    => true,
362
+            ],
363
+            'is_purchasable'      => [
364
+                'description' => __( 'Is the product purchasable?', 'woocommerce' ),
365
+                'type'        => 'boolean',
366
+                'context'     => [ 'view', 'edit' ],
367
+                'readonly'    => true,
368
+            ],
369
+            'is_in_stock'         => [
370
+                'description' => __( 'Is the product in stock?', 'woocommerce' ),
371
+                'type'        => 'boolean',
372
+                'context'     => [ 'view', 'edit' ],
373
+                'readonly'    => true,
374
+            ],
375
+            'is_on_backorder'     => [
376
+                'description' => __( 'Is the product stock backordered? This will also return false if backorder notifications are turned off.', 'woocommerce' ),
377
+                'type'        => 'boolean',
378
+                'context'     => [ 'view', 'edit' ],
379
+                'readonly'    => true,
380
+            ],
381
+            'low_stock_remaining' => [
382
+                'description' => __( 'Quantity left in stock if stock is low, or null if not applicable.', 'woocommerce' ),
383
+                'type'        => [ 'integer', 'null' ],
384
+                'context'     => [ 'view', 'edit' ],
385
+                'readonly'    => true,
386
+            ],
387
+            'sold_individually'   => [
388
+                'description' => __( 'If true, only one item of this product is allowed for purchase in a single order.', 'woocommerce' ),
389
+                'type'        => 'boolean',
390
+                'context'     => [ 'view', 'edit' ],
391
+                'readonly'    => true,
392
+            ],
393
+            'add_to_cart'         => [
394
+                'description' => __( 'Add to cart button parameters.', 'woocommerce' ),
395
+                'type'        => 'object',
396
+                'context'     => [ 'view', 'edit' ],
397
+                'readonly'    => true,
398
+                'properties'  => [
399
+                    'text'        => [
400
+                        'description' => __( 'Button text.', 'woocommerce' ),
401
+                        'type'        => 'string',
402
+                        'context'     => [ 'view', 'edit' ],
403
+                        'readonly'    => true,
404
+                    ],
405
+                    'description' => [
406
+                        'description' => __( 'Button description.', 'woocommerce' ),
407
+                        'type'        => 'string',
408
+                        'context'     => [ 'view', 'edit' ],
409
+                        'readonly'    => true,
410
+                    ],
411
+                    'url'         => [
412
+                        'description' => __( 'Add to cart URL.', 'woocommerce' ),
413
+                        'type'        => 'string',
414
+                        'context'     => [ 'view', 'edit' ],
415
+                        'readonly'    => true,
416
+                    ],
417
+                    'minimum'     => [
418
+                        'description' => __( 'The minimum quantity that can be added to the cart.', 'woocommerce' ),
419
+                        'type'        => 'integer',
420
+                        'context'     => [ 'view', 'edit' ],
421
+                        'readonly'    => true,
422
+                    ],
423
+                    'maximum'     => [
424
+                        'description' => __( 'The maximum quantity that can be added to the cart.', 'woocommerce' ),
425
+                        'type'        => 'integer',
426
+                        'context'     => [ 'view', 'edit' ],
427
+                        'readonly'    => true,
428
+                    ],
429
+                    'multiple_of' => [
430
+                        'description' => __( 'The amount that quantities increment by. Quantity must be an multiple of this value.', 'woocommerce' ),
431
+                        'type'        => 'integer',
432
+                        'context'     => [ 'view', 'edit' ],
433
+                        'readonly'    => true,
434
+                        'default'     => 1,
435
+                    ],
436
+                ],
437
+            ],
438
+            self::EXTENDING_KEY   => $this->get_extended_schema( self::IDENTIFIER ),
439
+        ];
440
+    }
441
+
442
+    /**
443
+     * Convert a WooCommerce product into an object suitable for the response.
444
+     *
445
+     * @param \WC_Product $product Product instance.
446
+     * @return array
447
+     */
448
+    public function get_item_response( $product ) {
449
+        return [
450
+            'id'                  => $product->get_id(),
451
+            'name'                => $this->prepare_html_response( $product->get_title() ),
452
+            'parent'              => $product->get_parent_id(),
453
+            'type'                => $product->get_type(),
454
+            'variation'           => $this->prepare_html_response( $product->is_type( 'variation' ) ? wc_get_formatted_variation( $product, true, true, false ) : '' ),
455
+            'permalink'           => $product->get_permalink(),
456
+            'sku'                 => $this->prepare_html_response( $product->get_sku() ),
457
+            'short_description'   => $this->prepare_html_response( wc_format_content( wp_kses_post( $product->get_short_description() ) ) ),
458
+            'description'         => $this->prepare_html_response( wc_format_content( wp_kses_post( $product->get_description() ) ) ),
459
+            'on_sale'             => $product->is_on_sale(),
460
+            'prices'              => (object) $this->prepare_product_price_response( $product ),
461
+            'price_html'          => $this->prepare_html_response( $product->get_price_html() ),
462
+            'average_rating'      => (string) $product->get_average_rating(),
463
+            'review_count'        => $product->get_review_count(),
464
+            'images'              => $this->get_images( $product ),
465
+            'categories'          => $this->get_term_list( $product, 'product_cat' ),
466
+            'tags'                => $this->get_term_list( $product, 'product_tag' ),
467
+            'attributes'          => $this->get_attributes( $product ),
468
+            'variations'          => $this->get_variations( $product ),
469
+            'has_options'         => $product->has_options(),
470
+            'is_purchasable'      => $product->is_purchasable(),
471
+            'is_in_stock'         => $product->is_in_stock(),
472
+            'is_on_backorder'     => 'onbackorder' === $product->get_stock_status(),
473
+            'low_stock_remaining' => $this->get_low_stock_remaining( $product ),
474
+            'sold_individually'   => $product->is_sold_individually(),
475
+            'add_to_cart'         => (object) array_merge(
476
+                [
477
+                    'text'        => $this->prepare_html_response( $product->add_to_cart_text() ),
478
+                    'description' => $this->prepare_html_response( $product->add_to_cart_description() ),
479
+                    'url'         => $this->prepare_html_response( $product->add_to_cart_url() ),
480
+                ],
481
+                ( new QuantityLimits() )->get_add_to_cart_limits( $product )
482
+            ),
483
+            self::EXTENDING_KEY   => $this->get_extended_data( self::IDENTIFIER, $product ),
484
+
485
+        ];
486
+    }
487
+
488
+    /**
489
+     * Get list of product images.
490
+     *
491
+     * @param \WC_Product $product Product instance.
492
+     * @return array
493
+     */
494
+    protected function get_images( \WC_Product $product ) {
495
+        $attachment_ids = array_merge( [ $product->get_image_id() ], $product->get_gallery_image_ids() );
496
+
497
+        return array_filter( array_map( [ $this->image_attachment_schema, 'get_item_response' ], $attachment_ids ) );
498
+    }
499
+
500
+    /**
501
+     * Gets remaining stock amount for a product.
502
+     *
503
+     * @param \WC_Product $product Product instance.
504
+     * @return integer|null
505
+     */
506
+    protected function get_remaining_stock( \WC_Product $product ) {
507
+        if ( is_null( $product->get_stock_quantity() ) ) {
508
+            return null;
509
+        }
510
+        return $product->get_stock_quantity();
511
+    }
512
+
513
+    /**
514
+     * If a product has low stock, return the remaining stock amount for display.
515
+     *
516
+     * @param \WC_Product $product Product instance.
517
+     * @return integer|null
518
+     */
519
+    protected function get_low_stock_remaining( \WC_Product $product ) {
520
+        $remaining_stock = $this->get_remaining_stock( $product );
521
+        $stock_format    = get_option( 'woocommerce_stock_format' );
522
+
523
+        // Don't show the low stock badge if the settings doesn't allow it.
524
+        if ( 'no_amount' === $stock_format ) {
525
+            return null;
526
+        }
527
+
528
+        // Show the low stock badge if the remaining stock is below or equal to the threshold.
529
+        if ( ! is_null( $remaining_stock ) && $remaining_stock <= wc_get_low_stock_amount( $product ) ) {
530
+            return max( $remaining_stock, 0 );
531
+        }
532
+
533
+        return null;
534
+    }
535
+
536
+    /**
537
+     * Returns true if the given attribute is valid.
538
+     *
539
+     * @param mixed $attribute Object or variable to check.
540
+     * @return boolean
541
+     */
542
+    protected function filter_valid_attribute( $attribute ) {
543
+        return is_a( $attribute, '\WC_Product_Attribute' );
544
+    }
545
+
546
+    /**
547
+     * Returns true if the given attribute is valid and used for variations.
548
+     *
549
+     * @param mixed $attribute Object or variable to check.
550
+     * @return boolean
551
+     */
552
+    protected function filter_variation_attribute( $attribute ) {
553
+        return $this->filter_valid_attribute( $attribute ) && $attribute->get_variation();
554
+    }
555
+
556
+    /**
557
+     * Get variation IDs and attributes from the DB.
558
+     *
559
+     * @param \WC_Product $product Product instance.
560
+     * @returns array
561
+     */
562
+    protected function get_variations( \WC_Product $product ) {
563
+        $variation_ids = $product->is_type( 'variable' ) ? $product->get_visible_children() : [];
564
+
565
+        if ( ! count( $variation_ids ) ) {
566
+            return [];
567
+        }
568
+
569
+        /**
570
+         * Gets default variation data which applies to all of this products variations.
571
+         */
572
+        $attributes                  = array_filter( $product->get_attributes(), [ $this, 'filter_variation_attribute' ] );
573
+        $default_variation_meta_data = array_reduce(
574
+            $attributes,
575
+            function( $defaults, $attribute ) use ( $product ) {
576
+                $meta_key              = wc_variation_attribute_name( $attribute->get_name() );
577
+                $defaults[ $meta_key ] = [
578
+                    'name'  => wc_attribute_label( $attribute->get_name(), $product ),
579
+                    'value' => null,
580
+                ];
581
+                return $defaults;
582
+            },
583
+            []
584
+        );
585
+        $default_variation_meta_keys = array_keys( $default_variation_meta_data );
586
+
587
+        /**
588
+         * Gets individual variation data from the database, using cache where possible.
589
+         */
590
+        $cache_group   = 'product_variation_meta_data';
591
+        $cache_value   = wp_cache_get( $product->get_id(), $cache_group );
592
+        $last_modified = get_the_modified_date( 'U', $product->get_id() );
593
+
594
+        if ( false === $cache_value || $last_modified !== $cache_value['last_modified'] ) {
595
+            global $wpdb;
596
+            // phpcs:disable WordPress.DB.PreparedSQL.NotPrepared
597
+            $variation_meta_data = $wpdb->get_results(
598
+                "
599 599
 				SELECT post_id as variation_id, meta_key as attribute_key, meta_value as attribute_value
600 600
 				FROM {$wpdb->postmeta}
601 601
 				WHERE post_id IN (" . implode( ',', array_map( 'esc_sql', $variation_ids ) ) . ")
602 602
 				AND meta_key IN ('" . implode( "','", array_map( 'esc_sql', $default_variation_meta_keys ) ) . "')
603 603
 			"
604
-			);
605
-			// phpcs:enable
606
-
607
-			wp_cache_set(
608
-				$product->get_id(),
609
-				[
610
-					'last_modified' => $last_modified,
611
-					'data'          => $variation_meta_data,
612
-				],
613
-				$cache_group
614
-			);
615
-		} else {
616
-			$variation_meta_data = $cache_value['data'];
617
-		}
618
-
619
-		/**
620
-		 * Merges and formats default variation data with individual variation data.
621
-		 */
622
-		$attributes_by_variation = array_reduce(
623
-			$variation_meta_data,
624
-			function( $values, $data ) use ( $default_variation_meta_keys ) {
625
-				// The query above only includes the keys of $default_variation_meta_data so we know all of the attributes
626
-				// being processed here apply to this product. However, we need an additional check here because the
627
-				// cache may have been primed elsewhere and include keys from other products.
628
-				// @see AbstractProductGrid::prime_product_variations.
629
-				if ( in_array( $data->attribute_key, $default_variation_meta_keys, true ) ) {
630
-					$values[ $data->variation_id ][ $data->attribute_key ] = $data->attribute_value;
631
-				}
632
-				return $values;
633
-			},
634
-			array_fill_keys( $variation_ids, [] )
635
-		);
636
-
637
-		$variations = [];
638
-
639
-		foreach ( $variation_ids as $variation_id ) {
640
-			$attribute_data = $default_variation_meta_data;
641
-
642
-			foreach ( $attributes_by_variation[ $variation_id ] as $meta_key => $meta_value ) {
643
-				if ( '' !== $meta_value ) {
644
-					$attribute_data[ $meta_key ]['value'] = $meta_value;
645
-				}
646
-			}
647
-
648
-			$variations[] = (object) [
649
-				'id'         => $variation_id,
650
-				'attributes' => array_values( $attribute_data ),
651
-			];
652
-		}
653
-
654
-		return $variations;
655
-	}
656
-
657
-	/**
658
-	 * Get list of product attributes and attribute terms.
659
-	 *
660
-	 * @param \WC_Product $product Product instance.
661
-	 * @return array
662
-	 */
663
-	protected function get_attributes( \WC_Product $product ) {
664
-		$attributes         = array_filter( $product->get_attributes(), [ $this, 'filter_valid_attribute' ] );
665
-		$default_attributes = $product->get_default_attributes();
666
-		$return             = [];
667
-
668
-		foreach ( $attributes as $attribute_slug => $attribute ) {
669
-			// Only visible or variation attributes will be exposed by this API.
670
-			if ( ! $attribute->get_visible() && ! $attribute->get_variation() ) {
671
-				continue;
672
-			}
673
-
674
-			$terms = $attribute->is_taxonomy() ? array_map( [ $this, 'prepare_product_attribute_taxonomy_value' ], $attribute->get_terms() ) : array_map( [ $this, 'prepare_product_attribute_value' ], $attribute->get_options() );
675
-			// Custom attribute names are sanitized to be the array keys.
676
-			// So when we do the array_key_exists check below we also need to sanitize the attribute names.
677
-
678
-			$sanitized_attribute_name = sanitize_key( $attribute->get_name() );
679
-
680
-			if ( array_key_exists( $sanitized_attribute_name, $default_attributes ) ) {
681
-				foreach ( $terms as $term ) {
682
-					$term->default = $term->slug === $default_attributes[ $sanitized_attribute_name ];
683
-				}
684
-			}
685
-
686
-			$return[] = (object) [
687
-				'id'             => $attribute->get_id(),
688
-				'name'           => wc_attribute_label( $attribute->get_name(), $product ),
689
-				'taxonomy'       => $attribute->is_taxonomy() ? $attribute->get_name() : null,
690
-				'has_variations' => true === $attribute->get_variation(),
691
-				'terms'          => $terms,
692
-			];
693
-		}
694
-
695
-		return $return;
696
-	}
697
-
698
-	/**
699
-	 * Prepare an attribute term for the response.
700
-	 *
701
-	 * @param \WP_Term $term Term object.
702
-	 * @return object
703
-	 */
704
-	protected function prepare_product_attribute_taxonomy_value( \WP_Term $term ) {
705
-		return $this->prepare_product_attribute_value( $term->name, $term->term_id, $term->slug );
706
-	}
707
-
708
-	/**
709
-	 * Prepare an attribute term for the response.
710
-	 *
711
-	 * @param string $name Attribute term name.
712
-	 * @param int    $id Attribute term ID.
713
-	 * @param string $slug Attribute term slug.
714
-	 * @return object
715
-	 */
716
-	protected function prepare_product_attribute_value( $name, $id = 0, $slug = '' ) {
717
-		return (object) [
718
-			'id'   => (int) $id,
719
-			'name' => $name,
720
-			'slug' => $slug ? $slug : $name,
721
-		];
722
-	}
723
-
724
-	/**
725
-	 * Get an array of pricing data.
726
-	 *
727
-	 * @param \WC_Product $product Product instance.
728
-	 * @param string      $tax_display_mode If returned prices are incl or excl of tax.
729
-	 * @return array
730
-	 */
731
-	protected function prepare_product_price_response( \WC_Product $product, $tax_display_mode = '' ) {
732
-		$prices           = [];
733
-		$tax_display_mode = $this->get_tax_display_mode( $tax_display_mode );
734
-		$price_function   = $this->get_price_function_from_tax_display_mode( $tax_display_mode );
735
-
736
-		// If we have a variable product, get the price from the variations (this will use the min value).
737
-		if ( $product->is_type( 'variable' ) ) {
738
-			$regular_price = $product->get_variation_regular_price();
739
-			$sale_price    = $product->get_variation_sale_price();
740
-		} else {
741
-			$regular_price = $product->get_regular_price();
742
-			$sale_price    = $product->get_sale_price();
743
-		}
744
-
745
-		$prices['price']         = $this->prepare_money_response( $price_function( $product ), wc_get_price_decimals() );
746
-		$prices['regular_price'] = $this->prepare_money_response( $price_function( $product, [ 'price' => $regular_price ] ), wc_get_price_decimals() );
747
-		$prices['sale_price']    = $this->prepare_money_response( $price_function( $product, [ 'price' => $sale_price ] ), wc_get_price_decimals() );
748
-		$prices['price_range']   = $this->get_price_range( $product, $tax_display_mode );
749
-
750
-		return $this->prepare_currency_response( $prices );
751
-	}
752
-
753
-	/**
754
-	 * WooCommerce can return prices including or excluding tax; choose the correct method based on tax display mode.
755
-	 *
756
-	 * @param string $tax_display_mode Provided tax display mode.
757
-	 * @return string Valid tax display mode.
758
-	 */
759
-	protected function get_tax_display_mode( $tax_display_mode = '' ) {
760
-		return in_array( $tax_display_mode, [ 'incl', 'excl' ], true ) ? $tax_display_mode : get_option( 'woocommerce_tax_display_shop' );
761
-	}
762
-
763
-	/**
764
-	 * WooCommerce can return prices including or excluding tax; choose the correct method based on tax display mode.
765
-	 *
766
-	 * @param string $tax_display_mode If returned prices are incl or excl of tax.
767
-	 * @return string Function name.
768
-	 */
769
-	protected function get_price_function_from_tax_display_mode( $tax_display_mode ) {
770
-		return 'incl' === $tax_display_mode ? 'wc_get_price_including_tax' : 'wc_get_price_excluding_tax';
771
-	}
772
-
773
-	/**
774
-	 * Get price range from certain product types.
775
-	 *
776
-	 * @param \WC_Product $product Product instance.
777
-	 * @param string      $tax_display_mode If returned prices are incl or excl of tax.
778
-	 * @return object|null
779
-	 */
780
-	protected function get_price_range( \WC_Product $product, $tax_display_mode = '' ) {
781
-		$tax_display_mode = $this->get_tax_display_mode( $tax_display_mode );
782
-
783
-		if ( $product->is_type( 'variable' ) ) {
784
-			$prices = $product->get_variation_prices( true );
785
-
786
-			if ( ! empty( $prices['price'] ) && ( min( $prices['price'] ) !== max( $prices['price'] ) ) ) {
787
-				return (object) [
788
-					'min_amount' => $this->prepare_money_response( min( $prices['price'] ), wc_get_price_decimals() ),
789
-					'max_amount' => $this->prepare_money_response( max( $prices['price'] ), wc_get_price_decimals() ),
790
-				];
791
-			}
792
-		}
793
-
794
-		if ( $product->is_type( 'grouped' ) ) {
795
-			$children       = array_filter( array_map( 'wc_get_product', $product->get_children() ), 'wc_products_array_filter_visible_grouped' );
796
-			$price_function = 'incl' === $tax_display_mode ? 'wc_get_price_including_tax' : 'wc_get_price_excluding_tax';
797
-
798
-			foreach ( $children as $child ) {
799
-				if ( '' !== $child->get_price() ) {
800
-					$child_prices[] = $price_function( $child );
801
-				}
802
-			}
803
-
804
-			if ( ! empty( $child_prices ) ) {
805
-				return (object) [
806
-					'min_amount' => $this->prepare_money_response( min( $child_prices ), wc_get_price_decimals() ),
807
-					'max_amount' => $this->prepare_money_response( max( $child_prices ), wc_get_price_decimals() ),
808
-				];
809
-			}
810
-		}
811
-
812
-		return null;
813
-	}
814
-
815
-	/**
816
-	 * Returns a list of terms assigned to the product.
817
-	 *
818
-	 * @param \WC_Product $product Product object.
819
-	 * @param string      $taxonomy Taxonomy name.
820
-	 * @return array Array of terms (id, name, slug).
821
-	 */
822
-	protected function get_term_list( \WC_Product $product, $taxonomy = '' ) {
823
-		if ( ! $taxonomy ) {
824
-			return [];
825
-		}
826
-
827
-		$terms = get_the_terms( $product->get_id(), $taxonomy );
828
-
829
-		if ( ! $terms || is_wp_error( $terms ) ) {
830
-			return [];
831
-		}
832
-
833
-		$return           = [];
834
-		$default_category = (int) get_option( 'default_product_cat', 0 );
835
-
836
-		foreach ( $terms as $term ) {
837
-			$link = get_term_link( $term, $taxonomy );
838
-
839
-			if ( is_wp_error( $link ) ) {
840
-				continue;
841
-			}
842
-
843
-			if ( $term->term_id === $default_category ) {
844
-				continue;
845
-			}
846
-
847
-			$return[] = (object) [
848
-				'id'   => $term->term_id,
849
-				'name' => $term->name,
850
-				'slug' => $term->slug,
851
-				'link' => $link,
852
-			];
853
-		}
854
-
855
-		return $return;
856
-	}
604
+            );
605
+            // phpcs:enable
606
+
607
+            wp_cache_set(
608
+                $product->get_id(),
609
+                [
610
+                    'last_modified' => $last_modified,
611
+                    'data'          => $variation_meta_data,
612
+                ],
613
+                $cache_group
614
+            );
615
+        } else {
616
+            $variation_meta_data = $cache_value['data'];
617
+        }
618
+
619
+        /**
620
+         * Merges and formats default variation data with individual variation data.
621
+         */
622
+        $attributes_by_variation = array_reduce(
623
+            $variation_meta_data,
624
+            function( $values, $data ) use ( $default_variation_meta_keys ) {
625
+                // The query above only includes the keys of $default_variation_meta_data so we know all of the attributes
626
+                // being processed here apply to this product. However, we need an additional check here because the
627
+                // cache may have been primed elsewhere and include keys from other products.
628
+                // @see AbstractProductGrid::prime_product_variations.
629
+                if ( in_array( $data->attribute_key, $default_variation_meta_keys, true ) ) {
630
+                    $values[ $data->variation_id ][ $data->attribute_key ] = $data->attribute_value;
631
+                }
632
+                return $values;
633
+            },
634
+            array_fill_keys( $variation_ids, [] )
635
+        );
636
+
637
+        $variations = [];
638
+
639
+        foreach ( $variation_ids as $variation_id ) {
640
+            $attribute_data = $default_variation_meta_data;
641
+
642
+            foreach ( $attributes_by_variation[ $variation_id ] as $meta_key => $meta_value ) {
643
+                if ( '' !== $meta_value ) {
644
+                    $attribute_data[ $meta_key ]['value'] = $meta_value;
645
+                }
646
+            }
647
+
648
+            $variations[] = (object) [
649
+                'id'         => $variation_id,
650
+                'attributes' => array_values( $attribute_data ),
651
+            ];
652
+        }
653
+
654
+        return $variations;
655
+    }
656
+
657
+    /**
658
+     * Get list of product attributes and attribute terms.
659
+     *
660
+     * @param \WC_Product $product Product instance.
661
+     * @return array
662
+     */
663
+    protected function get_attributes( \WC_Product $product ) {
664
+        $attributes         = array_filter( $product->get_attributes(), [ $this, 'filter_valid_attribute' ] );
665
+        $default_attributes = $product->get_default_attributes();
666
+        $return             = [];
667
+
668
+        foreach ( $attributes as $attribute_slug => $attribute ) {
669
+            // Only visible or variation attributes will be exposed by this API.
670
+            if ( ! $attribute->get_visible() && ! $attribute->get_variation() ) {
671
+                continue;
672
+            }
673
+
674
+            $terms = $attribute->is_taxonomy() ? array_map( [ $this, 'prepare_product_attribute_taxonomy_value' ], $attribute->get_terms() ) : array_map( [ $this, 'prepare_product_attribute_value' ], $attribute->get_options() );
675
+            // Custom attribute names are sanitized to be the array keys.
676
+            // So when we do the array_key_exists check below we also need to sanitize the attribute names.
677
+
678
+            $sanitized_attribute_name = sanitize_key( $attribute->get_name() );
679
+
680
+            if ( array_key_exists( $sanitized_attribute_name, $default_attributes ) ) {
681
+                foreach ( $terms as $term ) {
682
+                    $term->default = $term->slug === $default_attributes[ $sanitized_attribute_name ];
683
+                }
684
+            }
685
+
686
+            $return[] = (object) [
687
+                'id'             => $attribute->get_id(),
688
+                'name'           => wc_attribute_label( $attribute->get_name(), $product ),
689
+                'taxonomy'       => $attribute->is_taxonomy() ? $attribute->get_name() : null,
690
+                'has_variations' => true === $attribute->get_variation(),
691
+                'terms'          => $terms,
692
+            ];
693
+        }
694
+
695
+        return $return;
696
+    }
697
+
698
+    /**
699
+     * Prepare an attribute term for the response.
700
+     *
701
+     * @param \WP_Term $term Term object.
702
+     * @return object
703
+     */
704
+    protected function prepare_product_attribute_taxonomy_value( \WP_Term $term ) {
705
+        return $this->prepare_product_attribute_value( $term->name, $term->term_id, $term->slug );
706
+    }
707
+
708
+    /**
709
+     * Prepare an attribute term for the response.
710
+     *
711
+     * @param string $name Attribute term name.
712
+     * @param int    $id Attribute term ID.
713
+     * @param string $slug Attribute term slug.
714
+     * @return object
715
+     */
716
+    protected function prepare_product_attribute_value( $name, $id = 0, $slug = '' ) {
717
+        return (object) [
718
+            'id'   => (int) $id,
719
+            'name' => $name,
720
+            'slug' => $slug ? $slug : $name,
721
+        ];
722
+    }
723
+
724
+    /**
725
+     * Get an array of pricing data.
726
+     *
727
+     * @param \WC_Product $product Product instance.
728
+     * @param string      $tax_display_mode If returned prices are incl or excl of tax.
729
+     * @return array
730
+     */
731
+    protected function prepare_product_price_response( \WC_Product $product, $tax_display_mode = '' ) {
732
+        $prices           = [];
733
+        $tax_display_mode = $this->get_tax_display_mode( $tax_display_mode );
734
+        $price_function   = $this->get_price_function_from_tax_display_mode( $tax_display_mode );
735
+
736
+        // If we have a variable product, get the price from the variations (this will use the min value).
737
+        if ( $product->is_type( 'variable' ) ) {
738
+            $regular_price = $product->get_variation_regular_price();
739
+            $sale_price    = $product->get_variation_sale_price();
740
+        } else {
741
+            $regular_price = $product->get_regular_price();
742
+            $sale_price    = $product->get_sale_price();
743
+        }
744
+
745
+        $prices['price']         = $this->prepare_money_response( $price_function( $product ), wc_get_price_decimals() );
746
+        $prices['regular_price'] = $this->prepare_money_response( $price_function( $product, [ 'price' => $regular_price ] ), wc_get_price_decimals() );
747
+        $prices['sale_price']    = $this->prepare_money_response( $price_function( $product, [ 'price' => $sale_price ] ), wc_get_price_decimals() );
748
+        $prices['price_range']   = $this->get_price_range( $product, $tax_display_mode );
749
+
750
+        return $this->prepare_currency_response( $prices );
751
+    }
752
+
753
+    /**
754
+     * WooCommerce can return prices including or excluding tax; choose the correct method based on tax display mode.
755
+     *
756
+     * @param string $tax_display_mode Provided tax display mode.
757
+     * @return string Valid tax display mode.
758
+     */
759
+    protected function get_tax_display_mode( $tax_display_mode = '' ) {
760
+        return in_array( $tax_display_mode, [ 'incl', 'excl' ], true ) ? $tax_display_mode : get_option( 'woocommerce_tax_display_shop' );
761
+    }
762
+
763
+    /**
764
+     * WooCommerce can return prices including or excluding tax; choose the correct method based on tax display mode.
765
+     *
766
+     * @param string $tax_display_mode If returned prices are incl or excl of tax.
767
+     * @return string Function name.
768
+     */
769
+    protected function get_price_function_from_tax_display_mode( $tax_display_mode ) {
770
+        return 'incl' === $tax_display_mode ? 'wc_get_price_including_tax' : 'wc_get_price_excluding_tax';
771
+    }
772
+
773
+    /**
774
+     * Get price range from certain product types.
775
+     *
776
+     * @param \WC_Product $product Product instance.
777
+     * @param string      $tax_display_mode If returned prices are incl or excl of tax.
778
+     * @return object|null
779
+     */
780
+    protected function get_price_range( \WC_Product $product, $tax_display_mode = '' ) {
781
+        $tax_display_mode = $this->get_tax_display_mode( $tax_display_mode );
782
+
783
+        if ( $product->is_type( 'variable' ) ) {
784
+            $prices = $product->get_variation_prices( true );
785
+
786
+            if ( ! empty( $prices['price'] ) && ( min( $prices['price'] ) !== max( $prices['price'] ) ) ) {
787
+                return (object) [
788
+                    'min_amount' => $this->prepare_money_response( min( $prices['price'] ), wc_get_price_decimals() ),
789
+                    'max_amount' => $this->prepare_money_response( max( $prices['price'] ), wc_get_price_decimals() ),
790
+                ];
791
+            }
792
+        }
793
+
794
+        if ( $product->is_type( 'grouped' ) ) {
795
+            $children       = array_filter( array_map( 'wc_get_product', $product->get_children() ), 'wc_products_array_filter_visible_grouped' );
796
+            $price_function = 'incl' === $tax_display_mode ? 'wc_get_price_including_tax' : 'wc_get_price_excluding_tax';
797
+
798
+            foreach ( $children as $child ) {
799
+                if ( '' !== $child->get_price() ) {
800
+                    $child_prices[] = $price_function( $child );
801
+                }
802
+            }
803
+
804
+            if ( ! empty( $child_prices ) ) {
805
+                return (object) [
806
+                    'min_amount' => $this->prepare_money_response( min( $child_prices ), wc_get_price_decimals() ),
807
+                    'max_amount' => $this->prepare_money_response( max( $child_prices ), wc_get_price_decimals() ),
808
+                ];
809
+            }
810
+        }
811
+
812
+        return null;
813
+    }
814
+
815
+    /**
816
+     * Returns a list of terms assigned to the product.
817
+     *
818
+     * @param \WC_Product $product Product object.
819
+     * @param string      $taxonomy Taxonomy name.
820
+     * @return array Array of terms (id, name, slug).
821
+     */
822
+    protected function get_term_list( \WC_Product $product, $taxonomy = '' ) {
823
+        if ( ! $taxonomy ) {
824
+            return [];
825
+        }
826
+
827
+        $terms = get_the_terms( $product->get_id(), $taxonomy );
828
+
829
+        if ( ! $terms || is_wp_error( $terms ) ) {
830
+            return [];
831
+        }
832
+
833
+        $return           = [];
834
+        $default_category = (int) get_option( 'default_product_cat', 0 );
835
+
836
+        foreach ( $terms as $term ) {
837
+            $link = get_term_link( $term, $taxonomy );
838
+
839
+            if ( is_wp_error( $link ) ) {
840
+                continue;
841
+            }
842
+
843
+            if ( $term->term_id === $default_category ) {
844
+                continue;
845
+            }
846
+
847
+            $return[] = (object) [
848
+                'id'   => $term->term_id,
849
+                'name' => $term->name,
850
+                'slug' => $term->slug,
851
+                'link' => $link,
852
+            ];
853
+        }
854
+
855
+        return $return;
856
+    }
857 857
 }
Please login to merge, or discard this patch.
Spacing   +230 added lines, -230 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,103 +49,103 @@  discard block
 block discarded – undo
49 49
 	public function get_properties() {
50 50
 		return [
51 51
 			'id'                  => [
52
-				'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
52
+				'description' => __('Unique identifier for the resource.', 'woocommerce'),
53 53
 				'type'        => 'integer',
54
-				'context'     => [ 'view', 'edit' ],
54
+				'context'     => ['view', 'edit'],
55 55
 				'readonly'    => true,
56 56
 			],
57 57
 			'name'                => [
58
-				'description' => __( 'Product name.', 'woocommerce' ),
58
+				'description' => __('Product name.', 'woocommerce'),
59 59
 				'type'        => 'string',
60
-				'context'     => [ 'view', 'edit' ],
60
+				'context'     => ['view', 'edit'],
61 61
 			],
62 62
 			'parent'              => [
63
-				'description' => __( 'ID of the parent product, if applicable.', 'woocommerce' ),
63
+				'description' => __('ID of the parent product, if applicable.', 'woocommerce'),
64 64
 				'type'        => 'integer',
65
-				'context'     => [ 'view', 'edit' ],
65
+				'context'     => ['view', 'edit'],
66 66
 				'readonly'    => true,
67 67
 			],
68 68
 			'type'                => [
69
-				'description' => __( 'Product type.', 'woocommerce' ),
69
+				'description' => __('Product type.', 'woocommerce'),
70 70
 				'type'        => 'string',
71
-				'context'     => [ 'view', 'edit' ],
71
+				'context'     => ['view', 'edit'],
72 72
 				'readonly'    => true,
73 73
 			],
74 74
 			'variation'           => [
75
-				'description' => __( 'Product variation attributes, if applicable.', 'woocommerce' ),
75
+				'description' => __('Product variation attributes, if applicable.', 'woocommerce'),
76 76
 				'type'        => 'string',
77
-				'context'     => [ 'view', 'edit' ],
77
+				'context'     => ['view', 'edit'],
78 78
 			],
79 79
 			'permalink'           => [
80
-				'description' => __( 'Product URL.', 'woocommerce' ),
80
+				'description' => __('Product URL.', 'woocommerce'),
81 81
 				'type'        => 'string',
82 82
 				'format'      => 'uri',
83
-				'context'     => [ 'view', 'edit' ],
83
+				'context'     => ['view', 'edit'],
84 84
 				'readonly'    => true,
85 85
 			],
86 86
 			'short_description'   => [
87
-				'description' => __( 'Product short description in HTML format.', 'woocommerce' ),
87
+				'description' => __('Product short description in HTML format.', 'woocommerce'),
88 88
 				'type'        => 'string',
89
-				'context'     => [ 'view', 'edit' ],
89
+				'context'     => ['view', 'edit'],
90 90
 			],
91 91
 			'description'         => [
92
-				'description' => __( 'Product full description in HTML format.', 'woocommerce' ),
92
+				'description' => __('Product full description in HTML format.', 'woocommerce'),
93 93
 				'type'        => 'string',
94
-				'context'     => [ 'view', 'edit' ],
94
+				'context'     => ['view', 'edit'],
95 95
 			],
96 96
 			'on_sale'             => [
97
-				'description' => __( 'Is the product on sale?', 'woocommerce' ),
97
+				'description' => __('Is the product on sale?', 'woocommerce'),
98 98
 				'type'        => 'boolean',
99
-				'context'     => [ 'view', 'edit' ],
99
+				'context'     => ['view', 'edit'],
100 100
 				'readonly'    => true,
101 101
 			],
102 102
 			'sku'                 => [
103
-				'description' => __( 'Unique identifier.', 'woocommerce' ),
103
+				'description' => __('Unique identifier.', 'woocommerce'),
104 104
 				'type'        => 'string',
105
-				'context'     => [ 'view', 'edit' ],
105
+				'context'     => ['view', 'edit'],
106 106
 			],
107 107
 			'prices'              => [
108
-				'description' => __( 'Price data provided using the smallest unit of the currency.', 'woocommerce' ),
108
+				'description' => __('Price data provided using the smallest unit of the currency.', 'woocommerce'),
109 109
 				'type'        => 'object',
110
-				'context'     => [ 'view', 'edit' ],
110
+				'context'     => ['view', 'edit'],
111 111
 				'readonly'    => true,
112 112
 				'properties'  => array_merge(
113 113
 					$this->get_store_currency_properties(),
114 114
 					[
115 115
 						'price'         => [
116
-							'description' => __( 'Current product price.', 'woocommerce' ),
116
+							'description' => __('Current product price.', 'woocommerce'),
117 117
 							'type'        => 'string',
118
-							'context'     => [ 'view', 'edit' ],
118
+							'context'     => ['view', 'edit'],
119 119
 							'readonly'    => true,
120 120
 						],
121 121
 						'regular_price' => [
122
-							'description' => __( 'Regular product price.', 'woocommerce' ),
122
+							'description' => __('Regular product price.', 'woocommerce'),
123 123
 							'type'        => 'string',
124
-							'context'     => [ 'view', 'edit' ],
124
+							'context'     => ['view', 'edit'],
125 125
 							'readonly'    => true,
126 126
 						],
127 127
 						'sale_price'    => [
128
-							'description' => __( 'Sale product price, if applicable.', 'woocommerce' ),
128
+							'description' => __('Sale product price, if applicable.', 'woocommerce'),
129 129
 							'type'        => 'string',
130
-							'context'     => [ 'view', 'edit' ],
130
+							'context'     => ['view', 'edit'],
131 131
 							'readonly'    => true,
132 132
 						],
133 133
 						'price_range'   => [
134
-							'description' => __( 'Price range, if applicable.', 'woocommerce' ),
135
-							'type'        => [ 'object', 'null' ],
136
-							'context'     => [ 'view', 'edit' ],
134
+							'description' => __('Price range, if applicable.', 'woocommerce'),
135
+							'type'        => ['object', 'null'],
136
+							'context'     => ['view', 'edit'],
137 137
 							'readonly'    => true,
138 138
 							'properties'  => [
139 139
 								'min_amount' => [
140
-									'description' => __( 'Price amount.', 'woocommerce' ),
140
+									'description' => __('Price amount.', 'woocommerce'),
141 141
 									'type'        => 'string',
142
-									'context'     => [ 'view', 'edit' ],
142
+									'context'     => ['view', 'edit'],
143 143
 									'readonly'    => true,
144 144
 								],
145 145
 								'max_amount' => [
146
-									'description' => __( 'Price amount.', 'woocommerce' ),
146
+									'description' => __('Price amount.', 'woocommerce'),
147 147
 									'type'        => 'string',
148
-									'context'     => [ 'view', 'edit' ],
148
+									'context'     => ['view', 'edit'],
149 149
 									'readonly'    => true,
150 150
 								],
151 151
 							],
@@ -154,160 +154,160 @@  discard block
 block discarded – undo
154 154
 				),
155 155
 			],
156 156
 			'price_html'          => array(
157
-				'description' => __( 'Price string formatted as HTML.', 'woocommerce' ),
157
+				'description' => __('Price string formatted as HTML.', 'woocommerce'),
158 158
 				'type'        => 'string',
159
-				'context'     => array( 'view', 'edit' ),
159
+				'context'     => array('view', 'edit'),
160 160
 				'readonly'    => true,
161 161
 			),
162 162
 			'average_rating'      => [
163
-				'description' => __( 'Reviews average rating.', 'woocommerce' ),
163
+				'description' => __('Reviews average rating.', 'woocommerce'),
164 164
 				'type'        => 'string',
165
-				'context'     => [ 'view', 'edit' ],
165
+				'context'     => ['view', 'edit'],
166 166
 				'readonly'    => true,
167 167
 			],
168 168
 			'review_count'        => [
169
-				'description' => __( 'Amount of reviews that the product has.', 'woocommerce' ),
169
+				'description' => __('Amount of reviews that the product has.', 'woocommerce'),
170 170
 				'type'        => 'integer',
171
-				'context'     => [ 'view', 'edit' ],
171
+				'context'     => ['view', 'edit'],
172 172
 				'readonly'    => true,
173 173
 			],
174 174
 			'images'              => [
175
-				'description' => __( 'List of images.', 'woocommerce' ),
175
+				'description' => __('List of images.', 'woocommerce'),
176 176
 				'type'        => 'array',
177
-				'context'     => [ 'view', 'edit' ],
177
+				'context'     => ['view', 'edit'],
178 178
 				'items'       => [
179 179
 					'type'       => 'object',
180 180
 					'properties' => $this->image_attachment_schema->get_properties(),
181 181
 				],
182 182
 			],
183 183
 			'categories'          => [
184
-				'description' => __( 'List of categories, if applicable.', 'woocommerce' ),
184
+				'description' => __('List of categories, if applicable.', 'woocommerce'),
185 185
 				'type'        => 'array',
186
-				'context'     => [ 'view', 'edit' ],
186
+				'context'     => ['view', 'edit'],
187 187
 				'items'       => [
188 188
 					'type'       => 'object',
189 189
 					'properties' => [
190 190
 						'id'   => [
191
-							'description' => __( 'Category ID', 'woocommerce' ),
191
+							'description' => __('Category ID', 'woocommerce'),
192 192
 							'type'        => 'number',
193
-							'context'     => [ 'view', 'edit' ],
193
+							'context'     => ['view', 'edit'],
194 194
 							'readonly'    => true,
195 195
 						],
196 196
 						'name' => [
197
-							'description' => __( 'Category name', 'woocommerce' ),
197
+							'description' => __('Category name', 'woocommerce'),
198 198
 							'type'        => 'string',
199
-							'context'     => [ 'view', 'edit' ],
199
+							'context'     => ['view', 'edit'],
200 200
 							'readonly'    => true,
201 201
 						],
202 202
 						'slug' => [
203
-							'description' => __( 'Category slug', 'woocommerce' ),
203
+							'description' => __('Category slug', 'woocommerce'),
204 204
 							'type'        => 'string',
205
-							'context'     => [ 'view', 'edit' ],
205
+							'context'     => ['view', 'edit'],
206 206
 							'readonly'    => true,
207 207
 						],
208 208
 						'link' => [
209
-							'description' => __( 'Category link', 'woocommerce' ),
209
+							'description' => __('Category link', 'woocommerce'),
210 210
 							'type'        => 'string',
211
-							'context'     => [ 'view', 'edit' ],
211
+							'context'     => ['view', 'edit'],
212 212
 							'readonly'    => true,
213 213
 						],
214 214
 					],
215 215
 				],
216 216
 			],
217 217
 			'tags'                => [
218
-				'description' => __( 'List of tags, if applicable.', 'woocommerce' ),
218
+				'description' => __('List of tags, if applicable.', 'woocommerce'),
219 219
 				'type'        => 'array',
220
-				'context'     => [ 'view', 'edit' ],
220
+				'context'     => ['view', 'edit'],
221 221
 				'items'       => [
222 222
 					'type'       => 'object',
223 223
 					'properties' => [
224 224
 						'id'   => [
225
-							'description' => __( 'Tag ID', 'woocommerce' ),
225
+							'description' => __('Tag ID', 'woocommerce'),
226 226
 							'type'        => 'number',
227
-							'context'     => [ 'view', 'edit' ],
227
+							'context'     => ['view', 'edit'],
228 228
 							'readonly'    => true,
229 229
 						],
230 230
 						'name' => [
231
-							'description' => __( 'Tag name', 'woocommerce' ),
231
+							'description' => __('Tag name', 'woocommerce'),
232 232
 							'type'        => 'string',
233
-							'context'     => [ 'view', 'edit' ],
233
+							'context'     => ['view', 'edit'],
234 234
 							'readonly'    => true,
235 235
 						],
236 236
 						'slug' => [
237
-							'description' => __( 'Tag slug', 'woocommerce' ),
237
+							'description' => __('Tag slug', 'woocommerce'),
238 238
 							'type'        => 'string',
239
-							'context'     => [ 'view', 'edit' ],
239
+							'context'     => ['view', 'edit'],
240 240
 							'readonly'    => true,
241 241
 						],
242 242
 						'link' => [
243
-							'description' => __( 'Tag link', 'woocommerce' ),
243
+							'description' => __('Tag link', 'woocommerce'),
244 244
 							'type'        => 'string',
245
-							'context'     => [ 'view', 'edit' ],
245
+							'context'     => ['view', 'edit'],
246 246
 							'readonly'    => true,
247 247
 						],
248 248
 					],
249 249
 				],
250 250
 			],
251 251
 			'attributes'          => [
252
-				'description' => __( 'List of attributes assigned to the product/variation that are visible or used for variations.', 'woocommerce' ),
252
+				'description' => __('List of attributes assigned to the product/variation that are visible or used for variations.', 'woocommerce'),
253 253
 				'type'        => 'array',
254
-				'context'     => [ 'view', 'edit' ],
254
+				'context'     => ['view', 'edit'],
255 255
 				'items'       => [
256 256
 					'type'       => 'object',
257 257
 					'properties' => [
258 258
 						'id'             => [
259
-							'description' => __( 'The attribute ID, or 0 if the attribute is not taxonomy based.', 'woocommerce' ),
259
+							'description' => __('The attribute ID, or 0 if the attribute is not taxonomy based.', 'woocommerce'),
260 260
 							'type'        => 'integer',
261
-							'context'     => [ 'view', 'edit' ],
261
+							'context'     => ['view', 'edit'],
262 262
 							'readonly'    => true,
263 263
 						],
264 264
 						'name'           => [
265
-							'description' => __( 'The attribute name.', 'woocommerce' ),
265
+							'description' => __('The attribute name.', 'woocommerce'),
266 266
 							'type'        => 'string',
267
-							'context'     => [ 'view', 'edit' ],
267
+							'context'     => ['view', 'edit'],
268 268
 							'readonly'    => true,
269 269
 						],
270 270
 						'taxonomy'       => [
271
-							'description' => __( 'The attribute taxonomy, or null if the attribute is not taxonomy based.', 'woocommerce' ),
271
+							'description' => __('The attribute taxonomy, or null if the attribute is not taxonomy based.', 'woocommerce'),
272 272
 							'type'        => 'string',
273
-							'context'     => [ 'view', 'edit' ],
273
+							'context'     => ['view', 'edit'],
274 274
 							'readonly'    => true,
275 275
 						],
276 276
 						'has_variations' => [
277
-							'description' => __( 'True if this attribute is used by product variations.', 'woocommerce' ),
277
+							'description' => __('True if this attribute is used by product variations.', 'woocommerce'),
278 278
 							'type'        => 'boolean',
279
-							'context'     => [ 'view', 'edit' ],
279
+							'context'     => ['view', 'edit'],
280 280
 							'readonly'    => true,
281 281
 						],
282 282
 						'terms'          => [
283
-							'description' => __( 'List of assigned attribute terms.', 'woocommerce' ),
283
+							'description' => __('List of assigned attribute terms.', 'woocommerce'),
284 284
 							'type'        => 'array',
285
-							'context'     => [ 'view', 'edit' ],
285
+							'context'     => ['view', 'edit'],
286 286
 							'items'       => [
287 287
 								'type'       => 'object',
288 288
 								'properties' => [
289 289
 									'id'      => [
290
-										'description' => __( 'The term ID, or 0 if the attribute is not a global attribute.', 'woocommerce' ),
290
+										'description' => __('The term ID, or 0 if the attribute is not a global attribute.', 'woocommerce'),
291 291
 										'type'        => 'integer',
292
-										'context'     => [ 'view', 'edit' ],
292
+										'context'     => ['view', 'edit'],
293 293
 										'readonly'    => true,
294 294
 									],
295 295
 									'name'    => [
296
-										'description' => __( 'The term name.', 'woocommerce' ),
296
+										'description' => __('The term name.', 'woocommerce'),
297 297
 										'type'        => 'string',
298
-										'context'     => [ 'view', 'edit' ],
298
+										'context'     => ['view', 'edit'],
299 299
 										'readonly'    => true,
300 300
 									],
301 301
 									'slug'    => [
302
-										'description' => __( 'The term slug.', 'woocommerce' ),
302
+										'description' => __('The term slug.', 'woocommerce'),
303 303
 										'type'        => 'string',
304
-										'context'     => [ 'view', 'edit' ],
304
+										'context'     => ['view', 'edit'],
305 305
 										'readonly'    => true,
306 306
 									],
307 307
 									'default' => [
308
-										'description' => __( 'If this is a default attribute', 'woocommerce' ),
308
+										'description' => __('If this is a default attribute', 'woocommerce'),
309 309
 										'type'        => 'boolean',
310
-										'context'     => [ 'view', 'edit' ],
310
+										'context'     => ['view', 'edit'],
311 311
 										'readonly'    => true,
312 312
 									],
313 313
 								],
@@ -317,35 +317,35 @@  discard block
 block discarded – undo
317 317
 				],
318 318
 			],
319 319
 			'variations'          => [
320
-				'description' => __( 'List of variation IDs, if applicable.', 'woocommerce' ),
320
+				'description' => __('List of variation IDs, if applicable.', 'woocommerce'),
321 321
 				'type'        => 'array',
322
-				'context'     => [ 'view', 'edit' ],
322
+				'context'     => ['view', 'edit'],
323 323
 				'items'       => [
324 324
 					'type'       => 'object',
325 325
 					'properties' => [
326 326
 						'id'         => [
327
-							'description' => __( 'The attribute ID, or 0 if the attribute is not taxonomy based.', 'woocommerce' ),
327
+							'description' => __('The attribute ID, or 0 if the attribute is not taxonomy based.', 'woocommerce'),
328 328
 							'type'        => 'integer',
329
-							'context'     => [ 'view', 'edit' ],
329
+							'context'     => ['view', 'edit'],
330 330
 							'readonly'    => true,
331 331
 						],
332 332
 						'attributes' => [
333
-							'description' => __( 'List of variation attributes.', 'woocommerce' ),
333
+							'description' => __('List of variation attributes.', 'woocommerce'),
334 334
 							'type'        => 'array',
335
-							'context'     => [ 'view', 'edit' ],
335
+							'context'     => ['view', 'edit'],
336 336
 							'items'       => [
337 337
 								'type'       => 'object',
338 338
 								'properties' => [
339 339
 									'name'  => [
340
-										'description' => __( 'The attribute name.', 'woocommerce' ),
340
+										'description' => __('The attribute name.', 'woocommerce'),
341 341
 										'type'        => 'string',
342
-										'context'     => [ 'view', 'edit' ],
342
+										'context'     => ['view', 'edit'],
343 343
 										'readonly'    => true,
344 344
 									],
345 345
 									'value' => [
346
-										'description' => __( 'The assigned attribute.', 'woocommerce' ),
346
+										'description' => __('The assigned attribute.', 'woocommerce'),
347 347
 										'type'        => 'string',
348
-										'context'     => [ 'view', 'edit' ],
348
+										'context'     => ['view', 'edit'],
349 349
 										'readonly'    => true,
350 350
 									],
351 351
 								],
@@ -355,87 +355,87 @@  discard block
 block discarded – undo
355 355
 				],
356 356
 			],
357 357
 			'has_options'         => [
358
-				'description' => __( 'Does the product have additional options before it can be added to the cart?', 'woocommerce' ),
358
+				'description' => __('Does the product have additional options before it can be added to the cart?', 'woocommerce'),
359 359
 				'type'        => 'boolean',
360
-				'context'     => [ 'view', 'edit' ],
360
+				'context'     => ['view', 'edit'],
361 361
 				'readonly'    => true,
362 362
 			],
363 363
 			'is_purchasable'      => [
364
-				'description' => __( 'Is the product purchasable?', 'woocommerce' ),
364
+				'description' => __('Is the product purchasable?', 'woocommerce'),
365 365
 				'type'        => 'boolean',
366
-				'context'     => [ 'view', 'edit' ],
366
+				'context'     => ['view', 'edit'],
367 367
 				'readonly'    => true,
368 368
 			],
369 369
 			'is_in_stock'         => [
370
-				'description' => __( 'Is the product in stock?', 'woocommerce' ),
370
+				'description' => __('Is the product in stock?', 'woocommerce'),
371 371
 				'type'        => 'boolean',
372
-				'context'     => [ 'view', 'edit' ],
372
+				'context'     => ['view', 'edit'],
373 373
 				'readonly'    => true,
374 374
 			],
375 375
 			'is_on_backorder'     => [
376
-				'description' => __( 'Is the product stock backordered? This will also return false if backorder notifications are turned off.', 'woocommerce' ),
376
+				'description' => __('Is the product stock backordered? This will also return false if backorder notifications are turned off.', 'woocommerce'),
377 377
 				'type'        => 'boolean',
378
-				'context'     => [ 'view', 'edit' ],
378
+				'context'     => ['view', 'edit'],
379 379
 				'readonly'    => true,
380 380
 			],
381 381
 			'low_stock_remaining' => [
382
-				'description' => __( 'Quantity left in stock if stock is low, or null if not applicable.', 'woocommerce' ),
383
-				'type'        => [ 'integer', 'null' ],
384
-				'context'     => [ 'view', 'edit' ],
382
+				'description' => __('Quantity left in stock if stock is low, or null if not applicable.', 'woocommerce'),
383
+				'type'        => ['integer', 'null'],
384
+				'context'     => ['view', 'edit'],
385 385
 				'readonly'    => true,
386 386
 			],
387 387
 			'sold_individually'   => [
388
-				'description' => __( 'If true, only one item of this product is allowed for purchase in a single order.', 'woocommerce' ),
388
+				'description' => __('If true, only one item of this product is allowed for purchase in a single order.', 'woocommerce'),
389 389
 				'type'        => 'boolean',
390
-				'context'     => [ 'view', 'edit' ],
390
+				'context'     => ['view', 'edit'],
391 391
 				'readonly'    => true,
392 392
 			],
393 393
 			'add_to_cart'         => [
394
-				'description' => __( 'Add to cart button parameters.', 'woocommerce' ),
394
+				'description' => __('Add to cart button parameters.', 'woocommerce'),
395 395
 				'type'        => 'object',
396
-				'context'     => [ 'view', 'edit' ],
396
+				'context'     => ['view', 'edit'],
397 397
 				'readonly'    => true,
398 398
 				'properties'  => [
399 399
 					'text'        => [
400
-						'description' => __( 'Button text.', 'woocommerce' ),
400
+						'description' => __('Button text.', 'woocommerce'),
401 401
 						'type'        => 'string',
402
-						'context'     => [ 'view', 'edit' ],
402
+						'context'     => ['view', 'edit'],
403 403
 						'readonly'    => true,
404 404
 					],
405 405
 					'description' => [
406
-						'description' => __( 'Button description.', 'woocommerce' ),
406
+						'description' => __('Button description.', 'woocommerce'),
407 407
 						'type'        => 'string',
408
-						'context'     => [ 'view', 'edit' ],
408
+						'context'     => ['view', 'edit'],
409 409
 						'readonly'    => true,
410 410
 					],
411 411
 					'url'         => [
412
-						'description' => __( 'Add to cart URL.', 'woocommerce' ),
412
+						'description' => __('Add to cart URL.', 'woocommerce'),
413 413
 						'type'        => 'string',
414
-						'context'     => [ 'view', 'edit' ],
414
+						'context'     => ['view', 'edit'],
415 415
 						'readonly'    => true,
416 416
 					],
417 417
 					'minimum'     => [
418
-						'description' => __( 'The minimum quantity that can be added to the cart.', 'woocommerce' ),
418
+						'description' => __('The minimum quantity that can be added to the cart.', 'woocommerce'),
419 419
 						'type'        => 'integer',
420
-						'context'     => [ 'view', 'edit' ],
420
+						'context'     => ['view', 'edit'],
421 421
 						'readonly'    => true,
422 422
 					],
423 423
 					'maximum'     => [
424
-						'description' => __( 'The maximum quantity that can be added to the cart.', 'woocommerce' ),
424
+						'description' => __('The maximum quantity that can be added to the cart.', 'woocommerce'),
425 425
 						'type'        => 'integer',
426
-						'context'     => [ 'view', 'edit' ],
426
+						'context'     => ['view', 'edit'],
427 427
 						'readonly'    => true,
428 428
 					],
429 429
 					'multiple_of' => [
430
-						'description' => __( 'The amount that quantities increment by. Quantity must be an multiple of this value.', 'woocommerce' ),
430
+						'description' => __('The amount that quantities increment by. Quantity must be an multiple of this value.', 'woocommerce'),
431 431
 						'type'        => 'integer',
432
-						'context'     => [ 'view', 'edit' ],
432
+						'context'     => ['view', 'edit'],
433 433
 						'readonly'    => true,
434 434
 						'default'     => 1,
435 435
 					],
436 436
 				],
437 437
 			],
438
-			self::EXTENDING_KEY   => $this->get_extended_schema( self::IDENTIFIER ),
438
+			self::EXTENDING_KEY   => $this->get_extended_schema(self::IDENTIFIER),
439 439
 		];
440 440
 	}
441 441
 
@@ -445,42 +445,42 @@  discard block
 block discarded – undo
445 445
 	 * @param \WC_Product $product Product instance.
446 446
 	 * @return array
447 447
 	 */
448
-	public function get_item_response( $product ) {
448
+	public function get_item_response($product) {
449 449
 		return [
450 450
 			'id'                  => $product->get_id(),
451
-			'name'                => $this->prepare_html_response( $product->get_title() ),
451
+			'name'                => $this->prepare_html_response($product->get_title()),
452 452
 			'parent'              => $product->get_parent_id(),
453 453
 			'type'                => $product->get_type(),
454
-			'variation'           => $this->prepare_html_response( $product->is_type( 'variation' ) ? wc_get_formatted_variation( $product, true, true, false ) : '' ),
454
+			'variation'           => $this->prepare_html_response($product->is_type('variation') ? wc_get_formatted_variation($product, true, true, false) : ''),
455 455
 			'permalink'           => $product->get_permalink(),
456
-			'sku'                 => $this->prepare_html_response( $product->get_sku() ),
457
-			'short_description'   => $this->prepare_html_response( wc_format_content( wp_kses_post( $product->get_short_description() ) ) ),
458
-			'description'         => $this->prepare_html_response( wc_format_content( wp_kses_post( $product->get_description() ) ) ),
456
+			'sku'                 => $this->prepare_html_response($product->get_sku()),
457
+			'short_description'   => $this->prepare_html_response(wc_format_content(wp_kses_post($product->get_short_description()))),
458
+			'description'         => $this->prepare_html_response(wc_format_content(wp_kses_post($product->get_description()))),
459 459
 			'on_sale'             => $product->is_on_sale(),
460
-			'prices'              => (object) $this->prepare_product_price_response( $product ),
461
-			'price_html'          => $this->prepare_html_response( $product->get_price_html() ),
460
+			'prices'              => (object) $this->prepare_product_price_response($product),
461
+			'price_html'          => $this->prepare_html_response($product->get_price_html()),
462 462
 			'average_rating'      => (string) $product->get_average_rating(),
463 463
 			'review_count'        => $product->get_review_count(),
464
-			'images'              => $this->get_images( $product ),
465
-			'categories'          => $this->get_term_list( $product, 'product_cat' ),
466
-			'tags'                => $this->get_term_list( $product, 'product_tag' ),
467
-			'attributes'          => $this->get_attributes( $product ),
468
-			'variations'          => $this->get_variations( $product ),
464
+			'images'              => $this->get_images($product),
465
+			'categories'          => $this->get_term_list($product, 'product_cat'),
466
+			'tags'                => $this->get_term_list($product, 'product_tag'),
467
+			'attributes'          => $this->get_attributes($product),
468
+			'variations'          => $this->get_variations($product),
469 469
 			'has_options'         => $product->has_options(),
470 470
 			'is_purchasable'      => $product->is_purchasable(),
471 471
 			'is_in_stock'         => $product->is_in_stock(),
472 472
 			'is_on_backorder'     => 'onbackorder' === $product->get_stock_status(),
473
-			'low_stock_remaining' => $this->get_low_stock_remaining( $product ),
473
+			'low_stock_remaining' => $this->get_low_stock_remaining($product),
474 474
 			'sold_individually'   => $product->is_sold_individually(),
475 475
 			'add_to_cart'         => (object) array_merge(
476 476
 				[
477
-					'text'        => $this->prepare_html_response( $product->add_to_cart_text() ),
478
-					'description' => $this->prepare_html_response( $product->add_to_cart_description() ),
479
-					'url'         => $this->prepare_html_response( $product->add_to_cart_url() ),
477
+					'text'        => $this->prepare_html_response($product->add_to_cart_text()),
478
+					'description' => $this->prepare_html_response($product->add_to_cart_description()),
479
+					'url'         => $this->prepare_html_response($product->add_to_cart_url()),
480 480
 				],
481
-				( new QuantityLimits() )->get_add_to_cart_limits( $product )
481
+				(new QuantityLimits())->get_add_to_cart_limits($product)
482 482
 			),
483
-			self::EXTENDING_KEY   => $this->get_extended_data( self::IDENTIFIER, $product ),
483
+			self::EXTENDING_KEY   => $this->get_extended_data(self::IDENTIFIER, $product),
484 484
 
485 485
 		];
486 486
 	}
@@ -491,10 +491,10 @@  discard block
 block discarded – undo
491 491
 	 * @param \WC_Product $product Product instance.
492 492
 	 * @return array
493 493
 	 */
494
-	protected function get_images( \WC_Product $product ) {
495
-		$attachment_ids = array_merge( [ $product->get_image_id() ], $product->get_gallery_image_ids() );
494
+	protected function get_images(\WC_Product $product) {
495
+		$attachment_ids = array_merge([$product->get_image_id()], $product->get_gallery_image_ids());
496 496
 
497
-		return array_filter( array_map( [ $this->image_attachment_schema, 'get_item_response' ], $attachment_ids ) );
497
+		return array_filter(array_map([$this->image_attachment_schema, 'get_item_response'], $attachment_ids));
498 498
 	}
499 499
 
500 500
 	/**
@@ -503,8 +503,8 @@  discard block
 block discarded – undo
503 503
 	 * @param \WC_Product $product Product instance.
504 504
 	 * @return integer|null
505 505
 	 */
506
-	protected function get_remaining_stock( \WC_Product $product ) {
507
-		if ( is_null( $product->get_stock_quantity() ) ) {
506
+	protected function get_remaining_stock(\WC_Product $product) {
507
+		if (is_null($product->get_stock_quantity())) {
508 508
 			return null;
509 509
 		}
510 510
 		return $product->get_stock_quantity();
@@ -516,18 +516,18 @@  discard block
 block discarded – undo
516 516
 	 * @param \WC_Product $product Product instance.
517 517
 	 * @return integer|null
518 518
 	 */
519
-	protected function get_low_stock_remaining( \WC_Product $product ) {
520
-		$remaining_stock = $this->get_remaining_stock( $product );
521
-		$stock_format    = get_option( 'woocommerce_stock_format' );
519
+	protected function get_low_stock_remaining(\WC_Product $product) {
520
+		$remaining_stock = $this->get_remaining_stock($product);
521
+		$stock_format    = get_option('woocommerce_stock_format');
522 522
 
523 523
 		// Don't show the low stock badge if the settings doesn't allow it.
524
-		if ( 'no_amount' === $stock_format ) {
524
+		if ('no_amount' === $stock_format) {
525 525
 			return null;
526 526
 		}
527 527
 
528 528
 		// Show the low stock badge if the remaining stock is below or equal to the threshold.
529
-		if ( ! is_null( $remaining_stock ) && $remaining_stock <= wc_get_low_stock_amount( $product ) ) {
530
-			return max( $remaining_stock, 0 );
529
+		if (!is_null($remaining_stock) && $remaining_stock <= wc_get_low_stock_amount($product)) {
530
+			return max($remaining_stock, 0);
531 531
 		}
532 532
 
533 533
 		return null;
@@ -539,8 +539,8 @@  discard block
 block discarded – undo
539 539
 	 * @param mixed $attribute Object or variable to check.
540 540
 	 * @return boolean
541 541
 	 */
542
-	protected function filter_valid_attribute( $attribute ) {
543
-		return is_a( $attribute, '\WC_Product_Attribute' );
542
+	protected function filter_valid_attribute($attribute) {
543
+		return is_a($attribute, '\WC_Product_Attribute');
544 544
 	}
545 545
 
546 546
 	/**
@@ -549,8 +549,8 @@  discard block
 block discarded – undo
549 549
 	 * @param mixed $attribute Object or variable to check.
550 550
 	 * @return boolean
551 551
 	 */
552
-	protected function filter_variation_attribute( $attribute ) {
553
-		return $this->filter_valid_attribute( $attribute ) && $attribute->get_variation();
552
+	protected function filter_variation_attribute($attribute) {
553
+		return $this->filter_valid_attribute($attribute) && $attribute->get_variation();
554 554
 	}
555 555
 
556 556
 	/**
@@ -559,47 +559,47 @@  discard block
 block discarded – undo
559 559
 	 * @param \WC_Product $product Product instance.
560 560
 	 * @returns array
561 561
 	 */
562
-	protected function get_variations( \WC_Product $product ) {
563
-		$variation_ids = $product->is_type( 'variable' ) ? $product->get_visible_children() : [];
562
+	protected function get_variations(\WC_Product $product) {
563
+		$variation_ids = $product->is_type('variable') ? $product->get_visible_children() : [];
564 564
 
565
-		if ( ! count( $variation_ids ) ) {
565
+		if (!count($variation_ids)) {
566 566
 			return [];
567 567
 		}
568 568
 
569 569
 		/**
570 570
 		 * Gets default variation data which applies to all of this products variations.
571 571
 		 */
572
-		$attributes                  = array_filter( $product->get_attributes(), [ $this, 'filter_variation_attribute' ] );
572
+		$attributes                  = array_filter($product->get_attributes(), [$this, 'filter_variation_attribute']);
573 573
 		$default_variation_meta_data = array_reduce(
574 574
 			$attributes,
575
-			function( $defaults, $attribute ) use ( $product ) {
576
-				$meta_key              = wc_variation_attribute_name( $attribute->get_name() );
577
-				$defaults[ $meta_key ] = [
578
-					'name'  => wc_attribute_label( $attribute->get_name(), $product ),
575
+			function($defaults, $attribute) use ($product) {
576
+				$meta_key              = wc_variation_attribute_name($attribute->get_name());
577
+				$defaults[$meta_key] = [
578
+					'name'  => wc_attribute_label($attribute->get_name(), $product),
579 579
 					'value' => null,
580 580
 				];
581 581
 				return $defaults;
582 582
 			},
583 583
 			[]
584 584
 		);
585
-		$default_variation_meta_keys = array_keys( $default_variation_meta_data );
585
+		$default_variation_meta_keys = array_keys($default_variation_meta_data);
586 586
 
587 587
 		/**
588 588
 		 * Gets individual variation data from the database, using cache where possible.
589 589
 		 */
590 590
 		$cache_group   = 'product_variation_meta_data';
591
-		$cache_value   = wp_cache_get( $product->get_id(), $cache_group );
592
-		$last_modified = get_the_modified_date( 'U', $product->get_id() );
591
+		$cache_value   = wp_cache_get($product->get_id(), $cache_group);
592
+		$last_modified = get_the_modified_date('U', $product->get_id());
593 593
 
594
-		if ( false === $cache_value || $last_modified !== $cache_value['last_modified'] ) {
594
+		if (false === $cache_value || $last_modified !== $cache_value['last_modified']) {
595 595
 			global $wpdb;
596 596
 			// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared
597 597
 			$variation_meta_data = $wpdb->get_results(
598 598
 				"
599 599
 				SELECT post_id as variation_id, meta_key as attribute_key, meta_value as attribute_value
600 600
 				FROM {$wpdb->postmeta}
601
-				WHERE post_id IN (" . implode( ',', array_map( 'esc_sql', $variation_ids ) ) . ")
602
-				AND meta_key IN ('" . implode( "','", array_map( 'esc_sql', $default_variation_meta_keys ) ) . "')
601
+				WHERE post_id IN (" . implode(',', array_map('esc_sql', $variation_ids)) . ")
602
+				AND meta_key IN ('" . implode("','", array_map('esc_sql', $default_variation_meta_keys)) . "')
603 603
 			"
604 604
 			);
605 605
 			// phpcs:enable
@@ -621,33 +621,33 @@  discard block
 block discarded – undo
621 621
 		 */
622 622
 		$attributes_by_variation = array_reduce(
623 623
 			$variation_meta_data,
624
-			function( $values, $data ) use ( $default_variation_meta_keys ) {
624
+			function($values, $data) use ($default_variation_meta_keys) {
625 625
 				// The query above only includes the keys of $default_variation_meta_data so we know all of the attributes
626 626
 				// being processed here apply to this product. However, we need an additional check here because the
627 627
 				// cache may have been primed elsewhere and include keys from other products.
628 628
 				// @see AbstractProductGrid::prime_product_variations.
629
-				if ( in_array( $data->attribute_key, $default_variation_meta_keys, true ) ) {
630
-					$values[ $data->variation_id ][ $data->attribute_key ] = $data->attribute_value;
629
+				if (in_array($data->attribute_key, $default_variation_meta_keys, true)) {
630
+					$values[$data->variation_id][$data->attribute_key] = $data->attribute_value;
631 631
 				}
632 632
 				return $values;
633 633
 			},
634
-			array_fill_keys( $variation_ids, [] )
634
+			array_fill_keys($variation_ids, [])
635 635
 		);
636 636
 
637 637
 		$variations = [];
638 638
 
639
-		foreach ( $variation_ids as $variation_id ) {
639
+		foreach ($variation_ids as $variation_id) {
640 640
 			$attribute_data = $default_variation_meta_data;
641 641
 
642
-			foreach ( $attributes_by_variation[ $variation_id ] as $meta_key => $meta_value ) {
643
-				if ( '' !== $meta_value ) {
644
-					$attribute_data[ $meta_key ]['value'] = $meta_value;
642
+			foreach ($attributes_by_variation[$variation_id] as $meta_key => $meta_value) {
643
+				if ('' !== $meta_value) {
644
+					$attribute_data[$meta_key]['value'] = $meta_value;
645 645
 				}
646 646
 			}
647 647
 
648 648
 			$variations[] = (object) [
649 649
 				'id'         => $variation_id,
650
-				'attributes' => array_values( $attribute_data ),
650
+				'attributes' => array_values($attribute_data),
651 651
 			];
652 652
 		}
653 653
 
@@ -660,32 +660,32 @@  discard block
 block discarded – undo
660 660
 	 * @param \WC_Product $product Product instance.
661 661
 	 * @return array
662 662
 	 */
663
-	protected function get_attributes( \WC_Product $product ) {
664
-		$attributes         = array_filter( $product->get_attributes(), [ $this, 'filter_valid_attribute' ] );
663
+	protected function get_attributes(\WC_Product $product) {
664
+		$attributes         = array_filter($product->get_attributes(), [$this, 'filter_valid_attribute']);
665 665
 		$default_attributes = $product->get_default_attributes();
666 666
 		$return             = [];
667 667
 
668
-		foreach ( $attributes as $attribute_slug => $attribute ) {
668
+		foreach ($attributes as $attribute_slug => $attribute) {
669 669
 			// Only visible or variation attributes will be exposed by this API.
670
-			if ( ! $attribute->get_visible() && ! $attribute->get_variation() ) {
670
+			if (!$attribute->get_visible() && !$attribute->get_variation()) {
671 671
 				continue;
672 672
 			}
673 673
 
674
-			$terms = $attribute->is_taxonomy() ? array_map( [ $this, 'prepare_product_attribute_taxonomy_value' ], $attribute->get_terms() ) : array_map( [ $this, 'prepare_product_attribute_value' ], $attribute->get_options() );
674
+			$terms = $attribute->is_taxonomy() ? array_map([$this, 'prepare_product_attribute_taxonomy_value'], $attribute->get_terms()) : array_map([$this, 'prepare_product_attribute_value'], $attribute->get_options());
675 675
 			// Custom attribute names are sanitized to be the array keys.
676 676
 			// So when we do the array_key_exists check below we also need to sanitize the attribute names.
677 677
 
678
-			$sanitized_attribute_name = sanitize_key( $attribute->get_name() );
678
+			$sanitized_attribute_name = sanitize_key($attribute->get_name());
679 679
 
680
-			if ( array_key_exists( $sanitized_attribute_name, $default_attributes ) ) {
681
-				foreach ( $terms as $term ) {
682
-					$term->default = $term->slug === $default_attributes[ $sanitized_attribute_name ];
680
+			if (array_key_exists($sanitized_attribute_name, $default_attributes)) {
681
+				foreach ($terms as $term) {
682
+					$term->default = $term->slug === $default_attributes[$sanitized_attribute_name];
683 683
 				}
684 684
 			}
685 685
 
686 686
 			$return[] = (object) [
687 687
 				'id'             => $attribute->get_id(),
688
-				'name'           => wc_attribute_label( $attribute->get_name(), $product ),
688
+				'name'           => wc_attribute_label($attribute->get_name(), $product),
689 689
 				'taxonomy'       => $attribute->is_taxonomy() ? $attribute->get_name() : null,
690 690
 				'has_variations' => true === $attribute->get_variation(),
691 691
 				'terms'          => $terms,
@@ -701,8 +701,8 @@  discard block
 block discarded – undo
701 701
 	 * @param \WP_Term $term Term object.
702 702
 	 * @return object
703 703
 	 */
704
-	protected function prepare_product_attribute_taxonomy_value( \WP_Term $term ) {
705
-		return $this->prepare_product_attribute_value( $term->name, $term->term_id, $term->slug );
704
+	protected function prepare_product_attribute_taxonomy_value(\WP_Term $term) {
705
+		return $this->prepare_product_attribute_value($term->name, $term->term_id, $term->slug);
706 706
 	}
707 707
 
708 708
 	/**
@@ -713,7 +713,7 @@  discard block
 block discarded – undo
713 713
 	 * @param string $slug Attribute term slug.
714 714
 	 * @return object
715 715
 	 */
716
-	protected function prepare_product_attribute_value( $name, $id = 0, $slug = '' ) {
716
+	protected function prepare_product_attribute_value($name, $id = 0, $slug = '') {
717 717
 		return (object) [
718 718
 			'id'   => (int) $id,
719 719
 			'name' => $name,
@@ -728,13 +728,13 @@  discard block
 block discarded – undo
728 728
 	 * @param string      $tax_display_mode If returned prices are incl or excl of tax.
729 729
 	 * @return array
730 730
 	 */
731
-	protected function prepare_product_price_response( \WC_Product $product, $tax_display_mode = '' ) {
731
+	protected function prepare_product_price_response(\WC_Product $product, $tax_display_mode = '') {
732 732
 		$prices           = [];
733
-		$tax_display_mode = $this->get_tax_display_mode( $tax_display_mode );
734
-		$price_function   = $this->get_price_function_from_tax_display_mode( $tax_display_mode );
733
+		$tax_display_mode = $this->get_tax_display_mode($tax_display_mode);
734
+		$price_function   = $this->get_price_function_from_tax_display_mode($tax_display_mode);
735 735
 
736 736
 		// If we have a variable product, get the price from the variations (this will use the min value).
737
-		if ( $product->is_type( 'variable' ) ) {
737
+		if ($product->is_type('variable')) {
738 738
 			$regular_price = $product->get_variation_regular_price();
739 739
 			$sale_price    = $product->get_variation_sale_price();
740 740
 		} else {
@@ -742,12 +742,12 @@  discard block
 block discarded – undo
742 742
 			$sale_price    = $product->get_sale_price();
743 743
 		}
744 744
 
745
-		$prices['price']         = $this->prepare_money_response( $price_function( $product ), wc_get_price_decimals() );
746
-		$prices['regular_price'] = $this->prepare_money_response( $price_function( $product, [ 'price' => $regular_price ] ), wc_get_price_decimals() );
747
-		$prices['sale_price']    = $this->prepare_money_response( $price_function( $product, [ 'price' => $sale_price ] ), wc_get_price_decimals() );
748
-		$prices['price_range']   = $this->get_price_range( $product, $tax_display_mode );
745
+		$prices['price']         = $this->prepare_money_response($price_function($product), wc_get_price_decimals());
746
+		$prices['regular_price'] = $this->prepare_money_response($price_function($product, ['price' => $regular_price]), wc_get_price_decimals());
747
+		$prices['sale_price']    = $this->prepare_money_response($price_function($product, ['price' => $sale_price]), wc_get_price_decimals());
748
+		$prices['price_range']   = $this->get_price_range($product, $tax_display_mode);
749 749
 
750
-		return $this->prepare_currency_response( $prices );
750
+		return $this->prepare_currency_response($prices);
751 751
 	}
752 752
 
753 753
 	/**
@@ -756,8 +756,8 @@  discard block
 block discarded – undo
756 756
 	 * @param string $tax_display_mode Provided tax display mode.
757 757
 	 * @return string Valid tax display mode.
758 758
 	 */
759
-	protected function get_tax_display_mode( $tax_display_mode = '' ) {
760
-		return in_array( $tax_display_mode, [ 'incl', 'excl' ], true ) ? $tax_display_mode : get_option( 'woocommerce_tax_display_shop' );
759
+	protected function get_tax_display_mode($tax_display_mode = '') {
760
+		return in_array($tax_display_mode, ['incl', 'excl'], true) ? $tax_display_mode : get_option('woocommerce_tax_display_shop');
761 761
 	}
762 762
 
763 763
 	/**
@@ -766,7 +766,7 @@  discard block
 block discarded – undo
766 766
 	 * @param string $tax_display_mode If returned prices are incl or excl of tax.
767 767
 	 * @return string Function name.
768 768
 	 */
769
-	protected function get_price_function_from_tax_display_mode( $tax_display_mode ) {
769
+	protected function get_price_function_from_tax_display_mode($tax_display_mode) {
770 770
 		return 'incl' === $tax_display_mode ? 'wc_get_price_including_tax' : 'wc_get_price_excluding_tax';
771 771
 	}
772 772
 
@@ -777,34 +777,34 @@  discard block
 block discarded – undo
777 777
 	 * @param string      $tax_display_mode If returned prices are incl or excl of tax.
778 778
 	 * @return object|null
779 779
 	 */
780
-	protected function get_price_range( \WC_Product $product, $tax_display_mode = '' ) {
781
-		$tax_display_mode = $this->get_tax_display_mode( $tax_display_mode );
780
+	protected function get_price_range(\WC_Product $product, $tax_display_mode = '') {
781
+		$tax_display_mode = $this->get_tax_display_mode($tax_display_mode);
782 782
 
783
-		if ( $product->is_type( 'variable' ) ) {
784
-			$prices = $product->get_variation_prices( true );
783
+		if ($product->is_type('variable')) {
784
+			$prices = $product->get_variation_prices(true);
785 785
 
786
-			if ( ! empty( $prices['price'] ) && ( min( $prices['price'] ) !== max( $prices['price'] ) ) ) {
786
+			if (!empty($prices['price']) && (min($prices['price']) !== max($prices['price']))) {
787 787
 				return (object) [
788
-					'min_amount' => $this->prepare_money_response( min( $prices['price'] ), wc_get_price_decimals() ),
789
-					'max_amount' => $this->prepare_money_response( max( $prices['price'] ), wc_get_price_decimals() ),
788
+					'min_amount' => $this->prepare_money_response(min($prices['price']), wc_get_price_decimals()),
789
+					'max_amount' => $this->prepare_money_response(max($prices['price']), wc_get_price_decimals()),
790 790
 				];
791 791
 			}
792 792
 		}
793 793
 
794
-		if ( $product->is_type( 'grouped' ) ) {
795
-			$children       = array_filter( array_map( 'wc_get_product', $product->get_children() ), 'wc_products_array_filter_visible_grouped' );
794
+		if ($product->is_type('grouped')) {
795
+			$children       = array_filter(array_map('wc_get_product', $product->get_children()), 'wc_products_array_filter_visible_grouped');
796 796
 			$price_function = 'incl' === $tax_display_mode ? 'wc_get_price_including_tax' : 'wc_get_price_excluding_tax';
797 797
 
798
-			foreach ( $children as $child ) {
799
-				if ( '' !== $child->get_price() ) {
800
-					$child_prices[] = $price_function( $child );
798
+			foreach ($children as $child) {
799
+				if ('' !== $child->get_price()) {
800
+					$child_prices[] = $price_function($child);
801 801
 				}
802 802
 			}
803 803
 
804
-			if ( ! empty( $child_prices ) ) {
804
+			if (!empty($child_prices)) {
805 805
 				return (object) [
806
-					'min_amount' => $this->prepare_money_response( min( $child_prices ), wc_get_price_decimals() ),
807
-					'max_amount' => $this->prepare_money_response( max( $child_prices ), wc_get_price_decimals() ),
806
+					'min_amount' => $this->prepare_money_response(min($child_prices), wc_get_price_decimals()),
807
+					'max_amount' => $this->prepare_money_response(max($child_prices), wc_get_price_decimals()),
808 808
 				];
809 809
 			}
810 810
 		}
@@ -819,28 +819,28 @@  discard block
 block discarded – undo
819 819
 	 * @param string      $taxonomy Taxonomy name.
820 820
 	 * @return array Array of terms (id, name, slug).
821 821
 	 */
822
-	protected function get_term_list( \WC_Product $product, $taxonomy = '' ) {
823
-		if ( ! $taxonomy ) {
822
+	protected function get_term_list(\WC_Product $product, $taxonomy = '') {
823
+		if (!$taxonomy) {
824 824
 			return [];
825 825
 		}
826 826
 
827
-		$terms = get_the_terms( $product->get_id(), $taxonomy );
827
+		$terms = get_the_terms($product->get_id(), $taxonomy);
828 828
 
829
-		if ( ! $terms || is_wp_error( $terms ) ) {
829
+		if (!$terms || is_wp_error($terms)) {
830 830
 			return [];
831 831
 		}
832 832
 
833 833
 		$return           = [];
834
-		$default_category = (int) get_option( 'default_product_cat', 0 );
834
+		$default_category = (int) get_option('default_product_cat', 0);
835 835
 
836
-		foreach ( $terms as $term ) {
837
-			$link = get_term_link( $term, $taxonomy );
836
+		foreach ($terms as $term) {
837
+			$link = get_term_link($term, $taxonomy);
838 838
 
839
-			if ( is_wp_error( $link ) ) {
839
+			if (is_wp_error($link)) {
840 840
 				continue;
841 841
 			}
842 842
 
843
-			if ( $term->term_id === $default_category ) {
843
+			if ($term->term_id === $default_category) {
844 844
 				continue;
845 845
 			}
846 846
 
Please login to merge, or discard this patch.
woocommerce-blocks/src/StoreApi/Schemas/V1/AbstractAddressSchema.php 2 patches
Indentation   +208 added lines, -208 removed lines patch added patch discarded remove patch
@@ -7,212 +7,212 @@
 block discarded – undo
7 7
  * Provides a generic address schema for composition in other schemas.
8 8
  */
9 9
 abstract class AbstractAddressSchema extends AbstractSchema {
10
-	/**
11
-	 * Term properties.
12
-	 *
13
-	 * @internal Note that required properties don't require values, just that they are included in the request.
14
-	 * @return array
15
-	 */
16
-	public function get_properties() {
17
-		return [
18
-			'first_name' => [
19
-				'description' => __( 'First name', 'woocommerce' ),
20
-				'type'        => 'string',
21
-				'context'     => [ 'view', 'edit' ],
22
-				'required'    => true,
23
-			],
24
-			'last_name'  => [
25
-				'description' => __( 'Last name', 'woocommerce' ),
26
-				'type'        => 'string',
27
-				'context'     => [ 'view', 'edit' ],
28
-				'required'    => true,
29
-			],
30
-			'company'    => [
31
-				'description' => __( 'Company', 'woocommerce' ),
32
-				'type'        => 'string',
33
-				'context'     => [ 'view', 'edit' ],
34
-				'required'    => true,
35
-			],
36
-			'address_1'  => [
37
-				'description' => __( 'Address', 'woocommerce' ),
38
-				'type'        => 'string',
39
-				'context'     => [ 'view', 'edit' ],
40
-				'required'    => true,
41
-			],
42
-			'address_2'  => [
43
-				'description' => __( 'Apartment, suite, etc.', 'woocommerce' ),
44
-				'type'        => 'string',
45
-				'context'     => [ 'view', 'edit' ],
46
-				'required'    => true,
47
-			],
48
-			'city'       => [
49
-				'description' => __( 'City', 'woocommerce' ),
50
-				'type'        => 'string',
51
-				'context'     => [ 'view', 'edit' ],
52
-				'required'    => true,
53
-			],
54
-			'state'      => [
55
-				'description' => __( 'State/County code, or name of the state, county, province, or district.', 'woocommerce' ),
56
-				'type'        => 'string',
57
-				'context'     => [ 'view', 'edit' ],
58
-				'required'    => true,
59
-			],
60
-			'postcode'   => [
61
-				'description' => __( 'Postal code', 'woocommerce' ),
62
-				'type'        => 'string',
63
-				'context'     => [ 'view', 'edit' ],
64
-				'required'    => true,
65
-			],
66
-			'country'    => [
67
-				'description' => __( 'Country/Region code in ISO 3166-1 alpha-2 format.', 'woocommerce' ),
68
-				'type'        => 'string',
69
-				'context'     => [ 'view', 'edit' ],
70
-				'required'    => true,
71
-			],
72
-			'phone'      => [
73
-				'description' => __( 'Phone', 'woocommerce' ),
74
-				'type'        => 'string',
75
-				'context'     => [ 'view', 'edit' ],
76
-				'required'    => true,
77
-			],
78
-		];
79
-	}
80
-
81
-	/**
82
-	 * Sanitize and format the given address object.
83
-	 *
84
-	 * @param array            $address Value being sanitized.
85
-	 * @param \WP_REST_Request $request The Request.
86
-	 * @param string           $param The param being sanitized.
87
-	 * @return array
88
-	 */
89
-	public function sanitize_callback( $address, $request, $param ) {
90
-		$address               = array_merge( array_fill_keys( array_keys( $this->get_properties() ), '' ), (array) $address );
91
-		$address['country']    = wc_strtoupper( wc_clean( wp_unslash( $address['country'] ) ) );
92
-		$address['first_name'] = wc_clean( wp_unslash( $address['first_name'] ) );
93
-		$address['last_name']  = wc_clean( wp_unslash( $address['last_name'] ) );
94
-		$address['company']    = wc_clean( wp_unslash( $address['company'] ) );
95
-		$address['address_1']  = wc_clean( wp_unslash( $address['address_1'] ) );
96
-		$address['address_2']  = wc_clean( wp_unslash( $address['address_2'] ) );
97
-		$address['city']       = wc_clean( wp_unslash( $address['city'] ) );
98
-		$address['state']      = $this->format_state( wc_clean( wp_unslash( $address['state'] ) ), $address['country'] );
99
-		$address['postcode']   = $address['postcode'] ? wc_format_postcode( wc_clean( wp_unslash( $address['postcode'] ) ), $address['country'] ) : '';
100
-		$address['phone']      = wc_clean( wp_unslash( $address['phone'] ) );
101
-		return $address;
102
-	}
103
-
104
-	/**
105
-	 * Get list of states for a country.
106
-	 *
107
-	 * @param string $country Country code.
108
-	 * @return array Array of state names indexed by state keys.
109
-	 */
110
-	protected function get_states_for_country( $country ) {
111
-		return $country ? array_filter( (array) \wc()->countries->get_states( $country ) ) : [];
112
-	}
113
-
114
-	/**
115
-	 * Validate provided state against a countries list of defined states.
116
-	 *
117
-	 * If there are no defined states for a country, any given state is valid.
118
-	 *
119
-	 * @param string $state State name or code (sanitized).
120
-	 * @param string $country Country code.
121
-	 * @return boolean Valid or not valid.
122
-	 */
123
-	protected function validate_state( $state, $country ) {
124
-		$states = $this->get_states_for_country( $country );
125
-
126
-		if ( count( $states ) && ! in_array( \wc_strtoupper( $state ), array_map( '\wc_strtoupper', array_keys( $states ) ), true ) ) {
127
-			return false;
128
-		}
129
-
130
-		return true;
131
-	}
132
-
133
-	/**
134
-	 * Format a state based on the country. If country has defined states, will return a valid upper case state code.
135
-	 *
136
-	 * @param string $state State name or code (sanitized).
137
-	 * @param string $country Country code.
138
-	 * @return string
139
-	 */
140
-	protected function format_state( $state, $country ) {
141
-		$states = $this->get_states_for_country( $country );
142
-
143
-		if ( count( $states ) ) {
144
-			$state        = \wc_strtoupper( $state );
145
-			$state_values = array_map( 'wc_strtoupper', array_flip( array_map( '\wc_strtoupper', $states ) ) );
146
-
147
-			if ( isset( $state_values[ $state ] ) ) {
148
-				// Convert to state code if a state name was provided.
149
-				return $state_values[ $state ];
150
-			}
151
-		}
152
-
153
-		return $state;
154
-	}
155
-
156
-	/**
157
-	 * Validate the given address object.
158
-	 *
159
-	 * @see rest_validate_value_from_schema
160
-	 *
161
-	 * @param array            $address Value being sanitized.
162
-	 * @param \WP_REST_Request $request The Request.
163
-	 * @param string           $param The param being sanitized.
164
-	 * @return true|\WP_Error
165
-	 */
166
-	public function validate_callback( $address, $request, $param ) {
167
-		$errors  = new \WP_Error();
168
-		$address = $this->sanitize_callback( $address, $request, $param );
169
-
170
-		if ( empty( $address['country'] ) ) {
171
-			$errors->add(
172
-				'missing_country',
173
-				__( 'Country is required', 'woocommerce' )
174
-			);
175
-			return $errors;
176
-		}
177
-
178
-		if ( ! in_array( $address['country'], array_keys( wc()->countries->get_countries() ), true ) ) {
179
-			$errors->add(
180
-				'invalid_country',
181
-				sprintf(
182
-					/* translators: %s valid country codes */
183
-					__( 'Invalid country code provided. Must be one of: %s', 'woocommerce' ),
184
-					implode( ', ', array_keys( wc()->countries->get_countries() ) )
185
-				)
186
-			);
187
-			return $errors;
188
-		}
189
-
190
-		if ( ! empty( $address['state'] ) && ! $this->validate_state( $address['state'], $address['country'] ) ) {
191
-			$errors->add(
192
-				'invalid_state',
193
-				sprintf(
194
-					/* translators: %1$s given state, %2$s valid states */
195
-					__( 'The provided state (%1$s) is not valid. Must be one of: %2$s', 'woocommerce' ),
196
-					esc_html( $address['state'] ),
197
-					implode( ', ', array_keys( $this->get_states_for_country( $address['country'] ) ) )
198
-				)
199
-			);
200
-		}
201
-
202
-		if ( ! empty( $address['postcode'] ) && ! \WC_Validation::is_postcode( $address['postcode'], $address['country'] ) ) {
203
-			$errors->add(
204
-				'invalid_postcode',
205
-				__( 'The provided postcode / ZIP is not valid', 'woocommerce' )
206
-			);
207
-		}
208
-
209
-		if ( ! empty( $address['phone'] ) && ! \WC_Validation::is_phone( $address['phone'] ) ) {
210
-			$errors->add(
211
-				'invalid_phone',
212
-				__( 'The provided phone number is not valid', 'woocommerce' )
213
-			);
214
-		}
215
-
216
-		return $errors->has_errors( $errors ) ? $errors : true;
217
-	}
10
+    /**
11
+     * Term properties.
12
+     *
13
+     * @internal Note that required properties don't require values, just that they are included in the request.
14
+     * @return array
15
+     */
16
+    public function get_properties() {
17
+        return [
18
+            'first_name' => [
19
+                'description' => __( 'First name', 'woocommerce' ),
20
+                'type'        => 'string',
21
+                'context'     => [ 'view', 'edit' ],
22
+                'required'    => true,
23
+            ],
24
+            'last_name'  => [
25
+                'description' => __( 'Last name', 'woocommerce' ),
26
+                'type'        => 'string',
27
+                'context'     => [ 'view', 'edit' ],
28
+                'required'    => true,
29
+            ],
30
+            'company'    => [
31
+                'description' => __( 'Company', 'woocommerce' ),
32
+                'type'        => 'string',
33
+                'context'     => [ 'view', 'edit' ],
34
+                'required'    => true,
35
+            ],
36
+            'address_1'  => [
37
+                'description' => __( 'Address', 'woocommerce' ),
38
+                'type'        => 'string',
39
+                'context'     => [ 'view', 'edit' ],
40
+                'required'    => true,
41
+            ],
42
+            'address_2'  => [
43
+                'description' => __( 'Apartment, suite, etc.', 'woocommerce' ),
44
+                'type'        => 'string',
45
+                'context'     => [ 'view', 'edit' ],
46
+                'required'    => true,
47
+            ],
48
+            'city'       => [
49
+                'description' => __( 'City', 'woocommerce' ),
50
+                'type'        => 'string',
51
+                'context'     => [ 'view', 'edit' ],
52
+                'required'    => true,
53
+            ],
54
+            'state'      => [
55
+                'description' => __( 'State/County code, or name of the state, county, province, or district.', 'woocommerce' ),
56
+                'type'        => 'string',
57
+                'context'     => [ 'view', 'edit' ],
58
+                'required'    => true,
59
+            ],
60
+            'postcode'   => [
61
+                'description' => __( 'Postal code', 'woocommerce' ),
62
+                'type'        => 'string',
63
+                'context'     => [ 'view', 'edit' ],
64
+                'required'    => true,
65
+            ],
66
+            'country'    => [
67
+                'description' => __( 'Country/Region code in ISO 3166-1 alpha-2 format.', 'woocommerce' ),
68
+                'type'        => 'string',
69
+                'context'     => [ 'view', 'edit' ],
70
+                'required'    => true,
71
+            ],
72
+            'phone'      => [
73
+                'description' => __( 'Phone', 'woocommerce' ),
74
+                'type'        => 'string',
75
+                'context'     => [ 'view', 'edit' ],
76
+                'required'    => true,
77
+            ],
78
+        ];
79
+    }
80
+
81
+    /**
82
+     * Sanitize and format the given address object.
83
+     *
84
+     * @param array            $address Value being sanitized.
85
+     * @param \WP_REST_Request $request The Request.
86
+     * @param string           $param The param being sanitized.
87
+     * @return array
88
+     */
89
+    public function sanitize_callback( $address, $request, $param ) {
90
+        $address               = array_merge( array_fill_keys( array_keys( $this->get_properties() ), '' ), (array) $address );
91
+        $address['country']    = wc_strtoupper( wc_clean( wp_unslash( $address['country'] ) ) );
92
+        $address['first_name'] = wc_clean( wp_unslash( $address['first_name'] ) );
93
+        $address['last_name']  = wc_clean( wp_unslash( $address['last_name'] ) );
94
+        $address['company']    = wc_clean( wp_unslash( $address['company'] ) );
95
+        $address['address_1']  = wc_clean( wp_unslash( $address['address_1'] ) );
96
+        $address['address_2']  = wc_clean( wp_unslash( $address['address_2'] ) );
97
+        $address['city']       = wc_clean( wp_unslash( $address['city'] ) );
98
+        $address['state']      = $this->format_state( wc_clean( wp_unslash( $address['state'] ) ), $address['country'] );
99
+        $address['postcode']   = $address['postcode'] ? wc_format_postcode( wc_clean( wp_unslash( $address['postcode'] ) ), $address['country'] ) : '';
100
+        $address['phone']      = wc_clean( wp_unslash( $address['phone'] ) );
101
+        return $address;
102
+    }
103
+
104
+    /**
105
+     * Get list of states for a country.
106
+     *
107
+     * @param string $country Country code.
108
+     * @return array Array of state names indexed by state keys.
109
+     */
110
+    protected function get_states_for_country( $country ) {
111
+        return $country ? array_filter( (array) \wc()->countries->get_states( $country ) ) : [];
112
+    }
113
+
114
+    /**
115
+     * Validate provided state against a countries list of defined states.
116
+     *
117
+     * If there are no defined states for a country, any given state is valid.
118
+     *
119
+     * @param string $state State name or code (sanitized).
120
+     * @param string $country Country code.
121
+     * @return boolean Valid or not valid.
122
+     */
123
+    protected function validate_state( $state, $country ) {
124
+        $states = $this->get_states_for_country( $country );
125
+
126
+        if ( count( $states ) && ! in_array( \wc_strtoupper( $state ), array_map( '\wc_strtoupper', array_keys( $states ) ), true ) ) {
127
+            return false;
128
+        }
129
+
130
+        return true;
131
+    }
132
+
133
+    /**
134
+     * Format a state based on the country. If country has defined states, will return a valid upper case state code.
135
+     *
136
+     * @param string $state State name or code (sanitized).
137
+     * @param string $country Country code.
138
+     * @return string
139
+     */
140
+    protected function format_state( $state, $country ) {
141
+        $states = $this->get_states_for_country( $country );
142
+
143
+        if ( count( $states ) ) {
144
+            $state        = \wc_strtoupper( $state );
145
+            $state_values = array_map( 'wc_strtoupper', array_flip( array_map( '\wc_strtoupper', $states ) ) );
146
+
147
+            if ( isset( $state_values[ $state ] ) ) {
148
+                // Convert to state code if a state name was provided.
149
+                return $state_values[ $state ];
150
+            }
151
+        }
152
+
153
+        return $state;
154
+    }
155
+
156
+    /**
157
+     * Validate the given address object.
158
+     *
159
+     * @see rest_validate_value_from_schema
160
+     *
161
+     * @param array            $address Value being sanitized.
162
+     * @param \WP_REST_Request $request The Request.
163
+     * @param string           $param The param being sanitized.
164
+     * @return true|\WP_Error
165
+     */
166
+    public function validate_callback( $address, $request, $param ) {
167
+        $errors  = new \WP_Error();
168
+        $address = $this->sanitize_callback( $address, $request, $param );
169
+
170
+        if ( empty( $address['country'] ) ) {
171
+            $errors->add(
172
+                'missing_country',
173
+                __( 'Country is required', 'woocommerce' )
174
+            );
175
+            return $errors;
176
+        }
177
+
178
+        if ( ! in_array( $address['country'], array_keys( wc()->countries->get_countries() ), true ) ) {
179
+            $errors->add(
180
+                'invalid_country',
181
+                sprintf(
182
+                    /* translators: %s valid country codes */
183
+                    __( 'Invalid country code provided. Must be one of: %s', 'woocommerce' ),
184
+                    implode( ', ', array_keys( wc()->countries->get_countries() ) )
185
+                )
186
+            );
187
+            return $errors;
188
+        }
189
+
190
+        if ( ! empty( $address['state'] ) && ! $this->validate_state( $address['state'], $address['country'] ) ) {
191
+            $errors->add(
192
+                'invalid_state',
193
+                sprintf(
194
+                    /* translators: %1$s given state, %2$s valid states */
195
+                    __( 'The provided state (%1$s) is not valid. Must be one of: %2$s', 'woocommerce' ),
196
+                    esc_html( $address['state'] ),
197
+                    implode( ', ', array_keys( $this->get_states_for_country( $address['country'] ) ) )
198
+                )
199
+            );
200
+        }
201
+
202
+        if ( ! empty( $address['postcode'] ) && ! \WC_Validation::is_postcode( $address['postcode'], $address['country'] ) ) {
203
+            $errors->add(
204
+                'invalid_postcode',
205
+                __( 'The provided postcode / ZIP is not valid', 'woocommerce' )
206
+            );
207
+        }
208
+
209
+        if ( ! empty( $address['phone'] ) && ! \WC_Validation::is_phone( $address['phone'] ) ) {
210
+            $errors->add(
211
+                'invalid_phone',
212
+                __( 'The provided phone number is not valid', 'woocommerce' )
213
+            );
214
+        }
215
+
216
+        return $errors->has_errors( $errors ) ? $errors : true;
217
+    }
218 218
 }
Please login to merge, or discard this patch.
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -16,63 +16,63 @@  discard block
 block discarded – undo
16 16
 	public function get_properties() {
17 17
 		return [
18 18
 			'first_name' => [
19
-				'description' => __( 'First name', 'woocommerce' ),
19
+				'description' => __('First name', 'woocommerce'),
20 20
 				'type'        => 'string',
21
-				'context'     => [ 'view', 'edit' ],
21
+				'context'     => ['view', 'edit'],
22 22
 				'required'    => true,
23 23
 			],
24 24
 			'last_name'  => [
25
-				'description' => __( 'Last name', 'woocommerce' ),
25
+				'description' => __('Last name', 'woocommerce'),
26 26
 				'type'        => 'string',
27
-				'context'     => [ 'view', 'edit' ],
27
+				'context'     => ['view', 'edit'],
28 28
 				'required'    => true,
29 29
 			],
30 30
 			'company'    => [
31
-				'description' => __( 'Company', 'woocommerce' ),
31
+				'description' => __('Company', 'woocommerce'),
32 32
 				'type'        => 'string',
33
-				'context'     => [ 'view', 'edit' ],
33
+				'context'     => ['view', 'edit'],
34 34
 				'required'    => true,
35 35
 			],
36 36
 			'address_1'  => [
37
-				'description' => __( 'Address', 'woocommerce' ),
37
+				'description' => __('Address', 'woocommerce'),
38 38
 				'type'        => 'string',
39
-				'context'     => [ 'view', 'edit' ],
39
+				'context'     => ['view', 'edit'],
40 40
 				'required'    => true,
41 41
 			],
42 42
 			'address_2'  => [
43
-				'description' => __( 'Apartment, suite, etc.', 'woocommerce' ),
43
+				'description' => __('Apartment, suite, etc.', 'woocommerce'),
44 44
 				'type'        => 'string',
45
-				'context'     => [ 'view', 'edit' ],
45
+				'context'     => ['view', 'edit'],
46 46
 				'required'    => true,
47 47
 			],
48 48
 			'city'       => [
49
-				'description' => __( 'City', 'woocommerce' ),
49
+				'description' => __('City', 'woocommerce'),
50 50
 				'type'        => 'string',
51
-				'context'     => [ 'view', 'edit' ],
51
+				'context'     => ['view', 'edit'],
52 52
 				'required'    => true,
53 53
 			],
54 54
 			'state'      => [
55
-				'description' => __( 'State/County code, or name of the state, county, province, or district.', 'woocommerce' ),
55
+				'description' => __('State/County code, or name of the state, county, province, or district.', 'woocommerce'),
56 56
 				'type'        => 'string',
57
-				'context'     => [ 'view', 'edit' ],
57
+				'context'     => ['view', 'edit'],
58 58
 				'required'    => true,
59 59
 			],
60 60
 			'postcode'   => [
61
-				'description' => __( 'Postal code', 'woocommerce' ),
61
+				'description' => __('Postal code', 'woocommerce'),
62 62
 				'type'        => 'string',
63
-				'context'     => [ 'view', 'edit' ],
63
+				'context'     => ['view', 'edit'],
64 64
 				'required'    => true,
65 65
 			],
66 66
 			'country'    => [
67
-				'description' => __( 'Country/Region code in ISO 3166-1 alpha-2 format.', 'woocommerce' ),
67
+				'description' => __('Country/Region code in ISO 3166-1 alpha-2 format.', 'woocommerce'),
68 68
 				'type'        => 'string',
69
-				'context'     => [ 'view', 'edit' ],
69
+				'context'     => ['view', 'edit'],
70 70
 				'required'    => true,
71 71
 			],
72 72
 			'phone'      => [
73
-				'description' => __( 'Phone', 'woocommerce' ),
73
+				'description' => __('Phone', 'woocommerce'),
74 74
 				'type'        => 'string',
75
-				'context'     => [ 'view', 'edit' ],
75
+				'context'     => ['view', 'edit'],
76 76
 				'required'    => true,
77 77
 			],
78 78
 		];
@@ -86,18 +86,18 @@  discard block
 block discarded – undo
86 86
 	 * @param string           $param The param being sanitized.
87 87
 	 * @return array
88 88
 	 */
89
-	public function sanitize_callback( $address, $request, $param ) {
90
-		$address               = array_merge( array_fill_keys( array_keys( $this->get_properties() ), '' ), (array) $address );
91
-		$address['country']    = wc_strtoupper( wc_clean( wp_unslash( $address['country'] ) ) );
92
-		$address['first_name'] = wc_clean( wp_unslash( $address['first_name'] ) );
93
-		$address['last_name']  = wc_clean( wp_unslash( $address['last_name'] ) );
94
-		$address['company']    = wc_clean( wp_unslash( $address['company'] ) );
95
-		$address['address_1']  = wc_clean( wp_unslash( $address['address_1'] ) );
96
-		$address['address_2']  = wc_clean( wp_unslash( $address['address_2'] ) );
97
-		$address['city']       = wc_clean( wp_unslash( $address['city'] ) );
98
-		$address['state']      = $this->format_state( wc_clean( wp_unslash( $address['state'] ) ), $address['country'] );
99
-		$address['postcode']   = $address['postcode'] ? wc_format_postcode( wc_clean( wp_unslash( $address['postcode'] ) ), $address['country'] ) : '';
100
-		$address['phone']      = wc_clean( wp_unslash( $address['phone'] ) );
89
+	public function sanitize_callback($address, $request, $param) {
90
+		$address               = array_merge(array_fill_keys(array_keys($this->get_properties()), ''), (array) $address);
91
+		$address['country']    = wc_strtoupper(wc_clean(wp_unslash($address['country'])));
92
+		$address['first_name'] = wc_clean(wp_unslash($address['first_name']));
93
+		$address['last_name']  = wc_clean(wp_unslash($address['last_name']));
94
+		$address['company']    = wc_clean(wp_unslash($address['company']));
95
+		$address['address_1']  = wc_clean(wp_unslash($address['address_1']));
96
+		$address['address_2']  = wc_clean(wp_unslash($address['address_2']));
97
+		$address['city']       = wc_clean(wp_unslash($address['city']));
98
+		$address['state']      = $this->format_state(wc_clean(wp_unslash($address['state'])), $address['country']);
99
+		$address['postcode']   = $address['postcode'] ? wc_format_postcode(wc_clean(wp_unslash($address['postcode'])), $address['country']) : '';
100
+		$address['phone']      = wc_clean(wp_unslash($address['phone']));
101 101
 		return $address;
102 102
 	}
103 103
 
@@ -107,8 +107,8 @@  discard block
 block discarded – undo
107 107
 	 * @param string $country Country code.
108 108
 	 * @return array Array of state names indexed by state keys.
109 109
 	 */
110
-	protected function get_states_for_country( $country ) {
111
-		return $country ? array_filter( (array) \wc()->countries->get_states( $country ) ) : [];
110
+	protected function get_states_for_country($country) {
111
+		return $country ? array_filter((array) \wc()->countries->get_states($country)) : [];
112 112
 	}
113 113
 
114 114
 	/**
@@ -120,10 +120,10 @@  discard block
 block discarded – undo
120 120
 	 * @param string $country Country code.
121 121
 	 * @return boolean Valid or not valid.
122 122
 	 */
123
-	protected function validate_state( $state, $country ) {
124
-		$states = $this->get_states_for_country( $country );
123
+	protected function validate_state($state, $country) {
124
+		$states = $this->get_states_for_country($country);
125 125
 
126
-		if ( count( $states ) && ! in_array( \wc_strtoupper( $state ), array_map( '\wc_strtoupper', array_keys( $states ) ), true ) ) {
126
+		if (count($states) && !in_array(\wc_strtoupper($state), array_map('\wc_strtoupper', array_keys($states)), true)) {
127 127
 			return false;
128 128
 		}
129 129
 
@@ -137,16 +137,16 @@  discard block
 block discarded – undo
137 137
 	 * @param string $country Country code.
138 138
 	 * @return string
139 139
 	 */
140
-	protected function format_state( $state, $country ) {
141
-		$states = $this->get_states_for_country( $country );
140
+	protected function format_state($state, $country) {
141
+		$states = $this->get_states_for_country($country);
142 142
 
143
-		if ( count( $states ) ) {
144
-			$state        = \wc_strtoupper( $state );
145
-			$state_values = array_map( 'wc_strtoupper', array_flip( array_map( '\wc_strtoupper', $states ) ) );
143
+		if (count($states)) {
144
+			$state        = \wc_strtoupper($state);
145
+			$state_values = array_map('wc_strtoupper', array_flip(array_map('\wc_strtoupper', $states)));
146 146
 
147
-			if ( isset( $state_values[ $state ] ) ) {
147
+			if (isset($state_values[$state])) {
148 148
 				// Convert to state code if a state name was provided.
149
-				return $state_values[ $state ];
149
+				return $state_values[$state];
150 150
 			}
151 151
 		}
152 152
 
@@ -163,56 +163,56 @@  discard block
 block discarded – undo
163 163
 	 * @param string           $param The param being sanitized.
164 164
 	 * @return true|\WP_Error
165 165
 	 */
166
-	public function validate_callback( $address, $request, $param ) {
166
+	public function validate_callback($address, $request, $param) {
167 167
 		$errors  = new \WP_Error();
168
-		$address = $this->sanitize_callback( $address, $request, $param );
168
+		$address = $this->sanitize_callback($address, $request, $param);
169 169
 
170
-		if ( empty( $address['country'] ) ) {
170
+		if (empty($address['country'])) {
171 171
 			$errors->add(
172 172
 				'missing_country',
173
-				__( 'Country is required', 'woocommerce' )
173
+				__('Country is required', 'woocommerce')
174 174
 			);
175 175
 			return $errors;
176 176
 		}
177 177
 
178
-		if ( ! in_array( $address['country'], array_keys( wc()->countries->get_countries() ), true ) ) {
178
+		if (!in_array($address['country'], array_keys(wc()->countries->get_countries()), true)) {
179 179
 			$errors->add(
180 180
 				'invalid_country',
181 181
 				sprintf(
182 182
 					/* translators: %s valid country codes */
183
-					__( 'Invalid country code provided. Must be one of: %s', 'woocommerce' ),
184
-					implode( ', ', array_keys( wc()->countries->get_countries() ) )
183
+					__('Invalid country code provided. Must be one of: %s', 'woocommerce'),
184
+					implode(', ', array_keys(wc()->countries->get_countries()))
185 185
 				)
186 186
 			);
187 187
 			return $errors;
188 188
 		}
189 189
 
190
-		if ( ! empty( $address['state'] ) && ! $this->validate_state( $address['state'], $address['country'] ) ) {
190
+		if (!empty($address['state']) && !$this->validate_state($address['state'], $address['country'])) {
191 191
 			$errors->add(
192 192
 				'invalid_state',
193 193
 				sprintf(
194 194
 					/* translators: %1$s given state, %2$s valid states */
195
-					__( 'The provided state (%1$s) is not valid. Must be one of: %2$s', 'woocommerce' ),
196
-					esc_html( $address['state'] ),
197
-					implode( ', ', array_keys( $this->get_states_for_country( $address['country'] ) ) )
195
+					__('The provided state (%1$s) is not valid. Must be one of: %2$s', 'woocommerce'),
196
+					esc_html($address['state']),
197
+					implode(', ', array_keys($this->get_states_for_country($address['country'])))
198 198
 				)
199 199
 			);
200 200
 		}
201 201
 
202
-		if ( ! empty( $address['postcode'] ) && ! \WC_Validation::is_postcode( $address['postcode'], $address['country'] ) ) {
202
+		if (!empty($address['postcode']) && !\WC_Validation::is_postcode($address['postcode'], $address['country'])) {
203 203
 			$errors->add(
204 204
 				'invalid_postcode',
205
-				__( 'The provided postcode / ZIP is not valid', 'woocommerce' )
205
+				__('The provided postcode / ZIP is not valid', 'woocommerce')
206 206
 			);
207 207
 		}
208 208
 
209
-		if ( ! empty( $address['phone'] ) && ! \WC_Validation::is_phone( $address['phone'] ) ) {
209
+		if (!empty($address['phone']) && !\WC_Validation::is_phone($address['phone'])) {
210 210
 			$errors->add(
211 211
 				'invalid_phone',
212
-				__( 'The provided phone number is not valid', 'woocommerce' )
212
+				__('The provided phone number is not valid', 'woocommerce')
213 213
 			);
214 214
 		}
215 215
 
216
-		return $errors->has_errors( $errors ) ? $errors : true;
216
+		return $errors->has_errors($errors) ? $errors : true;
217 217
 	}
218 218
 }
Please login to merge, or discard this patch.
woocommerce-blocks/src/StoreApi/Schemas/V1/CartExtensionsSchema.php 2 patches
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -7,50 +7,50 @@
 block discarded – undo
7 7
  * Class CartExtensionsSchema
8 8
  */
9 9
 class CartExtensionsSchema extends AbstractSchema {
10
-	/**
11
-	 * The schema item name.
12
-	 *
13
-	 * @var string
14
-	 */
15
-	protected $title = 'cart-extensions';
10
+    /**
11
+     * The schema item name.
12
+     *
13
+     * @var string
14
+     */
15
+    protected $title = 'cart-extensions';
16 16
 
17
-	/**
18
-	 * The schema item identifier.
19
-	 *
20
-	 * @var string
21
-	 */
22
-	const IDENTIFIER = 'cart-extensions';
17
+    /**
18
+     * The schema item identifier.
19
+     *
20
+     * @var string
21
+     */
22
+    const IDENTIFIER = 'cart-extensions';
23 23
 
24
-	/**
25
-	 * Cart extensions schema properties.
26
-	 *
27
-	 * @return array
28
-	 */
29
-	public function get_properties() {
30
-		return [];
31
-	}
24
+    /**
25
+     * Cart extensions schema properties.
26
+     *
27
+     * @return array
28
+     */
29
+    public function get_properties() {
30
+        return [];
31
+    }
32 32
 
33
-	/**
34
-	 * Handle the request and return a valid response for this endpoint.
35
-	 *
36
-	 * @param \WP_REST_Request $request Request containing data for the extension callback.
37
-	 * @throws RouteException When callback is not callable or parameters are incorrect.
38
-	 *
39
-	 * @return array
40
-	 */
41
-	public function get_item_response( $request = null ) {
42
-		try {
43
-			$callback = $this->extend->get_update_callback( $request['namespace'] );
44
-		} catch ( \Exception $e ) {
45
-			throw new RouteException(
46
-				'woocommerce_rest_cart_extensions_error',
47
-				$e->getMessage(),
48
-				400
49
-			);
50
-		}
51
-		if ( is_callable( $callback ) ) {
52
-			$callback( $request['data'] );
53
-		}
54
-		return rest_ensure_response( wc()->api->get_endpoint_data( '/wc/store/v1/cart' ) );
55
-	}
33
+    /**
34
+     * Handle the request and return a valid response for this endpoint.
35
+     *
36
+     * @param \WP_REST_Request $request Request containing data for the extension callback.
37
+     * @throws RouteException When callback is not callable or parameters are incorrect.
38
+     *
39
+     * @return array
40
+     */
41
+    public function get_item_response( $request = null ) {
42
+        try {
43
+            $callback = $this->extend->get_update_callback( $request['namespace'] );
44
+        } catch ( \Exception $e ) {
45
+            throw new RouteException(
46
+                'woocommerce_rest_cart_extensions_error',
47
+                $e->getMessage(),
48
+                400
49
+            );
50
+        }
51
+        if ( is_callable( $callback ) ) {
52
+            $callback( $request['data'] );
53
+        }
54
+        return rest_ensure_response( wc()->api->get_endpoint_data( '/wc/store/v1/cart' ) );
55
+    }
56 56
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -38,19 +38,19 @@
 block discarded – undo
38 38
 	 *
39 39
 	 * @return array
40 40
 	 */
41
-	public function get_item_response( $request = null ) {
41
+	public function get_item_response($request = null) {
42 42
 		try {
43
-			$callback = $this->extend->get_update_callback( $request['namespace'] );
44
-		} catch ( \Exception $e ) {
43
+			$callback = $this->extend->get_update_callback($request['namespace']);
44
+		} catch (\Exception $e) {
45 45
 			throw new RouteException(
46 46
 				'woocommerce_rest_cart_extensions_error',
47 47
 				$e->getMessage(),
48 48
 				400
49 49
 			);
50 50
 		}
51
-		if ( is_callable( $callback ) ) {
52
-			$callback( $request['data'] );
51
+		if (is_callable($callback)) {
52
+			$callback($request['data']);
53 53
 		}
54
-		return rest_ensure_response( wc()->api->get_endpoint_data( '/wc/store/v1/cart' ) );
54
+		return rest_ensure_response(wc()->api->get_endpoint_data('/wc/store/v1/cart'));
55 55
 	}
56 56
 }
Please login to merge, or discard this patch.
packages/woocommerce-blocks/src/StoreApi/Schemas/V1/CartCouponSchema.php 2 patches
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -7,102 +7,102 @@
 block discarded – undo
7 7
  * CartCouponSchema class.
8 8
  */
9 9
 class CartCouponSchema extends AbstractSchema {
10
-	/**
11
-	 * The schema item name.
12
-	 *
13
-	 * @var string
14
-	 */
15
-	protected $title = 'cart_coupon';
10
+    /**
11
+     * The schema item name.
12
+     *
13
+     * @var string
14
+     */
15
+    protected $title = 'cart_coupon';
16 16
 
17
-	/**
18
-	 * The schema item identifier.
19
-	 *
20
-	 * @var string
21
-	 */
22
-	const IDENTIFIER = 'cart-coupon';
17
+    /**
18
+     * The schema item identifier.
19
+     *
20
+     * @var string
21
+     */
22
+    const IDENTIFIER = 'cart-coupon';
23 23
 
24
-	/**
25
-	 * Cart schema properties.
26
-	 *
27
-	 * @return array
28
-	 */
29
-	public function get_properties() {
30
-		return [
31
-			'code'          => [
32
-				'description' => __( 'The coupon\'s unique code.', 'woocommerce' ),
33
-				'type'        => 'string',
34
-				'context'     => [ 'view', 'edit' ],
35
-				'arg_options' => [
36
-					'sanitize_callback' => 'wc_format_coupon_code',
37
-					'validate_callback' => [ $this, 'coupon_exists' ],
38
-				],
39
-			],
40
-			'discount_type' => [
41
-				'description' => __( 'The discount type for the coupon (e.g. percentage or fixed amount)', 'woocommerce' ),
42
-				'type'        => 'string',
43
-				'context'     => [ 'view', 'edit' ],
44
-				'arg_options' => [
45
-					'validate_callback' => [ $this, 'coupon_exists' ],
46
-				],
47
-			],
48
-			'totals'        => [
49
-				'description' => __( 'Total amounts provided using the smallest unit of the currency.', 'woocommerce' ),
50
-				'type'        => 'object',
51
-				'context'     => [ 'view', 'edit' ],
52
-				'readonly'    => true,
53
-				'properties'  => array_merge(
54
-					$this->get_store_currency_properties(),
55
-					[
56
-						'total_discount'     => [
57
-							'description' => __( 'Total discount applied by this coupon.', 'woocommerce' ),
58
-							'type'        => 'string',
59
-							'context'     => [ 'view', 'edit' ],
60
-							'readonly'    => true,
61
-						],
62
-						'total_discount_tax' => [
63
-							'description' => __( 'Total tax removed due to discount applied by this coupon.', 'woocommerce' ),
64
-							'type'        => 'string',
65
-							'context'     => [ 'view', 'edit' ],
66
-							'readonly'    => true,
67
-						],
68
-					]
69
-				),
70
-			],
71
-		];
72
-	}
24
+    /**
25
+     * Cart schema properties.
26
+     *
27
+     * @return array
28
+     */
29
+    public function get_properties() {
30
+        return [
31
+            'code'          => [
32
+                'description' => __( 'The coupon\'s unique code.', 'woocommerce' ),
33
+                'type'        => 'string',
34
+                'context'     => [ 'view', 'edit' ],
35
+                'arg_options' => [
36
+                    'sanitize_callback' => 'wc_format_coupon_code',
37
+                    'validate_callback' => [ $this, 'coupon_exists' ],
38
+                ],
39
+            ],
40
+            'discount_type' => [
41
+                'description' => __( 'The discount type for the coupon (e.g. percentage or fixed amount)', 'woocommerce' ),
42
+                'type'        => 'string',
43
+                'context'     => [ 'view', 'edit' ],
44
+                'arg_options' => [
45
+                    'validate_callback' => [ $this, 'coupon_exists' ],
46
+                ],
47
+            ],
48
+            'totals'        => [
49
+                'description' => __( 'Total amounts provided using the smallest unit of the currency.', 'woocommerce' ),
50
+                'type'        => 'object',
51
+                'context'     => [ 'view', 'edit' ],
52
+                'readonly'    => true,
53
+                'properties'  => array_merge(
54
+                    $this->get_store_currency_properties(),
55
+                    [
56
+                        'total_discount'     => [
57
+                            'description' => __( 'Total discount applied by this coupon.', 'woocommerce' ),
58
+                            'type'        => 'string',
59
+                            'context'     => [ 'view', 'edit' ],
60
+                            'readonly'    => true,
61
+                        ],
62
+                        'total_discount_tax' => [
63
+                            'description' => __( 'Total tax removed due to discount applied by this coupon.', 'woocommerce' ),
64
+                            'type'        => 'string',
65
+                            'context'     => [ 'view', 'edit' ],
66
+                            'readonly'    => true,
67
+                        ],
68
+                    ]
69
+                ),
70
+            ],
71
+        ];
72
+    }
73 73
 
74
-	/**
75
-	 * Check given coupon exists.
76
-	 *
77
-	 * @param string $coupon_code Coupon code.
78
-	 * @return bool
79
-	 */
80
-	public function coupon_exists( $coupon_code ) {
81
-		$coupon = new \WC_Coupon( $coupon_code );
82
-		return (bool) $coupon->get_id() || $coupon->get_virtual();
83
-	}
74
+    /**
75
+     * Check given coupon exists.
76
+     *
77
+     * @param string $coupon_code Coupon code.
78
+     * @return bool
79
+     */
80
+    public function coupon_exists( $coupon_code ) {
81
+        $coupon = new \WC_Coupon( $coupon_code );
82
+        return (bool) $coupon->get_id() || $coupon->get_virtual();
83
+    }
84 84
 
85
-	/**
86
-	 * Generate a response from passed coupon code.
87
-	 *
88
-	 * @param string $coupon_code Coupon code from the cart.
89
-	 * @return array
90
-	 */
91
-	public function get_item_response( $coupon_code ) {
92
-		$controller           = new CartController();
93
-		$cart                 = $controller->get_cart_instance();
94
-		$total_discounts      = $cart->get_coupon_discount_totals();
95
-		$total_discount_taxes = $cart->get_coupon_discount_tax_totals();
96
-		$coupon               = new \WC_Coupon( $coupon_code );
97
-		return [
98
-			'code'          => $coupon_code,
99
-			'discount_type' => $coupon->get_discount_type(),
100
-			'totals'        => (object) $this->prepare_currency_response(
101
-				[
102
-					'total_discount'     => $this->prepare_money_response( isset( $total_discounts[ $coupon_code ] ) ? $total_discounts[ $coupon_code ] : 0, wc_get_price_decimals() ),
103
-					'total_discount_tax' => $this->prepare_money_response( isset( $total_discount_taxes[ $coupon_code ] ) ? $total_discount_taxes[ $coupon_code ] : 0, wc_get_price_decimals(), PHP_ROUND_HALF_DOWN ),
104
-				]
105
-			),
106
-		];
107
-	}
85
+    /**
86
+     * Generate a response from passed coupon code.
87
+     *
88
+     * @param string $coupon_code Coupon code from the cart.
89
+     * @return array
90
+     */
91
+    public function get_item_response( $coupon_code ) {
92
+        $controller           = new CartController();
93
+        $cart                 = $controller->get_cart_instance();
94
+        $total_discounts      = $cart->get_coupon_discount_totals();
95
+        $total_discount_taxes = $cart->get_coupon_discount_tax_totals();
96
+        $coupon               = new \WC_Coupon( $coupon_code );
97
+        return [
98
+            'code'          => $coupon_code,
99
+            'discount_type' => $coupon->get_discount_type(),
100
+            'totals'        => (object) $this->prepare_currency_response(
101
+                [
102
+                    'total_discount'     => $this->prepare_money_response( isset( $total_discounts[ $coupon_code ] ) ? $total_discounts[ $coupon_code ] : 0, wc_get_price_decimals() ),
103
+                    'total_discount_tax' => $this->prepare_money_response( isset( $total_discount_taxes[ $coupon_code ] ) ? $total_discount_taxes[ $coupon_code ] : 0, wc_get_price_decimals(), PHP_ROUND_HALF_DOWN ),
104
+                ]
105
+            ),
106
+        ];
107
+    }
108 108
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -29,40 +29,40 @@  discard block
 block discarded – undo
29 29
 	public function get_properties() {
30 30
 		return [
31 31
 			'code'          => [
32
-				'description' => __( 'The coupon\'s unique code.', 'woocommerce' ),
32
+				'description' => __('The coupon\'s unique code.', 'woocommerce'),
33 33
 				'type'        => 'string',
34
-				'context'     => [ 'view', 'edit' ],
34
+				'context'     => ['view', 'edit'],
35 35
 				'arg_options' => [
36 36
 					'sanitize_callback' => 'wc_format_coupon_code',
37
-					'validate_callback' => [ $this, 'coupon_exists' ],
37
+					'validate_callback' => [$this, 'coupon_exists'],
38 38
 				],
39 39
 			],
40 40
 			'discount_type' => [
41
-				'description' => __( 'The discount type for the coupon (e.g. percentage or fixed amount)', 'woocommerce' ),
41
+				'description' => __('The discount type for the coupon (e.g. percentage or fixed amount)', 'woocommerce'),
42 42
 				'type'        => 'string',
43
-				'context'     => [ 'view', 'edit' ],
43
+				'context'     => ['view', 'edit'],
44 44
 				'arg_options' => [
45
-					'validate_callback' => [ $this, 'coupon_exists' ],
45
+					'validate_callback' => [$this, 'coupon_exists'],
46 46
 				],
47 47
 			],
48 48
 			'totals'        => [
49
-				'description' => __( 'Total amounts provided using the smallest unit of the currency.', 'woocommerce' ),
49
+				'description' => __('Total amounts provided using the smallest unit of the currency.', 'woocommerce'),
50 50
 				'type'        => 'object',
51
-				'context'     => [ 'view', 'edit' ],
51
+				'context'     => ['view', 'edit'],
52 52
 				'readonly'    => true,
53 53
 				'properties'  => array_merge(
54 54
 					$this->get_store_currency_properties(),
55 55
 					[
56 56
 						'total_discount'     => [
57
-							'description' => __( 'Total discount applied by this coupon.', 'woocommerce' ),
57
+							'description' => __('Total discount applied by this coupon.', 'woocommerce'),
58 58
 							'type'        => 'string',
59
-							'context'     => [ 'view', 'edit' ],
59
+							'context'     => ['view', 'edit'],
60 60
 							'readonly'    => true,
61 61
 						],
62 62
 						'total_discount_tax' => [
63
-							'description' => __( 'Total tax removed due to discount applied by this coupon.', 'woocommerce' ),
63
+							'description' => __('Total tax removed due to discount applied by this coupon.', 'woocommerce'),
64 64
 							'type'        => 'string',
65
-							'context'     => [ 'view', 'edit' ],
65
+							'context'     => ['view', 'edit'],
66 66
 							'readonly'    => true,
67 67
 						],
68 68
 					]
@@ -77,8 +77,8 @@  discard block
 block discarded – undo
77 77
 	 * @param string $coupon_code Coupon code.
78 78
 	 * @return bool
79 79
 	 */
80
-	public function coupon_exists( $coupon_code ) {
81
-		$coupon = new \WC_Coupon( $coupon_code );
80
+	public function coupon_exists($coupon_code) {
81
+		$coupon = new \WC_Coupon($coupon_code);
82 82
 		return (bool) $coupon->get_id() || $coupon->get_virtual();
83 83
 	}
84 84
 
@@ -88,19 +88,19 @@  discard block
 block discarded – undo
88 88
 	 * @param string $coupon_code Coupon code from the cart.
89 89
 	 * @return array
90 90
 	 */
91
-	public function get_item_response( $coupon_code ) {
91
+	public function get_item_response($coupon_code) {
92 92
 		$controller           = new CartController();
93 93
 		$cart                 = $controller->get_cart_instance();
94 94
 		$total_discounts      = $cart->get_coupon_discount_totals();
95 95
 		$total_discount_taxes = $cart->get_coupon_discount_tax_totals();
96
-		$coupon               = new \WC_Coupon( $coupon_code );
96
+		$coupon               = new \WC_Coupon($coupon_code);
97 97
 		return [
98 98
 			'code'          => $coupon_code,
99 99
 			'discount_type' => $coupon->get_discount_type(),
100 100
 			'totals'        => (object) $this->prepare_currency_response(
101 101
 				[
102
-					'total_discount'     => $this->prepare_money_response( isset( $total_discounts[ $coupon_code ] ) ? $total_discounts[ $coupon_code ] : 0, wc_get_price_decimals() ),
103
-					'total_discount_tax' => $this->prepare_money_response( isset( $total_discount_taxes[ $coupon_code ] ) ? $total_discount_taxes[ $coupon_code ] : 0, wc_get_price_decimals(), PHP_ROUND_HALF_DOWN ),
102
+					'total_discount'     => $this->prepare_money_response(isset($total_discounts[$coupon_code]) ? $total_discounts[$coupon_code] : 0, wc_get_price_decimals()),
103
+					'total_discount_tax' => $this->prepare_money_response(isset($total_discount_taxes[$coupon_code]) ? $total_discount_taxes[$coupon_code] : 0, wc_get_price_decimals(), PHP_ROUND_HALF_DOWN),
104 104
 				]
105 105
 			),
106 106
 		];
Please login to merge, or discard this patch.
plugins/woocommerce/packages/woocommerce-blocks/src/StoreApi/deprecated.php 1 patch
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -6,62 +6,62 @@
 block discarded – undo
6 6
  */
7 7
 
8 8
 // Map old to new namespaces for utils and exceptions.
9
-class_alias( Automattic\WooCommerce\StoreApi\Exceptions\RouteException::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\RouteException::class );
10
-class_alias( Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema::class, Automattic\WooCommerce\Blocks\Domain\Services\ExtendRestApi::class );
11
-class_alias( Automattic\WooCommerce\StoreApi\SchemaController::class, Automattic\WooCommerce\Blocks\StoreApi\SchemaController::class );
12
-class_alias( Automattic\WooCommerce\StoreApi\RoutesController::class, Automattic\WooCommerce\Blocks\StoreApi\RoutesController::class );
13
-class_alias( Automattic\WooCommerce\StoreApi\Formatters::class, Automattic\WooCommerce\Blocks\StoreApi\Formatters::class );
14
-class_alias( Automattic\WooCommerce\StoreApi\Payments\PaymentResult::class, Automattic\WooCommerce\Blocks\Payments\PaymentResult::class );
15
-class_alias( Automattic\WooCommerce\StoreApi\Payments\PaymentContext::class, Automattic\WooCommerce\Blocks\Payments\PaymentContext::class );
9
+class_alias(Automattic\WooCommerce\StoreApi\Exceptions\RouteException::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\RouteException::class);
10
+class_alias(Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema::class, Automattic\WooCommerce\Blocks\Domain\Services\ExtendRestApi::class);
11
+class_alias(Automattic\WooCommerce\StoreApi\SchemaController::class, Automattic\WooCommerce\Blocks\StoreApi\SchemaController::class);
12
+class_alias(Automattic\WooCommerce\StoreApi\RoutesController::class, Automattic\WooCommerce\Blocks\StoreApi\RoutesController::class);
13
+class_alias(Automattic\WooCommerce\StoreApi\Formatters::class, Automattic\WooCommerce\Blocks\StoreApi\Formatters::class);
14
+class_alias(Automattic\WooCommerce\StoreApi\Payments\PaymentResult::class, Automattic\WooCommerce\Blocks\Payments\PaymentResult::class);
15
+class_alias(Automattic\WooCommerce\StoreApi\Payments\PaymentContext::class, Automattic\WooCommerce\Blocks\Payments\PaymentContext::class);
16 16
 
17 17
 // Map old schemas to V1 schemas under new namespace.
18
-class_alias( Automattic\WooCommerce\StoreApi\Schemas\V1\AbstractAddressSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\AbstractAddressSchema::class );
19
-class_alias( Automattic\WooCommerce\StoreApi\Schemas\V1\AbstractSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\AbstractSchema::class );
20
-class_alias( Automattic\WooCommerce\StoreApi\Schemas\V1\BillingAddressSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\BillingAddressSchema::class );
21
-class_alias( Automattic\WooCommerce\StoreApi\Schemas\V1\CartCouponSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\CartCouponSchema::class );
22
-class_alias( Automattic\WooCommerce\StoreApi\Schemas\V1\CartExtensionsSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\CartExtensionsSchema::class );
23
-class_alias( Automattic\WooCommerce\StoreApi\Schemas\V1\CartFeeSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\CartFeeSchema::class );
24
-class_alias( Automattic\WooCommerce\StoreApi\Schemas\V1\CartItemSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\CartItemSchema::class );
25
-class_alias( Automattic\WooCommerce\StoreApi\Schemas\V1\CartSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\CartSchema::class );
26
-class_alias( Automattic\WooCommerce\StoreApi\Schemas\V1\CartShippingRateSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\CartShippingRateSchema::class );
27
-class_alias( Automattic\WooCommerce\StoreApi\Schemas\V1\CheckoutSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\CheckoutSchema::class );
28
-class_alias( Automattic\WooCommerce\StoreApi\Schemas\V1\ErrorSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\ErrorSchema::class );
29
-class_alias( Automattic\WooCommerce\StoreApi\Schemas\V1\ImageAttachmentSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\ImageAttachmentSchema::class );
30
-class_alias( Automattic\WooCommerce\StoreApi\Schemas\V1\OrderCouponSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\OrderCouponSchema::class );
31
-class_alias( Automattic\WooCommerce\StoreApi\Schemas\V1\ProductAttributeSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\ProductAttributeSchema::class );
32
-class_alias( Automattic\WooCommerce\StoreApi\Schemas\V1\ProductCategorySchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\ProductCategorySchema::class );
33
-class_alias( Automattic\WooCommerce\StoreApi\Schemas\V1\ProductCollectionDataSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\ProductCollectionDataSchema::class );
34
-class_alias( Automattic\WooCommerce\StoreApi\Schemas\V1\ProductReviewSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\ProductReviewSchema::class );
35
-class_alias( Automattic\WooCommerce\StoreApi\Schemas\V1\ProductSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\ProductSchema::class );
36
-class_alias( Automattic\WooCommerce\StoreApi\Schemas\V1\ShippingAddressSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\ShippingAddressSchema::class );
37
-class_alias( Automattic\WooCommerce\StoreApi\Schemas\V1\TermSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\TermSchema::class );
18
+class_alias(Automattic\WooCommerce\StoreApi\Schemas\V1\AbstractAddressSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\AbstractAddressSchema::class);
19
+class_alias(Automattic\WooCommerce\StoreApi\Schemas\V1\AbstractSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\AbstractSchema::class);
20
+class_alias(Automattic\WooCommerce\StoreApi\Schemas\V1\BillingAddressSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\BillingAddressSchema::class);
21
+class_alias(Automattic\WooCommerce\StoreApi\Schemas\V1\CartCouponSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\CartCouponSchema::class);
22
+class_alias(Automattic\WooCommerce\StoreApi\Schemas\V1\CartExtensionsSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\CartExtensionsSchema::class);
23
+class_alias(Automattic\WooCommerce\StoreApi\Schemas\V1\CartFeeSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\CartFeeSchema::class);
24
+class_alias(Automattic\WooCommerce\StoreApi\Schemas\V1\CartItemSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\CartItemSchema::class);
25
+class_alias(Automattic\WooCommerce\StoreApi\Schemas\V1\CartSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\CartSchema::class);
26
+class_alias(Automattic\WooCommerce\StoreApi\Schemas\V1\CartShippingRateSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\CartShippingRateSchema::class);
27
+class_alias(Automattic\WooCommerce\StoreApi\Schemas\V1\CheckoutSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\CheckoutSchema::class);
28
+class_alias(Automattic\WooCommerce\StoreApi\Schemas\V1\ErrorSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\ErrorSchema::class);
29
+class_alias(Automattic\WooCommerce\StoreApi\Schemas\V1\ImageAttachmentSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\ImageAttachmentSchema::class);
30
+class_alias(Automattic\WooCommerce\StoreApi\Schemas\V1\OrderCouponSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\OrderCouponSchema::class);
31
+class_alias(Automattic\WooCommerce\StoreApi\Schemas\V1\ProductAttributeSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\ProductAttributeSchema::class);
32
+class_alias(Automattic\WooCommerce\StoreApi\Schemas\V1\ProductCategorySchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\ProductCategorySchema::class);
33
+class_alias(Automattic\WooCommerce\StoreApi\Schemas\V1\ProductCollectionDataSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\ProductCollectionDataSchema::class);
34
+class_alias(Automattic\WooCommerce\StoreApi\Schemas\V1\ProductReviewSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\ProductReviewSchema::class);
35
+class_alias(Automattic\WooCommerce\StoreApi\Schemas\V1\ProductSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\ProductSchema::class);
36
+class_alias(Automattic\WooCommerce\StoreApi\Schemas\V1\ShippingAddressSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\ShippingAddressSchema::class);
37
+class_alias(Automattic\WooCommerce\StoreApi\Schemas\V1\TermSchema::class, Automattic\WooCommerce\Blocks\StoreApi\Schemas\TermSchema::class);
38 38
 
39 39
 // Map old routes to V1 routes under new namespace.
40
-class_alias( Automattic\WooCommerce\StoreApi\Routes\V1\AbstractCartRoute::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\AbstractCartRoute::class );
41
-class_alias( Automattic\WooCommerce\StoreApi\Routes\V1\AbstractRoute::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\AbstractRoute::class );
42
-class_alias( Automattic\WooCommerce\StoreApi\Routes\V1\AbstractTermsRoute::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\AbstractTermsRoute::class );
43
-class_alias( Automattic\WooCommerce\StoreApi\Routes\V1\Batch::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\Batch::class );
44
-class_alias( Automattic\WooCommerce\StoreApi\Routes\V1\Cart::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\Cart::class );
45
-class_alias( Automattic\WooCommerce\StoreApi\Routes\V1\CartAddItem::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\CartAddItem::class );
46
-class_alias( Automattic\WooCommerce\StoreApi\Routes\V1\CartApplyCoupon::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\CartApplyCoupon::class );
47
-class_alias( Automattic\WooCommerce\StoreApi\Routes\V1\CartCoupons::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\CartCoupons::class );
48
-class_alias( Automattic\WooCommerce\StoreApi\Routes\V1\CartCouponsByCode::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\CartCouponsByCode::class );
49
-class_alias( Automattic\WooCommerce\StoreApi\Routes\V1\CartExtensions::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\CartExtensions::class );
50
-class_alias( Automattic\WooCommerce\StoreApi\Routes\V1\CartItems::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\CartItems::class );
51
-class_alias( Automattic\WooCommerce\StoreApi\Routes\V1\CartItemsByKey::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\CartItemsByKey::class );
52
-class_alias( Automattic\WooCommerce\StoreApi\Routes\V1\CartRemoveCoupon::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\CartRemoveCoupon::class );
53
-class_alias( Automattic\WooCommerce\StoreApi\Routes\V1\CartRemoveItem::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\CartRemoveItem::class );
54
-class_alias( Automattic\WooCommerce\StoreApi\Routes\V1\CartSelectShippingRate::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\CartSelectShippingRate::class );
55
-class_alias( Automattic\WooCommerce\StoreApi\Routes\V1\CartUpdateCustomer::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\CartUpdateCustomer::class );
56
-class_alias( Automattic\WooCommerce\StoreApi\Routes\V1\CartUpdateItem::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\CartUpdateItem::class );
57
-class_alias( Automattic\WooCommerce\StoreApi\Routes\V1\Checkout::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\Checkout::class );
58
-class_alias( Automattic\WooCommerce\StoreApi\Routes\V1\ProductAttributes::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\ProductAttributes::class );
59
-class_alias( Automattic\WooCommerce\StoreApi\Routes\V1\ProductAttributesById::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\ProductAttributesById::class );
60
-class_alias( Automattic\WooCommerce\StoreApi\Routes\V1\ProductAttributeTerms::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\ProductAttributeTerms::class );
61
-class_alias( Automattic\WooCommerce\StoreApi\Routes\V1\ProductCategories::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\ProductCategories::class );
62
-class_alias( Automattic\WooCommerce\StoreApi\Routes\V1\ProductCategoriesById::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\ProductCategoriesById::class );
63
-class_alias( Automattic\WooCommerce\StoreApi\Routes\V1\ProductCollectionData::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\ProductCollectionData::class );
64
-class_alias( Automattic\WooCommerce\StoreApi\Routes\V1\ProductReviews::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\ProductReviews::class );
65
-class_alias( Automattic\WooCommerce\StoreApi\Routes\V1\Products::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\Products::class );
66
-class_alias( Automattic\WooCommerce\StoreApi\Routes\V1\ProductsById::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\ProductsById::class );
67
-class_alias( Automattic\WooCommerce\StoreApi\Routes\V1\ProductTags::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\ProductTags::class );
40
+class_alias(Automattic\WooCommerce\StoreApi\Routes\V1\AbstractCartRoute::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\AbstractCartRoute::class);
41
+class_alias(Automattic\WooCommerce\StoreApi\Routes\V1\AbstractRoute::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\AbstractRoute::class);
42
+class_alias(Automattic\WooCommerce\StoreApi\Routes\V1\AbstractTermsRoute::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\AbstractTermsRoute::class);
43
+class_alias(Automattic\WooCommerce\StoreApi\Routes\V1\Batch::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\Batch::class);
44
+class_alias(Automattic\WooCommerce\StoreApi\Routes\V1\Cart::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\Cart::class);
45
+class_alias(Automattic\WooCommerce\StoreApi\Routes\V1\CartAddItem::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\CartAddItem::class);
46
+class_alias(Automattic\WooCommerce\StoreApi\Routes\V1\CartApplyCoupon::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\CartApplyCoupon::class);
47
+class_alias(Automattic\WooCommerce\StoreApi\Routes\V1\CartCoupons::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\CartCoupons::class);
48
+class_alias(Automattic\WooCommerce\StoreApi\Routes\V1\CartCouponsByCode::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\CartCouponsByCode::class);
49
+class_alias(Automattic\WooCommerce\StoreApi\Routes\V1\CartExtensions::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\CartExtensions::class);
50
+class_alias(Automattic\WooCommerce\StoreApi\Routes\V1\CartItems::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\CartItems::class);
51
+class_alias(Automattic\WooCommerce\StoreApi\Routes\V1\CartItemsByKey::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\CartItemsByKey::class);
52
+class_alias(Automattic\WooCommerce\StoreApi\Routes\V1\CartRemoveCoupon::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\CartRemoveCoupon::class);
53
+class_alias(Automattic\WooCommerce\StoreApi\Routes\V1\CartRemoveItem::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\CartRemoveItem::class);
54
+class_alias(Automattic\WooCommerce\StoreApi\Routes\V1\CartSelectShippingRate::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\CartSelectShippingRate::class);
55
+class_alias(Automattic\WooCommerce\StoreApi\Routes\V1\CartUpdateCustomer::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\CartUpdateCustomer::class);
56
+class_alias(Automattic\WooCommerce\StoreApi\Routes\V1\CartUpdateItem::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\CartUpdateItem::class);
57
+class_alias(Automattic\WooCommerce\StoreApi\Routes\V1\Checkout::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\Checkout::class);
58
+class_alias(Automattic\WooCommerce\StoreApi\Routes\V1\ProductAttributes::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\ProductAttributes::class);
59
+class_alias(Automattic\WooCommerce\StoreApi\Routes\V1\ProductAttributesById::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\ProductAttributesById::class);
60
+class_alias(Automattic\WooCommerce\StoreApi\Routes\V1\ProductAttributeTerms::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\ProductAttributeTerms::class);
61
+class_alias(Automattic\WooCommerce\StoreApi\Routes\V1\ProductCategories::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\ProductCategories::class);
62
+class_alias(Automattic\WooCommerce\StoreApi\Routes\V1\ProductCategoriesById::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\ProductCategoriesById::class);
63
+class_alias(Automattic\WooCommerce\StoreApi\Routes\V1\ProductCollectionData::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\ProductCollectionData::class);
64
+class_alias(Automattic\WooCommerce\StoreApi\Routes\V1\ProductReviews::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\ProductReviews::class);
65
+class_alias(Automattic\WooCommerce\StoreApi\Routes\V1\Products::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\Products::class);
66
+class_alias(Automattic\WooCommerce\StoreApi\Routes\V1\ProductsById::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\ProductsById::class);
67
+class_alias(Automattic\WooCommerce\StoreApi\Routes\V1\ProductTags::class, Automattic\WooCommerce\Blocks\StoreApi\Routes\ProductTags::class);
Please login to merge, or discard this patch.