diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b84ec0..b734830 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Next release New features: - `GET /api/v1/cloudstorages` added. (`Client::getCloudStorages()`) +- `GET /api/v1/products/category` added. (`Client::getCategories()`) ## 1.6.2 (16 Sep 2019) diff --git a/src/Client.php b/src/Client.php index 3d2e29a..95e1058 100644 --- a/src/Client.php +++ b/src/Client.php @@ -94,7 +94,7 @@ public function __construct($username, $apiPassword, $apiKey, LoggerInterface $l try { $this->jom = new ObjectMapper(new JsonSerializer()); } catch (Exception $ex) { - if($logger !== null) { + if ($logger !== null) { $this->logger->critical('Object Mapper could not be created.'); } throw $ex; @@ -139,12 +139,11 @@ public function getProducts($page = 1, $pageSize = 50, DateTime $minCreatedAt = * * @param int $productId The product id * @param string $lookupBy Either the value id, ean or the value sku to specify the meaning of the id parameter - * @see \BillbeeDe\BillbeeAPI\Type\ProductLookupBy - * * @return Response\GetProductResponse The product response * * @throws QuotaExceededException If the maximum number of calls per second exceeded * @throws Exception If the response cannot be parsed + * @see \BillbeeDe\BillbeeAPI\Type\ProductLookupBy */ public function getProduct($productId, $lookupBy = Type\ProductLookupBy::ID) { @@ -155,6 +154,24 @@ public function getProduct($productId, $lookupBy = Type\ProductLookupBy::ID) ); } + /** + * Get a list of all defined categories + * + * @return Response\GetCategoriesResponse The category response + * + * @throws QuotaExceededException If the maximum number of calls per second exceeded + * @throws Exception If the response cannot be parsed + * + */ + public function getCategories() + { + return $this->requestGET( + 'products/category', + [], + Response\GetCategoriesResponse::class + ); + } + #endregion #region POST diff --git a/src/Response/GetCategoriesResponse.php b/src/Response/GetCategoriesResponse.php new file mode 100644 index 0000000..ebf1566 --- /dev/null +++ b/src/Response/GetCategoriesResponse.php @@ -0,0 +1,24 @@ + + */ + +namespace BillbeeDe\BillbeeAPI\Response; + +use MintWare\DMM\DataField; + +class GetCategoriesResponse extends BaseResponse +{ + /** + * @var \BillbeeDe\BillbeeAPI\Model\Category[] + * @DataField(name="Data", type="\BillbeeDe\BillbeeAPI\Model\Category[]") + */ + public $data = null; +} diff --git a/test_config.dist.yml b/test_config.dist.yml index 1aa8648..6103051 100644 --- a/test_config.dist.yml +++ b/test_config.dist.yml @@ -15,6 +15,7 @@ test_delete_web_hooks: false # If true, the delete all web hooks call will be te customer_id: '' # Id of a customer address_id: '' # Id of an address cloud_storage_id: 0 # Id of an cloud storage +category_id: 0 # Id of c category # Test Shipping: shippable_order_id: '' # Id of an order which can be shipped shipping_provider_id: '' # The Id of a shipping provider diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 7a20863..8337ef2 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -88,6 +88,7 @@ class ClientTest extends TestCase protected $shippingProviderId; protected $shippingProviderProduct; protected $cloudStorageId = 0; + protected $categoryId = 0; public function __construct($name = null, array $data = [], $dataName = '') { @@ -114,6 +115,7 @@ public function __construct($name = null, array $data = [], $dataName = '') $this->shippingProviderId, $this->shippingProviderProduct, $this->cloudStorageId, + $this->categoryId, ) = [ $data['username'], $data['password'], @@ -134,6 +136,7 @@ public function __construct($name = null, array $data = [], $dataName = '') $data['shipping_provider_id'], $data['shipping_provider_product'], $data['cloud_storage_id'], + $data['category_id'], ]; } @@ -1171,6 +1174,29 @@ public function testGetCloudStorages() $this->assertTrue($containsCloudStorage); } + /** @throws Exception */ + public function testGetCategories() + { + if ($this->categoryId == 0) { + return; + } + + $client = $this->getClient(); + sleep(1); + $categories = $client->getCategories(); + $this->assertGreaterThanOrEqual(1, count($categories->data)); + + $containsCategory = false; + foreach ($categories->data as $category) { + if ($category->id == $this->categoryId) { + $containsCategory = true; + break; + } + } + + $this->assertTrue($containsCategory); + } + /** @throws Exception */ public function getClient() {