diff --git a/src/Bigcommerce/Api/Client.php b/src/Bigcommerce/Api/Client.php index 306b6671..bae46f78 100644 --- a/src/Bigcommerce/Api/Client.php +++ b/src/Bigcommerce/Api/Client.php @@ -1402,4 +1402,73 @@ public static function getOrderShippingAddresses($orderID, $filter = array()) $filter = Filter::create($filter); return self::getCollection('/orders/' . $orderID . '/shipping_addresses' . $filter->toQuery(), 'Address'); } + + /** + * Create a new currency. + * + * @param mixed $object fields to create + * @return mixed + */ + public static function createCurrency($object) + { + return self::createResource('/currencies', $object); + } + + /** + * Returns a single currency resource by the given id. + * + * @param int $id currency id + * @return Resources\Currency|string + */ + public static function getCurrency($id) + { + return self::getResource('/currencies/' . $id, 'Currency'); + } + + /** + * Update the given currency. + * + * @param int $id currency id + * @param mixed $object fields to update + * @return mixed + */ + public static function updateCurrency($id, $object) + { + return self::updateResource('/currencies/' . $id, $object); + } + + /** + * Delete the given currency. + * + * @param int $id currency id + * @return mixed + */ + public static function deleteCurrency($id) + { + return self::deleteResource('/currencies/' . $id); + } + + /** + * Returns the default collection of currencies. + * + * @param array $filter + * @return mixed array|string list of currencies or XML string if useXml is true + */ + public static function getCurrencies($filter = array()) + { + $filter = Filter::create($filter); + return self::getCollection('/currencies' . $filter->toQuery(), 'Currency'); + } + + /** + * Returns the total number of currencies in the collection. + * + * @param array $filter + * @return int|string number of currencies or XML string if useXml is true + */ + public static function getCurrenciesCount($filter = array()) + { + $filter = Filter::create($filter); + return self::getCount('/currencies/count' . $filter->toQuery()); + } } diff --git a/src/Bigcommerce/Api/Resources/Currency.php b/src/Bigcommerce/Api/Resources/Currency.php new file mode 100644 index 00000000..365aa9f1 --- /dev/null +++ b/src/Bigcommerce/Api/Resources/Currency.php @@ -0,0 +1,38 @@ +getCreateFields()); + } + + public function update() + { + return Client::updateCurrency($this->id, $this->getUpdateFields()); + } + + public function delete() + { + return Client::deleteCurrency($this->id); + } +} diff --git a/test/Unit/Api/ClientTest.php b/test/Unit/Api/ClientTest.php index 0d26b247..dbe7c6cd 100644 --- a/test/Unit/Api/ClientTest.php +++ b/test/Unit/Api/ClientTest.php @@ -261,6 +261,7 @@ public function collections() array('optionsets', 'getOptionSets', 'OptionSet'), array('products/skus', 'getSkus', 'Sku'), array('requestlogs', 'getRequestLogs', 'RequestLog'), + array('currencies', 'getCurrencies', 'Currency'), ); } @@ -313,6 +314,7 @@ public function resources() array('options', '%sOption', 'Option'), array('optionsets', '%sOptionSet', 'OptionSet'), array('coupons', '%sCoupon', 'Coupon'), + array('currencies', '%sCurrency', 'Currency'), ); } diff --git a/test/Unit/Api/Resources/CurrencyTest.php b/test/Unit/Api/Resources/CurrencyTest.php new file mode 100644 index 00000000..05421da0 --- /dev/null +++ b/test/Unit/Api/Resources/CurrencyTest.php @@ -0,0 +1,38 @@ + 1)); + $this->connection->expects($this->once()) + ->method('post') + ->with($this->basePath . '/currencies', (object)array('id' => 1)); + + $currency->create(); + } + + public function testUpdatePassesThroughToConnection() + { + $currency = new Currency((object)array('id' => 1)); + $this->connection->expects($this->once()) + ->method('put') + ->with($this->basePath . '/currencies/1', (object)array()); + + $currency->update(); + } + + public function testDeletePassesThroughToConnection() + { + $currency = new Currency((object)array('id' => 1)); + $this->connection->expects($this->once()) + ->method('delete') + ->with($this->basePath . '/currencies/1'); + + $currency->delete(); + } +}