1
0
mirror of synced 2024-11-21 12:56:08 +03:00

Add support for GET "/api/v5/store/products/properties/values" method

This commit is contained in:
Pavel 2024-08-09 12:46:31 +03:00 committed by GitHub
commit 544d16186f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 290 additions and 0 deletions

View File

@ -0,0 +1,45 @@
<?php
/**
* PHP version 7.3
*
* @category ProductPropertyValue
* @package RetailCrm\Api\Model\Entity\Store
*/
namespace RetailCrm\Api\Model\Entity\Store;
use RetailCrm\Api\Component\Serializer\Annotation as JMS;
/**
* Class ProductPropertyValue
*
* @category ProductPropertyValue
* @package RetailCrm\Api\Model\Entity\Store
*/
class ProductPropertyValue
{
/**
* @var \RetailCrm\Api\Model\Entity\Store\ProductProperty
*
* @JMS\Type("RetailCrm\Api\Model\Entity\Store\ProductProperty")
* @JMS\SerializedName("property")
*/
public $property;
/**
* @var string
*
* @JMS\Type("string")
* @JMS\SerializedName("value")
*/
public $value;
/**
* @var int
*
* @JMS\Type("int")
* @JMS\SerializedName("offersCount")
*/
public $offersCount;
}

View File

@ -0,0 +1,45 @@
<?php
/**
* PHP version 7.3
*
* @category ProductPropertyValuesFilterType
* @package RetailCrm\Api\Model\Filter\Store
*/
namespace RetailCrm\Api\Model\Filter\Store;
use RetailCrm\Api\Component\FormData\Mapping as Form;
/**
* Class ProductPropertyValuesFilterType
*
* @category ProductPropertyValuesFilterType
* @package RetailCrm\Api\Model\Filter\Store
*/
class ProductPropertyValuesFilterType
{
/**
* @var string
*
* @Form\Type("string")
* @Form\SerializedName("propertyName")
*/
public $propertyName;
/**
* @var string
*
* @Form\Type("string")
* @Form\SerializedName("propertyCode")
*/
public $propertyCode;
/**
* @var int[]
*
* @Form\Type("int[]")
* @Form\SerializedName("groups")
*/
public $groups;
}

View File

@ -0,0 +1,33 @@
<?php
/**
* PHP version 7.3
*
* @category ProductPropertyValuesRequest
* @package RetailCrm\Api\Model\Request\Store
*/
namespace RetailCrm\Api\Model\Request\Store;
use RetailCrm\Api\Component\FormData\Mapping as Form;
use RetailCrm\Api\Interfaces\RequestInterface;
use RetailCrm\Api\Model\Request\Traits\PageLimitTrait;
/**
* Class ProductPropertyValuesRequest
*
* @category ProductPropertyValuesRequest
* @package RetailCrm\Api\Model\Request\Store
*/
class ProductPropertyValuesRequest implements RequestInterface
{
use PageLimitTrait;
/**
* @var \RetailCrm\Api\Model\Filter\Store\ProductPropertyValuesFilterType
*
* @Form\Type("RetailCrm\Api\Model\Filter\Store\ProductPropertyValuesFilterType")
* @Form\SerializedName("filter")
*/
public $filter;
}

View File

@ -0,0 +1,31 @@
<?php
/**
* PHP version 7.3
*
* @category ProductPropertyValuesResponse
* @package RetailCrm\Api\Model\Response\Store
*/
namespace RetailCrm\Api\Model\Response\Store;
use RetailCrm\Api\Component\Serializer\Annotation as JMS;
use RetailCrm\Api\Model\Response\AbstractPaginatedResponse;
/**
* Class ProductPropertyValuesResponse
*
* @category ProductPropertyValuesResponse
* @package RetailCrm\Api\Model\Response\Store
* @SuppressWarnings(PHPMD.LongVariable)
*/
class ProductPropertyValuesResponse extends AbstractPaginatedResponse
{
/**
* @var \RetailCrm\Api\Model\Entity\Store\ProductPropertyValue[]
*
* @JMS\Type("array<RetailCrm\Api\Model\Entity\Store\ProductPropertyValue>")
* @JMS\SerializedName("productPropertyValues")
*/
public $productPropertyValues;
}

View File

@ -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;
}
}

View File

@ -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);
}
}