Skip to content

Commit

Permalink
Add support for GET /api/v5/properties/values method
Browse files Browse the repository at this point in the history
  • Loading branch information
kifril committed Aug 7, 2024
1 parent 5b04bd9 commit d9d5028
Show file tree
Hide file tree
Showing 6 changed files with 290 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/Model/Entity/Store/ProductPropertyValue.php
Original file line number Diff line number Diff line change
@@ -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;
}
45 changes: 45 additions & 0 deletions src/Model/Filter/Store/ProductPropertyValuesFilterType.php
Original file line number Diff line number Diff line change
@@ -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;
}
33 changes: 33 additions & 0 deletions src/Model/Request/Store/ProductPropertyValuesRequest.php
Original file line number Diff line number Diff line change
@@ -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;
}
31 changes: 31 additions & 0 deletions src/Model/Response/Store/ProductPropertyValuesResponse.php
Original file line number Diff line number Diff line change
@@ -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
*/
class ProductPropertyValuesResponse extends AbstractPaginatedResponse
{
/**
* @var \RetailCrm\Api\Model\Entity\Store\ProductPropertyValue[]
*
* @JMS\Type("array<RetailCrm\Api\Model\Entity\Store\ProductPropertyValue>")
* @JMS\SerializedName("productPropertyValues")
* @SuppressWarnings(PHPMD.LongVariable)
*/
public $productPropertyValues;

Check warning on line 30 in src/Model/Response/Store/ProductPropertyValuesResponse.php

View workflow job for this annotation

GitHub Actions / PHP MessDetector

[PHPMD] reported by reviewdog 🐶 LongVariable Avoid excessively long variable names like $productPropertyValues. Keep variable name length under 20. Raw Output: /github/workspace/src/Model/Response/Store/ProductPropertyValuesResponse.php:30:LongVariable Avoid excessively long variable names like $productPropertyValues. Keep variable name length under 20.
}
62 changes: 62 additions & 0 deletions src/ResourceGroup/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,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\ProductPropertyValuesRequest;
use RetailCrm\Api\Model\Request\Store\ProductsBatchCreateRequest;
use RetailCrm\Api\Model\Request\Store\ProductsRequest;
use RetailCrm\Api\Model\Response\IdResponse;
Expand All @@ -27,6 +28,7 @@
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;

Expand Down Expand Up @@ -690,4 +692,64 @@ public function productsBatchCreate(ProductsBatchCreateRequest $request): Produc

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;
}
}
74 changes: 74 additions & 0 deletions tests/src/ResourceGroup/StoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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;
Expand All @@ -34,6 +35,7 @@
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;
Expand Down Expand Up @@ -783,4 +785,76 @@ public function testProductGroupsEdit(): void

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

0 comments on commit d9d5028

Please sign in to comment.