/var/www/html/wp-content/plugins/woocommerce/src/Admin/Features/Blueprint/Steps/SetWCTaxRates.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php

declare( strict_types 1);

namespace 
Automattic\WooCommerce\Admin\Features\Blueprint\Steps;

use 
Automattic\WooCommerce\Blueprint\Steps\Step;

/**
 * Class SetWCTaxRates
 *
 * This class sets WooCommerce tax rates and extends the Step class.
 *
 * @package Automattic\WooCommerce\Admin\Features\Blueprint\Steps
 */
class SetWCTaxRates extends Step {

    
/**
     * Tax rates.
     *
     * @var array $rates Tax rates.
     */
    
private array $rates;

    
/**
     * Tax rate locations.
     *
     * @var array $locations Tax rate locations.
     */
    
private array $locations;

    
/**
     * Constructor.
     *
     * @param array $rates Tax rates.
     * @param array $locations Tax rate locations.
     */
    
public function __construct( array $rates, array $locations ) {
        
$this->rates     $rates;
        
$this->locations $locations;
    }

    
/**
     * Prepare the JSON array for the step.
     *
     * @return array The JSON array.
     */
    
public function prepare_json_array(): array {
        return array(
            
'step'   => static::get_step_name(),
            
'values' => array(
                
'rates'     => $this->rates,
                
'locations' => $this->locations,
            ),
        );
    }

    
/**
     * Get the name of the step.
     *
     * @return string
     */
    
public static function get_step_name(): string {
        return 
'setWCTaxRates';
    }

    
/**
     * Get the schema for the step.
     *
     * @param int $version Optional version number of the schema.
     * @return array The schema array.
     */
    
public static function get_schema$version ): array {
        return array(
            
'type'       => 'object',
            
'properties' => array(
                
'step'   => array(
                    
'type' => 'string',
                    
'enum' => array( static::get_step_name() ),
                ),
                
'values' => array(
                    
'type'       => 'object',
                    
'properties' => array(
                        
'rates'     => array(
                            
'type'  => 'array',
                            
'items' => array(
                                
'type'       => 'object',
                                
'properties' => array(
                                    
'tax_rate_id'       => array( 'type' => 'string' ),
                                    
'tax_rate_country'  => array( 'type' => 'string' ),
                                    
'tax_rate_state'    => array( 'type' => 'string' ),
                                    
'tax_rate'          => array( 'type' => 'string' ),
                                    
'tax_rate_name'     => array( 'type' => 'string' ),
                                    
'tax_rate_priority' => array( 'type' => 'string' ),
                                    
'tax_rate_compound' => array( 'type' => 'string' ),
                                    
'tax_rate_shipping' => array( 'type' => 'string' ),
                                    
'tax_rate_order'    => array( 'type' => 'string' ),
                                    
'tax_rate_class'    => array( 'type' => 'string' ),
                                ),
                                
'required'   => array(
                                    
'tax_rate_id',
                                    
'tax_rate_country',
                                    
'tax_rate_state',
                                    
'tax_rate',
                                    
'tax_rate_name',
                                    
'tax_rate_priority',
                                    
'tax_rate_compound',
                                    
'tax_rate_shipping',
                                    
'tax_rate_order',
                                    
'tax_rate_class',
                                ),
                            ),
                        ),
                        
'locations' => array(
                            
'type'  => 'array',
                            
'items' => array(
                                
'type'       => 'object',
                                
'properties' => array(
                                    
'location_id'   => array( 'type' => 'string' ),
                                    
'location_code' => array( 'type' => 'string' ),
                                    
'tax_rate_id'   => array( 'type' => 'string' ),
                                    
'location_type' => array( 'type' => 'string' ),
                                ),
                                
'required'   => array( 'location_id''location_code''tax_rate_id''location_type' ),
                            ),
                        ),
                    ),
                    
'required'   => array( 'rates' ),
                ),
            ),
            
'required'   => array( 'step''values' ),
        );
    }
}