Skip to content

Commit

Permalink
Merge pull request #125 from bc-joshroe/api-fix-1
Browse files Browse the repository at this point in the history
Adding deleteAllOrders and getOrderProductsCount
  • Loading branch information
aleachjr committed Mar 5, 2015
2 parents 246e198 + efa986e commit 7840860
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/Bigcommerce/Api/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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
**/
Expand Down
22 changes: 21 additions & 1 deletion test/Unit/Api/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ public function testDeletingACustomerDeletesToTheCustomerResource()
Client::deleteCustomers();
}

public function testDeletingAllCouponDeletesToTheCouponResource()
public function testDeletingAllCouponsDeletesToTheCouponResource()
{
$this->connection->expects($this->once())
->method('delete')
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 7840860

Please sign in to comment.