Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 108 additions & 8 deletions src/Bigcommerce/Api/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand All @@ -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);
Expand Down Expand Up @@ -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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only name I'm not sold on is this one--but it's not bad, and I can't think of anything more clear.

{
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');
}
}
86 changes: 86 additions & 0 deletions test/Unit/Api/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}