From 1c82876487a6fad240de5d46403bc21806a95321 Mon Sep 17 00:00:00 2001 From: Enrico Deleo Date: Wed, 23 Mar 2016 23:09:43 +0100 Subject: [PATCH 1/6] get by sku via filter. Compatible with v3 --- .../resources/class-wc-api-client-resource-products.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/woocommerce-api/resources/class-wc-api-client-resource-products.php b/lib/woocommerce-api/resources/class-wc-api-client-resource-products.php index 47b2aee..14410c9 100644 --- a/lib/woocommerce-api/resources/class-wc-api-client-resource-products.php +++ b/lib/woocommerce-api/resources/class-wc-api-client-resource-products.php @@ -45,7 +45,7 @@ public function get( $id = null, $args = array() ) { /** * Get product by SKU * - * GET /products/sku/{sku} + * GET /products/?filter[{sku}] * * Note this will throw an exception if no products are found (404 not found) * @@ -58,8 +58,7 @@ public function get_by_sku( $sku, $args = array() ) { $this->set_request_args( array( 'method' => 'GET', - 'path' => array( 'sku', urlencode( $sku ) ), - 'params' => $args, + 'params' => array_merge( array( filter[sku] ), $args ) ) ); return $this->do_request(); From a332f1b12685aa1620c1d45f8063779443c6925c Mon Sep 17 00:00:00 2001 From: Enrico Deleo Date: Wed, 23 Mar 2016 23:16:40 +0100 Subject: [PATCH 2/6] get by sku via filter. Compatible with v3 --- .../resources/class-wc-api-client-resource-products.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/woocommerce-api/resources/class-wc-api-client-resource-products.php b/lib/woocommerce-api/resources/class-wc-api-client-resource-products.php index 14410c9..37a136f 100644 --- a/lib/woocommerce-api/resources/class-wc-api-client-resource-products.php +++ b/lib/woocommerce-api/resources/class-wc-api-client-resource-products.php @@ -58,7 +58,7 @@ public function get_by_sku( $sku, $args = array() ) { $this->set_request_args( array( 'method' => 'GET', - 'params' => array_merge( array( filter[sku] ), $args ) + 'params' => array_merge( array( "filter[$sku]" ), $args ) ) ); return $this->do_request(); From 6a72797701ec9152e930d8d635d4e531d3ef07c3 Mon Sep 17 00:00:00 2001 From: Enrico Deleo Date: Wed, 23 Mar 2016 23:31:16 +0100 Subject: [PATCH 3/6] get by sku via filter. Compatible with v3 --- lib/woocommerce-api/class-wc-api-client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/woocommerce-api/class-wc-api-client.php b/lib/woocommerce-api/class-wc-api-client.php index e27052a..1d7a077 100644 --- a/lib/woocommerce-api/class-wc-api-client.php +++ b/lib/woocommerce-api/class-wc-api-client.php @@ -161,7 +161,7 @@ public function build_api_url() { $path = isset( $url['path'] ) ? rtrim( $url['path'], '/' ) : ''; // add WC API path - $path .= '/wc-api/v2/'; + $path .= '/wc-api/v3/'; // build URL $this->api_url = "{$scheme}://{$host}{$path}"; From 3ba2f234b2afd5e0ed441b2b2e96b5404562671b Mon Sep 17 00:00:00 2001 From: Enrico Deleo Date: Wed, 23 Mar 2016 23:34:18 +0100 Subject: [PATCH 4/6] get by sku via filter. Compatible with v3 --- .../resources/class-wc-api-client-resource-products.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/woocommerce-api/resources/class-wc-api-client-resource-products.php b/lib/woocommerce-api/resources/class-wc-api-client-resource-products.php index 37a136f..b14a480 100644 --- a/lib/woocommerce-api/resources/class-wc-api-client-resource-products.php +++ b/lib/woocommerce-api/resources/class-wc-api-client-resource-products.php @@ -58,7 +58,7 @@ public function get_by_sku( $sku, $args = array() ) { $this->set_request_args( array( 'method' => 'GET', - 'params' => array_merge( array( "filter[$sku]" ), $args ) + 'params' => array_merge( array( "filter[sku]" => $sku ), $args ) ) ); return $this->do_request(); From 6d4c0e56f7c768c2b2b311c05d2c9bcdd1de6d32 Mon Sep 17 00:00:00 2001 From: Enrico Deleo Date: Wed, 23 Mar 2016 23:40:01 +0100 Subject: [PATCH 5/6] support new v3 endpoint --- .../class-wc-api-client-resource-products.php | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/woocommerce-api/resources/class-wc-api-client-resource-products.php b/lib/woocommerce-api/resources/class-wc-api-client-resource-products.php index b14a480..e0f12ad 100644 --- a/lib/woocommerce-api/resources/class-wc-api-client-resource-products.php +++ b/lib/woocommerce-api/resources/class-wc-api-client-resource-products.php @@ -49,7 +49,7 @@ public function get( $id = null, $args = array() ) { * * Note this will throw an exception if no products are found (404 not found) * - * @since 2.0 + * @since 3.0 * @param string $sku product SKU * @param array $args acceptable product SKU lookup endpoint args, currently only `fields` * @return array|object product! @@ -194,6 +194,27 @@ public function get_categories( $id = null, $args = array() ) { return $this->do_request(); } + /** + * Retrieve all product orders. + * + * GET /products/{#id}/orders + * + * @since 3.0 + * @param int $id category ID or null to get all product categories + * @param array $args acceptable product categories endpoint args, currently only `fields` + * @return array|object product categories! + */ + public function get_categories( $id = null, $args = array() ) { + + $this->set_request_args( array( + 'method' => 'GET', + 'path' => array( $id, 'orders' ), + 'params' => $args, + ) ); + + return $this->do_request(); + } + /** Convenience methods - these do not map directly to an endpoint ********/ From edbfe88fb860f10276512aebda8ab29eb2287f6f Mon Sep 17 00:00:00 2001 From: Enrico Deleo Date: Wed, 23 Mar 2016 23:43:06 +0100 Subject: [PATCH 6/6] support new v3 endpoint --- .../resources/class-wc-api-client-resource-products.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/woocommerce-api/resources/class-wc-api-client-resource-products.php b/lib/woocommerce-api/resources/class-wc-api-client-resource-products.php index e0f12ad..2ee511f 100644 --- a/lib/woocommerce-api/resources/class-wc-api-client-resource-products.php +++ b/lib/woocommerce-api/resources/class-wc-api-client-resource-products.php @@ -204,7 +204,7 @@ public function get_categories( $id = null, $args = array() ) { * @param array $args acceptable product categories endpoint args, currently only `fields` * @return array|object product categories! */ - public function get_categories( $id = null, $args = array() ) { + public function get_product_orders( $id = null, $args = array() ) { $this->set_request_args( array( 'method' => 'GET',