From 4b0fff3437dd4f44d950a37c58ad59037550f124 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Fri, 28 Apr 2017 15:49:51 +0100 Subject: [PATCH] Fix zone routes in CLI Fixes #14750 --- .../class-wc-rest-shipping-zone-locations-controller.php | 2 +- .../api/class-wc-rest-shipping-zone-methods-controller.php | 4 ++-- includes/cli/class-wc-cli-runner.php | 2 ++ tests/unit-tests/api/shipping-zones.php | 6 +++--- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/includes/api/class-wc-rest-shipping-zone-locations-controller.php b/includes/api/class-wc-rest-shipping-zone-locations-controller.php index fbda19d8ca35..07c965456d0c 100644 --- a/includes/api/class-wc-rest-shipping-zone-locations-controller.php +++ b/includes/api/class-wc-rest-shipping-zone-locations-controller.php @@ -26,7 +26,7 @@ class WC_REST_Shipping_Zone_Locations_Controller extends WC_REST_Shipping_Zones_ * Register the routes for Shipping Zone Locations. */ public function register_routes() { - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P[\d-]+)/locations', array( + register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P[\d]+)/locations', array( 'args' => array( 'id' => array( 'description' => __( 'Unique ID for the resource.', 'woocommerce' ), diff --git a/includes/api/class-wc-rest-shipping-zone-methods-controller.php b/includes/api/class-wc-rest-shipping-zone-methods-controller.php index c37dd49ad7f9..5102f0a1aed8 100644 --- a/includes/api/class-wc-rest-shipping-zone-methods-controller.php +++ b/includes/api/class-wc-rest-shipping-zone-methods-controller.php @@ -26,7 +26,7 @@ class WC_REST_Shipping_Zone_Methods_Controller extends WC_REST_Shipping_Zones_Co * Register the routes for Shipping Zone Methods. */ public function register_routes() { - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P[\d-]+)/methods', array( + register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P[\d]+)/methods', array( 'args' => array( 'zone_id' => array( 'description' => __( 'Unique ID for the zone.', 'woocommerce' ), @@ -53,7 +53,7 @@ public function register_routes() { 'schema' => array( $this, 'get_public_item_schema' ), ) ); - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P[\d-]+)/methods/(?P[\d-]+)', array( + register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P[\d]+)/methods/(?P[\d-]+)', array( 'args' => array( 'zone_id' => array( 'description' => __( 'Unique ID for the zone.', 'woocommerce' ), diff --git a/includes/cli/class-wc-cli-runner.php b/includes/cli/class-wc-cli-runner.php index e9c93a241793..7d8a2dc402e5 100644 --- a/includes/cli/class-wc-cli-runner.php +++ b/includes/cli/class-wc-cli-runner.php @@ -92,11 +92,13 @@ private static function register_route_commands( $rest_command, $route, $route_d // Define IDs that we are looking for in the routes (in addition to id) // so that we can pass it to the rest command, and use it here to generate documentation. $supported_ids = array( + 'id' => __( 'ID.', 'woocommerce' ), 'product_id' => __( 'Product ID.', 'woocommerce' ), 'customer_id' => __( 'Customer ID.', 'woocommerce' ), 'order_id' => __( 'Order ID.', 'woocommerce' ), 'refund_id' => __( 'Refund ID.', 'woocommerce' ), 'attribute_id' => __( 'Attribute ID.', 'woocommerce' ), + 'zone_id' => __( 'Zone ID.', 'woocommerce' ), ); $rest_command->set_supported_ids( $supported_ids ); $positional_args = array_merge( array( 'id' ), array_keys( $supported_ids ) ); diff --git a/tests/unit-tests/api/shipping-zones.php b/tests/unit-tests/api/shipping-zones.php index 3f557abadb54..d82937d9df98 100644 --- a/tests/unit-tests/api/shipping-zones.php +++ b/tests/unit-tests/api/shipping-zones.php @@ -64,9 +64,9 @@ public function test_register_routes() { $routes = $this->server->get_routes(); $this->assertArrayHasKey( '/wc/v2/shipping/zones', $routes ); $this->assertArrayHasKey( '/wc/v2/shipping/zones/(?P[\d-]+)', $routes ); - $this->assertArrayHasKey( '/wc/v2/shipping/zones/(?P[\d-]+)/locations', $routes ); - $this->assertArrayHasKey( '/wc/v2/shipping/zones/(?P[\d-]+)/methods', $routes ); - $this->assertArrayHasKey( '/wc/v2/shipping/zones/(?P[\d-]+)/methods/(?P[\d-]+)', $routes ); + $this->assertArrayHasKey( '/wc/v2/shipping/zones/(?P[\d]+)/locations', $routes ); + $this->assertArrayHasKey( '/wc/v2/shipping/zones/(?P[\d]+)/methods', $routes ); + $this->assertArrayHasKey( '/wc/v2/shipping/zones/(?P[\d]+)/methods/(?P[\d-]+)', $routes ); } /**