From 3b0c855b3ec9419f7151510e50943974b8f8d37b Mon Sep 17 00:00:00 2001 From: bc-joshroe Date: Fri, 6 Mar 2015 20:06:07 -0800 Subject: [PATCH] Adding Order Shipment and Shipping Address methods --- src/Bigcommerce/Api/Client.php | 116 ++++++++++++++++++++++++++++++--- test/Unit/Api/ClientTest.php | 86 ++++++++++++++++++++++++ 2 files changed, 194 insertions(+), 8 deletions(-) diff --git a/src/Bigcommerce/Api/Client.php b/src/Bigcommerce/Api/Client.php index cf81d8a1..c50d2c98 100644 --- a/src/Bigcommerce/Api/Client.php +++ b/src/Bigcommerce/Api/Client.php @@ -770,25 +770,25 @@ public static function getOrder($id) } /** - * @param $id + * @param $orderID * @return mixed */ - public static function getOrderProducts($id) + public static function getOrderProducts($orderID) { - return self::getCollection('/orders/' . $id . '/products', 'OrderProduct'); + return self::getCollection('/orders/' . $orderID . '/products', 'OrderProduct'); } /** * The total number of order products in the collection. * - * @param $id + * @param $orderID * @param array $filter * @return mixed */ - public static function getOrderProductsCount($id, $filter = array()) + public static function getOrderProductsCount($orderID, $filter = array()) { $filter = Filter::create($filter); - return self::getCount('/orders/' . $id . '/products/count' . $filter->toQuery()); + return self::getCount('/orders/' . $orderID . '/products/count' . $filter->toQuery()); } /** @@ -815,8 +815,10 @@ public static function deleteAllOrders() /** * Create an order - **/ - + * + * @param $object + * @return hash|bool|mixed + */ public static function createOrder($object) { return self::createResource('/orders', $object); @@ -1140,4 +1142,102 @@ public static function getRequestsRemaining() return intval($limit); } + + /** + * Get a single shipment by given id. + * + * @param $orderID + * @param $shipmentID + * @return mixed + */ + public static function getShipment($orderID, $shipmentID) + { + return self::getResource('/orders/' . $orderID . '/shipments/' . $shipmentID, 'Shipment'); + } + + /** + * Get shipments for a given order + * + * @param $orderID + * @param array $filter + * @return mixed + */ + public static function getShipments($orderID, $filter = array()) + { + $filter = Filter::create($filter); + return self::getCollection('/orders/' . $orderID . '/shipments' . $filter->toQuery(), 'Shipment'); + } + + /** + * Create shipment + * + * @param $orderID + * @param $object + * @return hash|bool|mixed + */ + public static function createShipment($orderID, $object) + { + return self::createResource('/orders/' . $orderID . '/shipments', $object); + } + + /** + * Update shipment + * + * @param $orderID + * @param $shipmentID + * @param $object + * @return hash|bool|mixed + */ + public static function updateShipment($orderID, $shipmentID, $object) + { + return self::updateResource('/orders/' . $orderID . '/shipments/' . $shipmentID, $object); + } + + /** + * Delete the given shipment. + * + * @param $orderID + * @param $shipmentID + * @return hash|bool|mixed + */ + public static function deleteShipment($orderID, $shipmentID) + { + return self::deleteResource('/orders/' . $orderID . '/shipments/' . $shipmentID); + } + + /** + * Delete all Shipments for the given order. + * + * @param $orderID + * @return hash|bool|mixed + */ + public static function deleteAllShipmentsForOrder($orderID) + { + return self::deleteResource('/orders/' . $orderID . '/shipments'); + } + + /** + * Get a single order shipping address by given order and order shipping address id. + * + * @param $orderID + * @param $orderShippingAddressID + * @return mixed + */ + public static function getOrderShippingAddress($orderID, $orderShippingAddressID) + { + return self::getResource('/orders/' . $orderID . '/shipping_addresses/' . $orderShippingAddressID, 'Address'); + } + + /** + * Get order shipping addresses for a given order + * + * @param $orderID + * @param array $filter + * @return mixed + */ + public static function getOrderShippingAddresses($orderID, $filter = array()) + { + $filter = Filter::create($filter); + return self::getCollection('/orders/' . $orderID . '/shipping_addresses' . $filter->toQuery(), 'Address'); + } } diff --git a/test/Unit/Api/ClientTest.php b/test/Unit/Api/ClientTest.php index 9438ae87..1c9a439a 100644 --- a/test/Unit/Api/ClientTest.php +++ b/test/Unit/Api/ClientTest.php @@ -592,4 +592,90 @@ public function testGettingOrderProductsCountCountsToTheOrderProductsResource() $count = Client::getOrderProductsCount(1); $this->assertSame(7, $count); } + + public function testGettingOrderShipmentReturnsTheOrderShipmentResource() + { + $this->connection->expects($this->once()) + ->method('get') + ->with('/orders/1/shipments/1', false) + ->will($this->returnValue(array(array(), array()))); + + $resource = Client::getShipment(1, 1); + $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\Shipment', $resource); + } + + public function testGettingOrderShipmentsReturnsTheOrderShipmentsResource() + { + $this->connection->expects($this->once()) + ->method('get') + ->with('/orders/1/shipments', false) + ->will($this->returnValue(array(array(), array()))); + + $collection = Client::getShipments(1); + $this->assertInternalType('array', $collection); + foreach ($collection as $resource) { + $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\Shipment', $resource); + } + } + + public function testCreatingOrderShipmentsPostsToTheOrderShipmentsResource() + { + $this->connection->expects($this->once()) + ->method('post') + ->with('/orders/1/shipments', (object)array()); + + Client::createShipment(1, array()); + } + + public function testUpdatingOrderShipmentsPutsToTheOrderShipmentsResource() + { + $this->connection->expects($this->once()) + ->method('put') + ->with('/orders/1/shipments/1', (object)array()); + + Client::updateShipment(1, 1, array()); + } + + public function testDeletingAllOrderShipmentsDeletesToTheOrderShipmentResource() + { + $this->connection->expects($this->once()) + ->method('delete') + ->with('/orders/1/shipments'); + + Client::deleteAllShipmentsForOrder(1); + } + + public function testDeletingAnOrderShipmentDeletesToTheOrderShipmentResource() + { + $this->connection->expects($this->once()) + ->method('delete') + ->with('/orders/1/shipments/1'); + + Client::deleteShipment(1, 1); + } + + public function testGettingOrderShippingAddressReturnsTheAddressResource() + { + $this->connection->expects($this->once()) + ->method('get') + ->with('/orders/1/shipping_addresses/1', false) + ->will($this->returnValue(array(array(), array()))); + + $resource = Client::getOrderShippingAddress(1, 1); + $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\Address', $resource); + } + + public function testGettingOrderShippingAddressesReturnsTheAddressResource() + { + $this->connection->expects($this->once()) + ->method('get') + ->with('/orders/1/shipping_addresses', false) + ->will($this->returnValue(array(array(), array()))); + + $collection = Client::getOrderShippingAddresses(1); + $this->assertInternalType('array', $collection); + foreach ($collection as $resource) { + $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\Address', $resource); + } + } }