From efa986ef8e24b8d93745f9b0ec083bd4bdb58815 Mon Sep 17 00:00:00 2001 From: bc-joshroe Date: Thu, 5 Mar 2015 13:03:24 -0800 Subject: [PATCH] Adding deleteAllOrders and getOrderProductsCount --- src/Bigcommerce/Api/Client.php | 23 +++++++++++++++++++++++ test/Unit/Api/ClientTest.php | 22 +++++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/Bigcommerce/Api/Client.php b/src/Bigcommerce/Api/Client.php index 80ba2ea0..cf81d8a1 100644 --- a/src/Bigcommerce/Api/Client.php +++ b/src/Bigcommerce/Api/Client.php @@ -778,6 +778,19 @@ public static function getOrderProducts($id) return self::getCollection('/orders/' . $id . '/products', 'OrderProduct'); } + /** + * The total number of order products in the collection. + * + * @param $id + * @param array $filter + * @return mixed + */ + public static function getOrderProductsCount($id, $filter = array()) + { + $filter = Filter::create($filter); + return self::getCount('/orders/' . $id . '/products/count' . $filter->toQuery()); + } + /** * Delete the given order (unlike in the Control Panel, this will permanently * delete the order). @@ -790,6 +803,16 @@ public static function deleteOrder($id) return self::deleteResource('/orders/' . $id); } + /** + * Delete all orders. + * + * @return hash|bool|mixed + */ + public static function deleteAllOrders() + { + return self::deleteResource('/orders'); + } + /** * Create an order **/ diff --git a/test/Unit/Api/ClientTest.php b/test/Unit/Api/ClientTest.php index fb9f04a8..9438ae87 100644 --- a/test/Unit/Api/ClientTest.php +++ b/test/Unit/Api/ClientTest.php @@ -533,7 +533,7 @@ public function testDeletingACustomerDeletesToTheCustomerResource() Client::deleteCustomers(); } - public function testDeletingAllCouponDeletesToTheCouponResource() + public function testDeletingAllCouponsDeletesToTheCouponResource() { $this->connection->expects($this->once()) ->method('delete') @@ -572,4 +572,24 @@ public function testGettingASpecifiedOrderStatusReturnsThatOrderStatus() $resource = Client::getOrderStatus(1); $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\OrderStatus', $resource); } + + public function testDeletingAllOrdersDeletesToTheOrderResource() + { + $this->connection->expects($this->once()) + ->method('delete') + ->with('/orders'); + + Client::deleteAllOrders(); + } + + public function testGettingOrderProductsCountCountsToTheOrderProductsResource() + { + $this->connection->expects($this->once()) + ->method('get') + ->with('/orders/1/products/count', false) + ->will($this->returnValue((object)array('count' => 7))); + + $count = Client::getOrderProductsCount(1); + $this->assertSame(7, $count); + } }