diff --git a/src/Model/Entity/Store/ProductEditGroupInput.php b/src/Model/Entity/Store/ProductEditGroupInput.php new file mode 100644 index 0000000..0ff8aab --- /dev/null +++ b/src/Model/Entity/Store/ProductEditGroupInput.php @@ -0,0 +1,23 @@ +") + * @JMS\SerializedName("groups") + */ + public $groups; + + /** + * @var string + * + * @JMS\Type("string") + * @JMS\SerializedName("externalId") + */ + public $externalId; + + /** + * @var string + * + * @JMS\Type("string") + * @JMS\SerializedName("manufacturer") + */ + public $manufacturer; + + /** + * @var bool + * + * @JMS\Type("bool") + * @JMS\SerializedName("active") + */ + public $active; + + /** + * @var bool + * + * @JMS\Type("bool") + * @JMS\SerializedName("markable") + */ + public $markable; + + /** + * @var string + * + * @JMS\Type("string") + * @JMS\SerializedName("site") + */ + public $site; + + /** + * @var int + * + * @JMS\Type("int") + * @JMS\SerializedName("catalogId") + */ + public $catalogId; +} diff --git a/src/Model/Entity/Store/ProductEditNotFoundResponse.php b/src/Model/Entity/Store/ProductEditNotFoundResponse.php new file mode 100644 index 0000000..f4bed9e --- /dev/null +++ b/src/Model/Entity/Store/ProductEditNotFoundResponse.php @@ -0,0 +1,23 @@ + 0) { + $this->products = $products; + } + } +} diff --git a/src/Model/Response/Store/ProductBatchEditResponse.php b/src/Model/Response/Store/ProductBatchEditResponse.php new file mode 100644 index 0000000..f460e1d --- /dev/null +++ b/src/Model/Response/Store/ProductBatchEditResponse.php @@ -0,0 +1,39 @@ +") + * @JMS\SerializedName("notFoundProducts") + */ + public $notFoundProducts; +} diff --git a/src/ResourceGroup/Store.php b/src/ResourceGroup/Store.php index 540e021..3dda306 100644 --- a/src/ResourceGroup/Store.php +++ b/src/ResourceGroup/Store.php @@ -13,12 +13,14 @@ use RetailCrm\Api\Enum\RequestMethod; use RetailCrm\Api\Model\Request\Store\InventoriesRequest; use RetailCrm\Api\Model\Request\Store\InventoriesUploadRequest; use RetailCrm\Api\Model\Request\Store\PricesUploadRequest; +use RetailCrm\Api\Model\Request\Store\ProductBatchEditRequest; use RetailCrm\Api\Model\Request\Store\ProductGroupsRequest; use RetailCrm\Api\Model\Request\Store\ProductPropertiesRequest; use RetailCrm\Api\Model\Request\Store\ProductsRequest; use RetailCrm\Api\Model\Response\Store\InventoriesResponse; use RetailCrm\Api\Model\Response\Store\InventoriesUploadResponse; 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\ProductsResponse; @@ -413,4 +415,81 @@ class Store extends AbstractApiResourceGroup ); return $response; } + + /** + * Makes GET "/api/v5/store/store/products/batch/edit" request. + * + * Example: + * ```php + * use RetailCrm\Api\Model\Entity\Store\ProductEditGroupInput; + * use RetailCrm\Api\Model\Entity\Store\ProductEditInput; + * use RetailCrm\Api\Model\Request\Store\ProductBatchEditRequest; + * use RetailCrm\Api\Factory\SimpleClientFactory; + * use RetailCrm\Api\Interfaces\ApiExceptionInterface; + * + * $client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey'); + * + * $productInput = new ProductEditInput(); + * $productInput->name = 'testName'; + * $productInput->description = 'testDescription'; + * $productInput->active = true; + * $productInput->id = 10; + * $productInput->url = 'testUrl'; + * $productInput->article = 'testArticle'; + * $productInput->catalogId = 10; + * $productInput->externalId = 'testExternalId'; + * $productInput->manufacturer = 'testManufacturer'; + * $productInput->markable = true; + * $productInput->novelty = true; + * $productInput->popular = true; + * $productInput->recommended = true; + * $productInput->site = 'testSite'; + * $productInput->stock = true; + * $productEditGroupInput = new ProductEditGroupInput(); + * $productEditGroupInput->externalId = 'testExternalId'; + * $productEditGroupInput->id = 10; + * $productInput->groups[] = $productEditGroupInput; + * + * try { + * $response = $client->store->productBatchEdit(new ProductBatchEditRequest([$productInput])); + * } 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 'Processed product count: ' . $response->processedProductsCount; + * ``` + * + * @param \RetailCrm\Api\Model\Request\Store\ProductBatchEditRequest $request + * + * @return \RetailCrm\Api\Model\Response\Store\ProductBatchEditResponse + * @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 + * @throws \RetailCrm\Api\Interfaces\ApiExceptionInterface + * @throws \RetailCrm\Api\Interfaces\ClientExceptionInterface + */ + public function productBatchEdit(ProductBatchEditRequest $request): ProductBatchEditResponse + { + /** @var ProductBatchEditResponse $response */ + $response = $this->sendRequest( + RequestMethod::POST, + 'store/products/batch/edit', + $request, + ProductBatchEditResponse::class + ); + + return $response; + } } diff --git a/tests/src/ResourceGroup/StoreTest.php b/tests/src/ResourceGroup/StoreTest.php index d5a8968..ae40f84 100644 --- a/tests/src/ResourceGroup/StoreTest.php +++ b/tests/src/ResourceGroup/StoreTest.php @@ -16,6 +16,8 @@ use RetailCrm\Api\Model\Entity\Store\Inventory; use RetailCrm\Api\Model\Entity\Store\Offer; use RetailCrm\Api\Model\Entity\Store\PriceUploadInput; use RetailCrm\Api\Model\Entity\Store\PriceUploadPricesInput; +use RetailCrm\Api\Model\Entity\Store\ProductEditGroupInput; +use RetailCrm\Api\Model\Entity\Store\ProductEditInput; use RetailCrm\Api\Model\Filter\Store\InventoryFilterType; use RetailCrm\Api\Model\Filter\Store\ProductFilterType; use RetailCrm\Api\Model\Filter\Store\ProductGroupFilterType; @@ -23,6 +25,7 @@ use RetailCrm\Api\Model\Filter\Store\ProductPropertiesFilterType; use RetailCrm\Api\Model\Request\Store\InventoriesRequest; use RetailCrm\Api\Model\Request\Store\InventoriesUploadRequest; use RetailCrm\Api\Model\Request\Store\PricesUploadRequest; +use RetailCrm\Api\Model\Request\Store\ProductBatchEditRequest; use RetailCrm\Api\Model\Request\Store\ProductGroupsRequest; use RetailCrm\Api\Model\Request\Store\ProductPropertiesRequest; use RetailCrm\Api\Model\Request\Store\ProductsRequest; @@ -622,4 +625,46 @@ EOF; self::assertModelEqualsToResponse($json, $response); } + + public function testProductBatchEdit(): void + { + $json = <<<'EOF' +{ + "success": true +} +EOF; + + $productInput = new ProductEditInput(); + $productInput->name = 'testName'; + $productInput->description = 'testDescription'; + $productInput->active = true; + $productInput->id = 10; + $productInput->url = 'testUrl'; + $productInput->article = 'testArticle'; + $productInput->catalogId = 10; + $productInput->externalId = 'testExternalId'; + $productInput->manufacturer = 'testManufacturer'; + $productInput->markable = true; + $productInput->novelty = true; + $productInput->popular = true; + $productInput->recommended = true; + $productInput->site = 'testSite'; + $productInput->stock = true; + $productEditGroupInput = new ProductEditGroupInput(); + $productEditGroupInput->externalId = 'testExternalId'; + $productEditGroupInput->id = 10; + $productInput->groups[] = $productEditGroupInput; + $request = new ProductBatchEditRequest([$productInput]); + + $mock = static::createApiMockBuilder('store/products/batch/edit'); + $mock->matchMethod(RequestMethod::POST) + ->matchBody(self::encodeForm($request)) + ->reply(200) + ->withBody($json); + + $client = TestClientFactory::createClient($mock->getClient()); + $response = $client->store->productBatchEdit($request); + + self::assertModelEqualsToResponse($json, $response); + } }