Merge pull request #13755 from woocommerce/fix/shipping-zone-locations-schema
[REST API] Fixed shipping zone locations schema
This commit is contained in:
commit
803786ceeb
|
@ -90,10 +90,20 @@ class WC_REST_Shipping_Zone_Locations_Controller extends WC_REST_Shipping_Zones_
|
||||||
$locations = array();
|
$locations = array();
|
||||||
|
|
||||||
foreach ( (array) $raw_locations as $raw_location ) {
|
foreach ( (array) $raw_locations as $raw_location ) {
|
||||||
if ( empty( $raw_location['code'] ) || empty( $raw_location['type'] ) ) {
|
if ( empty( $raw_location['code'] ) ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$locations[] = $raw_location;
|
|
||||||
|
$type = ! empty( $raw_location['type'] ) ? sanitize_text_field( $raw_location['type'] ) : 'country';
|
||||||
|
|
||||||
|
if ( ! in_array( $type, array( 'postcode', 'state', 'country', 'continent' ), true ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$locations[] = array(
|
||||||
|
'code' => sanitize_text_field( $raw_location['code'] ),
|
||||||
|
'type' => sanitize_text_field( $type ),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$zone->set_locations( $locations );
|
$zone->set_locations( $locations );
|
||||||
|
@ -157,25 +167,18 @@ class WC_REST_Shipping_Zone_Locations_Controller extends WC_REST_Shipping_Zones_
|
||||||
'description' => __( 'Shipping zone location code.', 'woocommerce' ),
|
'description' => __( 'Shipping zone location code.', 'woocommerce' ),
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
'context' => array( 'view', 'edit' ),
|
'context' => array( 'view', 'edit' ),
|
||||||
'required' => true,
|
|
||||||
'arg_options' => array(
|
|
||||||
'sanitize_callback' => 'sanitize_text_field',
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
'type' => array(
|
'type' => array(
|
||||||
'description' => __( 'Shipping zone location type.', 'woocommerce' ),
|
'description' => __( 'Shipping zone location type.', 'woocommerce' ),
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
'context' => array( 'view', 'edit' ),
|
'default' => 'country',
|
||||||
'required' => true,
|
|
||||||
'arg_options' => array(
|
|
||||||
'sanitize_callback' => 'sanitize_text_field',
|
|
||||||
),
|
|
||||||
'enum' => array(
|
'enum' => array(
|
||||||
'postcode',
|
'postcode',
|
||||||
'state',
|
'state',
|
||||||
'country',
|
'country',
|
||||||
'continent',
|
'continent',
|
||||||
),
|
),
|
||||||
|
'context' => array( 'view', 'edit' ),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -467,7 +467,7 @@ class WC_Tests_API_Shipping_Zones extends WC_REST_Unit_Test_Case {
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( count( $data ), 2 );
|
$this->assertEquals( 3, count( $data ) );
|
||||||
$this->assertEquals( array(
|
$this->assertEquals( array(
|
||||||
array(
|
array(
|
||||||
'code' => 'UK',
|
'code' => 'UK',
|
||||||
|
|
Loading…
Reference in New Issue