From dc9e0a5b39913230e2e3e97b5db97e0c644ef6b5 Mon Sep 17 00:00:00 2001 From: Kirill Sukhorukov Date: Thu, 1 Aug 2024 14:30:28 +0300 Subject: [PATCH] Add support for GET /api/v5/properties/values method --- .../Entity/Store/ProductPropertyValue.php | 45 +++++++++++ .../Store/ProductPropertyValuesFilterType.php | 45 +++++++++++ .../Store/ProductPropertyValuesRequest.php | 33 +++++++++ .../Store/ProductPropertyValuesResponse.php | 31 ++++++++ src/ResourceGroup/Store.php | 62 ++++++++++++++++ tests/src/ResourceGroup/StoreTest.php | 74 +++++++++++++++++++ 6 files changed, 290 insertions(+) create mode 100644 src/Model/Entity/Store/ProductPropertyValue.php create mode 100644 src/Model/Filter/Store/ProductPropertyValuesFilterType.php create mode 100644 src/Model/Request/Store/ProductPropertyValuesRequest.php create mode 100644 src/Model/Response/Store/ProductPropertyValuesResponse.php diff --git a/src/Model/Entity/Store/ProductPropertyValue.php b/src/Model/Entity/Store/ProductPropertyValue.php new file mode 100644 index 0000000..4d163b3 --- /dev/null +++ b/src/Model/Entity/Store/ProductPropertyValue.php @@ -0,0 +1,45 @@ +") + * @JMS\SerializedName("productPropertyValues") + */ + public $productPropertyValues; +} diff --git a/src/ResourceGroup/Store.php b/src/ResourceGroup/Store.php index 0f7e4d5..8bf2ec5 100644 --- a/src/ResourceGroup/Store.php +++ b/src/ResourceGroup/Store.php @@ -18,6 +18,7 @@ use RetailCrm\Api\Model\Request\Store\ProductGroupsCreateRequest; use RetailCrm\Api\Model\Request\Store\ProductGroupsEditRequest; use RetailCrm\Api\Model\Request\Store\ProductGroupsRequest; use RetailCrm\Api\Model\Request\Store\ProductPropertiesRequest; +use RetailCrm\Api\Model\Request\Store\ProductPropertyValuesRequest; use RetailCrm\Api\Model\Request\Store\ProductsBatchCreateRequest; use RetailCrm\Api\Model\Request\Store\ProductsRequest; use RetailCrm\Api\Model\Response\IdResponse; @@ -27,6 +28,7 @@ use RetailCrm\Api\Model\Response\Store\PricesUploadResponse; use RetailCrm\Api\Model\Response\Store\ProductBatchEditResponse; use RetailCrm\Api\Model\Response\Store\ProductGroupsResponse; use RetailCrm\Api\Model\Response\Store\ProductPropertiesResponse; +use RetailCrm\Api\Model\Response\Store\ProductPropertyValuesResponse; use RetailCrm\Api\Model\Response\Store\ProductsBatchCreateResponse; use RetailCrm\Api\Model\Response\Store\ProductsResponse; @@ -690,4 +692,64 @@ class Store extends AbstractApiResourceGroup return $response; } + + /** + * Makes GET "/api/v5/store/products/properties/values" request. + * + * Example: + * ```php + * use RetailCrm\Api\Factory\SimpleClientFactory; + * use RetailCrm\Api\Interfaces\ApiExceptionInterface; + * use RetailCrm\Api\Model\Filter\Store\ProductPropertiesFilterType; + * use RetailCrm\Api\Model\Request\Store\ProductPropertiesRequest; + * + * $client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey'); + * + * $request = new ProductPropertyValuesRequest(); + * $request->filter = new ProductPropertyValuesFilterType(); + * $request->filter->propertyCode = 'property_code'; + * + * try { + * $response = $client->store->productsPropertyValues($request); + * } catch (ApiExceptionInterface $exception) { + * echo sprintf( + * 'Error from RetailCRM API (status code: %d): %s', + * $exception->getStatusCode(), + * $exception->getMessage() + * ); + * + * if (count($exception->getErrorResponse()->errors) > 0) { + * echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors); + * } + * + * return; + * } + * + * echo 'Product property values: ' . print_r($response->productPropertyValues, true); + * ``` + * + * @param \RetailCrm\Api\Model\Request\Store\ProductPropertyValuesRequest|null $request + * + * @return \RetailCrm\Api\Model\Response\Store\ProductPropertyValuesResponse + * @throws \RetailCrm\Api\Interfaces\ApiExceptionInterface + * @throws \RetailCrm\Api\Interfaces\ClientExceptionInterface + * @throws \RetailCrm\Api\Exception\Api\AccountDoesNotExistException + * @throws \RetailCrm\Api\Exception\Api\ApiErrorException + * @throws \RetailCrm\Api\Exception\Api\MissingCredentialsException + * @throws \RetailCrm\Api\Exception\Api\MissingParameterException + * @throws \RetailCrm\Api\Exception\Api\ValidationException + * @throws \RetailCrm\Api\Exception\Client\HandlerException + * @throws \RetailCrm\Api\Exception\Client\HttpClientException + */ + public function productsPropertyValues(?ProductPropertyValuesRequest $request = null): ProductPropertyValuesResponse + { + /** @var ProductPropertyValuesResponse $response */ + $response = $this->sendRequest( + RequestMethod::GET, + 'store/products/properties/values', + $request, + ProductPropertyValuesResponse::class + ); + return $response; + } } diff --git a/tests/src/ResourceGroup/StoreTest.php b/tests/src/ResourceGroup/StoreTest.php index 07b8f56..7a24ea6 100644 --- a/tests/src/ResourceGroup/StoreTest.php +++ b/tests/src/ResourceGroup/StoreTest.php @@ -25,6 +25,7 @@ use RetailCrm\Api\Model\Filter\Store\InventoryFilterType; use RetailCrm\Api\Model\Filter\Store\ProductFilterType; use RetailCrm\Api\Model\Filter\Store\ProductGroupFilterType; use RetailCrm\Api\Model\Filter\Store\ProductPropertiesFilterType; +use RetailCrm\Api\Model\Filter\Store\ProductPropertyValuesFilterType; use RetailCrm\Api\Model\Request\Store\InventoriesRequest; use RetailCrm\Api\Model\Request\Store\InventoriesUploadRequest; use RetailCrm\Api\Model\Request\Store\PricesUploadRequest; @@ -34,6 +35,7 @@ use RetailCrm\Api\Model\Request\Store\ProductGroupsEditRequest; use RetailCrm\Api\Model\Request\Store\ProductGroupsRequest; use RetailCrm\Api\Model\Request\Store\ProductPropertiesRequest; use RetailCrm\Api\Model\Request\Store\ProductPropertiesSort; +use RetailCrm\Api\Model\Request\Store\ProductPropertyValuesRequest; use RetailCrm\Api\Model\Request\Store\ProductsBatchCreateRequest; use RetailCrm\Api\Model\Request\Store\ProductsRequest; use RetailCrm\TestUtils\Factory\TestClientFactory; @@ -783,4 +785,76 @@ EOF; self::assertModelEqualsToResponse($json, $response); } + + public function testProductPropertyValues(): void + { + $json = <<<'EOF' +{ + "success": true, + "pagination": { + "limit": 20, + "totalCount": 1, + "currentPage": 1, + "totalPageCount": 1 + }, + "productPropertyValues": [ + { + "property": { + "sites": [ + "e-mapper", + "sendpulse", + "glavpunkt", + "retailcrm-services-peshkariki", + "vk-com", + "moysklad", + "eftestshop-ru" + ], + "groups": [ + { + "id": 3676, + "name": "warehouseRoot" + }, + { + "id": 3679, + "name": "Входящая в группу" + }, + { + "id": 3680, + "name": "test" + }, + { + "id": 3724, + "name": "Услуги" + } + ], + "code": "code", + "name": "Код", + "isNumeric": false, + "visible": true, + "variative": true + }, + "value": "testValue", + "offersCount": 10 + } + ] +} +EOF; + + $request = new ProductPropertyValuesRequest(); + $request->filter = new ProductPropertyValuesFilterType(); + $request->filter->propertyName = "testName"; + $request->filter->propertyCode = "testCode"; + $request->filter->groups = [1, 2, 3]; + + $mock = static::createApiMockBuilder('store/products/properties/values'); + $mock->matchMethod(RequestMethod::GET) + ->matchQuery(self::encodeFormArray($request)) + ->reply(200) + ->withBody($json); + + $client = TestClientFactory::createClient($mock->getClient()); + $response = $client->store->productsPropertyValues($request); + + self::assertModelEqualsToResponse($json, $response); + } }