Skip to content

Commit 825638c

Browse files
committed
Merge pull request #126 from bc-joshroe/api-fix-1
Adding Order Shipment and Shipping Address methods
2 parents 7840860 + 3b0c855 commit 825638c

2 files changed

Lines changed: 194 additions & 8 deletions

File tree

src/Bigcommerce/Api/Client.php

Lines changed: 108 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -770,25 +770,25 @@ public static function getOrder($id)
770770
}
771771

772772
/**
773-
* @param $id
773+
* @param $orderID
774774
* @return mixed
775775
*/
776-
public static function getOrderProducts($id)
776+
public static function getOrderProducts($orderID)
777777
{
778-
return self::getCollection('/orders/' . $id . '/products', 'OrderProduct');
778+
return self::getCollection('/orders/' . $orderID . '/products', 'OrderProduct');
779779
}
780780

781781
/**
782782
* The total number of order products in the collection.
783783
*
784-
* @param $id
784+
* @param $orderID
785785
* @param array $filter
786786
* @return mixed
787787
*/
788-
public static function getOrderProductsCount($id, $filter = array())
788+
public static function getOrderProductsCount($orderID, $filter = array())
789789
{
790790
$filter = Filter::create($filter);
791-
return self::getCount('/orders/' . $id . '/products/count' . $filter->toQuery());
791+
return self::getCount('/orders/' . $orderID . '/products/count' . $filter->toQuery());
792792
}
793793

794794
/**
@@ -815,8 +815,10 @@ public static function deleteAllOrders()
815815

816816
/**
817817
* Create an order
818-
**/
819-
818+
*
819+
* @param $object
820+
* @return hash|bool|mixed
821+
*/
820822
public static function createOrder($object)
821823
{
822824
return self::createResource('/orders', $object);
@@ -1140,4 +1142,102 @@ public static function getRequestsRemaining()
11401142

11411143
return intval($limit);
11421144
}
1145+
1146+
/**
1147+
* Get a single shipment by given id.
1148+
*
1149+
* @param $orderID
1150+
* @param $shipmentID
1151+
* @return mixed
1152+
*/
1153+
public static function getShipment($orderID, $shipmentID)
1154+
{
1155+
return self::getResource('/orders/' . $orderID . '/shipments/' . $shipmentID, 'Shipment');
1156+
}
1157+
1158+
/**
1159+
* Get shipments for a given order
1160+
*
1161+
* @param $orderID
1162+
* @param array $filter
1163+
* @return mixed
1164+
*/
1165+
public static function getShipments($orderID, $filter = array())
1166+
{
1167+
$filter = Filter::create($filter);
1168+
return self::getCollection('/orders/' . $orderID . '/shipments' . $filter->toQuery(), 'Shipment');
1169+
}
1170+
1171+
/**
1172+
* Create shipment
1173+
*
1174+
* @param $orderID
1175+
* @param $object
1176+
* @return hash|bool|mixed
1177+
*/
1178+
public static function createShipment($orderID, $object)
1179+
{
1180+
return self::createResource('/orders/' . $orderID . '/shipments', $object);
1181+
}
1182+
1183+
/**
1184+
* Update shipment
1185+
*
1186+
* @param $orderID
1187+
* @param $shipmentID
1188+
* @param $object
1189+
* @return hash|bool|mixed
1190+
*/
1191+
public static function updateShipment($orderID, $shipmentID, $object)
1192+
{
1193+
return self::updateResource('/orders/' . $orderID . '/shipments/' . $shipmentID, $object);
1194+
}
1195+
1196+
/**
1197+
* Delete the given shipment.
1198+
*
1199+
* @param $orderID
1200+
* @param $shipmentID
1201+
* @return hash|bool|mixed
1202+
*/
1203+
public static function deleteShipment($orderID, $shipmentID)
1204+
{
1205+
return self::deleteResource('/orders/' . $orderID . '/shipments/' . $shipmentID);
1206+
}
1207+
1208+
/**
1209+
* Delete all Shipments for the given order.
1210+
*
1211+
* @param $orderID
1212+
* @return hash|bool|mixed
1213+
*/
1214+
public static function deleteAllShipmentsForOrder($orderID)
1215+
{
1216+
return self::deleteResource('/orders/' . $orderID . '/shipments');
1217+
}
1218+
1219+
/**
1220+
* Get a single order shipping address by given order and order shipping address id.
1221+
*
1222+
* @param $orderID
1223+
* @param $orderShippingAddressID
1224+
* @return mixed
1225+
*/
1226+
public static function getOrderShippingAddress($orderID, $orderShippingAddressID)
1227+
{
1228+
return self::getResource('/orders/' . $orderID . '/shipping_addresses/' . $orderShippingAddressID, 'Address');
1229+
}
1230+
1231+
/**
1232+
* Get order shipping addresses for a given order
1233+
*
1234+
* @param $orderID
1235+
* @param array $filter
1236+
* @return mixed
1237+
*/
1238+
public static function getOrderShippingAddresses($orderID, $filter = array())
1239+
{
1240+
$filter = Filter::create($filter);
1241+
return self::getCollection('/orders/' . $orderID . '/shipping_addresses' . $filter->toQuery(), 'Address');
1242+
}
11431243
}

test/Unit/Api/ClientTest.php

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,4 +592,90 @@ public function testGettingOrderProductsCountCountsToTheOrderProductsResource()
592592
$count = Client::getOrderProductsCount(1);
593593
$this->assertSame(7, $count);
594594
}
595+
596+
public function testGettingOrderShipmentReturnsTheOrderShipmentResource()
597+
{
598+
$this->connection->expects($this->once())
599+
->method('get')
600+
->with('/orders/1/shipments/1', false)
601+
->will($this->returnValue(array(array(), array())));
602+
603+
$resource = Client::getShipment(1, 1);
604+
$this->assertInstanceOf('Bigcommerce\\Api\\Resources\\Shipment', $resource);
605+
}
606+
607+
public function testGettingOrderShipmentsReturnsTheOrderShipmentsResource()
608+
{
609+
$this->connection->expects($this->once())
610+
->method('get')
611+
->with('/orders/1/shipments', false)
612+
->will($this->returnValue(array(array(), array())));
613+
614+
$collection = Client::getShipments(1);
615+
$this->assertInternalType('array', $collection);
616+
foreach ($collection as $resource) {
617+
$this->assertInstanceOf('Bigcommerce\\Api\\Resources\\Shipment', $resource);
618+
}
619+
}
620+
621+
public function testCreatingOrderShipmentsPostsToTheOrderShipmentsResource()
622+
{
623+
$this->connection->expects($this->once())
624+
->method('post')
625+
->with('/orders/1/shipments', (object)array());
626+
627+
Client::createShipment(1, array());
628+
}
629+
630+
public function testUpdatingOrderShipmentsPutsToTheOrderShipmentsResource()
631+
{
632+
$this->connection->expects($this->once())
633+
->method('put')
634+
->with('/orders/1/shipments/1', (object)array());
635+
636+
Client::updateShipment(1, 1, array());
637+
}
638+
639+
public function testDeletingAllOrderShipmentsDeletesToTheOrderShipmentResource()
640+
{
641+
$this->connection->expects($this->once())
642+
->method('delete')
643+
->with('/orders/1/shipments');
644+
645+
Client::deleteAllShipmentsForOrder(1);
646+
}
647+
648+
public function testDeletingAnOrderShipmentDeletesToTheOrderShipmentResource()
649+
{
650+
$this->connection->expects($this->once())
651+
->method('delete')
652+
->with('/orders/1/shipments/1');
653+
654+
Client::deleteShipment(1, 1);
655+
}
656+
657+
public function testGettingOrderShippingAddressReturnsTheAddressResource()
658+
{
659+
$this->connection->expects($this->once())
660+
->method('get')
661+
->with('/orders/1/shipping_addresses/1', false)
662+
->will($this->returnValue(array(array(), array())));
663+
664+
$resource = Client::getOrderShippingAddress(1, 1);
665+
$this->assertInstanceOf('Bigcommerce\\Api\\Resources\\Address', $resource);
666+
}
667+
668+
public function testGettingOrderShippingAddressesReturnsTheAddressResource()
669+
{
670+
$this->connection->expects($this->once())
671+
->method('get')
672+
->with('/orders/1/shipping_addresses', false)
673+
->will($this->returnValue(array(array(), array())));
674+
675+
$collection = Client::getOrderShippingAddresses(1);
676+
$this->assertInternalType('array', $collection);
677+
foreach ($collection as $resource) {
678+
$this->assertInstanceOf('Bigcommerce\\Api\\Resources\\Address', $resource);
679+
}
680+
}
595681
}

0 commit comments

Comments
 (0)