From 16fd821b877b92342432cf0036f4298f6730016c Mon Sep 17 00:00:00 2001 From: Fabio Bianchi Date: Mon, 15 May 2017 18:12:53 +1000 Subject: [PATCH 1/2] SHIPPING-249 - add shipping-zone resource --- src/Bigcommerce/Api/Client.php | 33 +++++++++ .../Api/Resources/ShippingZone.php | 27 +++++++ test/Unit/Api/Resources/RealTest.php | 0 test/Unit/Api/Resources/ShippingZoneTest.php | 73 +++++++++++++++++++ 4 files changed, 133 insertions(+) create mode 100644 src/Bigcommerce/Api/Resources/ShippingZone.php create mode 100644 test/Unit/Api/Resources/RealTest.php create mode 100644 test/Unit/Api/Resources/ShippingZoneTest.php diff --git a/src/Bigcommerce/Api/Client.php b/src/Bigcommerce/Api/Client.php index 18cdcf1c..c0e01bbc 100644 --- a/src/Bigcommerce/Api/Client.php +++ b/src/Bigcommerce/Api/Client.php @@ -1943,4 +1943,37 @@ public static function deleteWebhook($id) { return self::deleteResource('/hooks/' . $id); } + + /** + * Return a collection of shipping-zones + * + * @return mixed + */ + public static function getShippingZones() + { + return self::getCollection('/shipping/zones/', 'ShippingZone'); + } + + /** + * Return a shipping-zone by id + * + * @param int $id shipping-zone id + * @return mixed + */ + public static function getShippingZone($id) + { + return self::getResource('/shipping/zones/' . $id, 'ShippingZone'); + } + + + /** + * Delete the given shipping-zone + * + * @param int $id shipping-zone id + * @return mixed + */ + public static function deleteShippingZone($id) + { + return self::deleteResource('/shipping/zones/' . $id); + } } diff --git a/src/Bigcommerce/Api/Resources/ShippingZone.php b/src/Bigcommerce/Api/Resources/ShippingZone.php new file mode 100644 index 00000000..680e8672 --- /dev/null +++ b/src/Bigcommerce/Api/Resources/ShippingZone.php @@ -0,0 +1,27 @@ +getCreateFields()); + } + + public function update() + { + return Client::updateResource('/shipping/zones/'. $this->id, $this->getUpdateFields()); + } +} diff --git a/test/Unit/Api/Resources/RealTest.php b/test/Unit/Api/Resources/RealTest.php new file mode 100644 index 00000000..e69de29b diff --git a/test/Unit/Api/Resources/ShippingZoneTest.php b/test/Unit/Api/Resources/ShippingZoneTest.php new file mode 100644 index 00000000..f78db0e5 --- /dev/null +++ b/test/Unit/Api/Resources/ShippingZoneTest.php @@ -0,0 +1,73 @@ + 'United States', + 'type' => 'country', + 'locations' => array( + array('country_iso2' => 'US'), + ), + ); + $zone = new ShippingZone((object)$input); + $this->connection->expects($this->once()) + ->method('post') + ->with($this->basePath . '/shipping/zones/', (object)$input); + + $zone->create(); + } + + public function testUpdateShippingZone() + { + $input = array( + 'name' => 'United States', + 'type' => 'country', + 'locations' => array( + array('country_iso2' => 'US'), + ), + ); + $updateResource = array_merge(['id' => 1], $input); + $zone = new ShippingZone((object)$updateResource); + + $this->connection->expects($this->once()) + ->method('put') + ->with($this->basePath . '/shipping/zones/1', (object)$input); + + $zone->update(); + } + + public function testGetShippingZone() + { + $this->connection->expects($this->once()) + ->method('get') + ->with($this->basePath . '/shipping/zones/1'); + + Client::getShippingZone(1); + } + + public function testGetShippingZones() + { + $this->connection->expects($this->once()) + ->method('get') + ->with($this->basePath . '/shipping/zones/'); + + Client::getShippingZones(); + } + + public function testDeleteShippingZone() + { + + $this->connection->expects($this->once()) + ->method('delete') + ->with($this->basePath . '/shipping/zones/1'); + + Client::deleteShippingZone(1); + } +} From 222560e4b9b10a3c478df85b3819d3ec39f82428 Mon Sep 17 00:00:00 2001 From: Fabio Bianchi Date: Wed, 17 May 2017 16:01:17 +1000 Subject: [PATCH 2/2] SHIPPING-249 add shipping-method resource --- src/Bigcommerce/Api/Client.php | 36 ++++++ .../Api/Resources/ShippingMethod.php | 27 +++++ .../Unit/Api/Resources/ShippingMethodTest.php | 105 ++++++++++++++++++ test/Unit/Api/Resources/ShippingZoneTest.php | 2 +- 4 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 src/Bigcommerce/Api/Resources/ShippingMethod.php create mode 100644 test/Unit/Api/Resources/ShippingMethodTest.php diff --git a/src/Bigcommerce/Api/Client.php b/src/Bigcommerce/Api/Client.php index c0e01bbc..c6cea157 100644 --- a/src/Bigcommerce/Api/Client.php +++ b/src/Bigcommerce/Api/Client.php @@ -1976,4 +1976,40 @@ public static function deleteShippingZone($id) { return self::deleteResource('/shipping/zones/' . $id); } + + /** + * Return a shipping-method by id + * + * @param $zoneId + * @param $methodId + * @return mixed + */ + public static function getShippingMethod($zoneId, $methodId) + { + return self::getResource('/shipping/zones/'. $zoneId . '/methods/'. $methodId, 'ShippingMethod'); + } + + /** + * Return a collection of shipping-methods + * + * @param $zoneId + * @return mixed + */ + public static function getShippingMethods($zoneId) + { + return self::getCollection('/shipping/zones/' . $zoneId . '/methods', 'ShippingMethod'); + } + + + /** + * Delete the given shipping-method by id + * + * @param $zoneId + * @param $methodId + * @return mixed + */ + public static function deleteShippingMethod($zoneId, $methodId) + { + return self::deleteResource('/shipping/zones/'. $zoneId . '/methods/'. $methodId); + } } diff --git a/src/Bigcommerce/Api/Resources/ShippingMethod.php b/src/Bigcommerce/Api/Resources/ShippingMethod.php new file mode 100644 index 00000000..60764afa --- /dev/null +++ b/src/Bigcommerce/Api/Resources/ShippingMethod.php @@ -0,0 +1,27 @@ +getCreateFields()); + } + + public function update($zoneId) + { + return Client::updateResource('/shipping/zones/' . $zoneId . '/methods/' . $this->id, $this->getUpdateFields()); + } +} diff --git a/test/Unit/Api/Resources/ShippingMethodTest.php b/test/Unit/Api/Resources/ShippingMethodTest.php new file mode 100644 index 00000000..c205190f --- /dev/null +++ b/test/Unit/Api/Resources/ShippingMethodTest.php @@ -0,0 +1,105 @@ + "USPS Endicia", + "type" => "endicia", + "settings" => array( + "carrier_options" => array( + "delivery_services" => array( + "PriorityExpress", + "PriorityMailExpressInternational", + "FirstClassPackageInternationalService", + "Priority", + "PriorityMailInternational", + "First", + "ParcelSelect", + "MediaMail" + ), + "packaging" => array( + "FlatRateLegalEnvelope", + "FlatRatePaddedEnvelope", + "Parcel", + "SmallFlatRateBox", + "MediumFlatRateBox", + "LargeFlatRateBox", + "FlatRateEnvelope", + "RegionalRateBoxA", + "RegionalRateBoxB" + ), + "show_transit_time" => true, + ) + ), + "enabled" => true + ); + $method = new ShippingMethod((object)$input); + $this->connection->expects($this->once()) + ->method('post') + ->with($this->basePath . '/shipping/zones/1/methods', (object)$input); + + $method->create(1); + } + + public function testUpdateShippingMethod() + { + $input = array( + "name" => "Ship by Weight", + "type" => "weight", + "settings" => array( + "default_cost" => 1, + "default_cost_type" => "fixed_amount", + "range" => array( + array( + "lower_limit" => 0, + "upper_limit" => 20, + "shipping_cost" => 8 + ) + ) + ), + "enabled" => true + ); + $updateResource = array_merge(array('id' => 1), $input); + $method = new ShippingMethod((object)$updateResource); + $this->connection->expects($this->once()) + ->method('put') + ->with($this->basePath . '/shipping/zones/1/methods/1', (object)$input); + + $method->update(1); + } + + public function testGetShippingMethod() + { + $this->connection->expects($this->once()) + ->method('get') + ->with($this->basePath . '/shipping/zones/1/methods/2'); + + Client::getShippingMethod(1, 2); + } + + public function testGetShippingMethods() + { + $this->connection->expects($this->once()) + ->method('get') + ->with($this->basePath . '/shipping/zones/1/methods'); + + Client::getShippingMethods(1); + } + + public function testDeleteShippingMethod() + { + + $this->connection->expects($this->once()) + ->method('delete') + ->with($this->basePath . '/shipping/zones/1/methods/2'); + + Client::deleteShippingMethod(1, 2); + } +} diff --git a/test/Unit/Api/Resources/ShippingZoneTest.php b/test/Unit/Api/Resources/ShippingZoneTest.php index f78db0e5..645e61d0 100644 --- a/test/Unit/Api/Resources/ShippingZoneTest.php +++ b/test/Unit/Api/Resources/ShippingZoneTest.php @@ -33,7 +33,7 @@ public function testUpdateShippingZone() array('country_iso2' => 'US'), ), ); - $updateResource = array_merge(['id' => 1], $input); + $updateResource = array_merge(array('id' => 1), $input); $zone = new ShippingZone((object)$updateResource); $this->connection->expects($this->once())