Add product batch edit request (#127)
This commit is contained in:
parent
649b60b392
commit
f0a1adfb3d
23
src/Model/Entity/Store/ProductEditGroupInput.php
Normal file
23
src/Model/Entity/Store/ProductEditGroupInput.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ProductEditGroupInput
|
||||||
|
*
|
||||||
|
* @category ProductEditGroupInput
|
||||||
|
* @package RetailCrm\Api\Model\Response\Store
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace RetailCrm\Api\Model\Entity\Store;
|
||||||
|
|
||||||
|
use RetailCrm\Api\Component\Serializer\Annotation as JMS;
|
||||||
|
use RetailCrm\Api\Model\Entity\FixExternalRow;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ProductEditGroupInput
|
||||||
|
*
|
||||||
|
* @category ProductEditGroupInput
|
||||||
|
* @package RetailCrm\Api\Model\Response\Store
|
||||||
|
*/
|
||||||
|
class ProductEditGroupInput extends FixExternalRow
|
||||||
|
{
|
||||||
|
}
|
149
src/Model/Entity/Store/ProductEditInput.php
Normal file
149
src/Model/Entity/Store/ProductEditInput.php
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PHP version 7.3
|
||||||
|
*
|
||||||
|
* @category ProductEditInput
|
||||||
|
* @package RetailCrm\Api\Model\Request\Store
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace RetailCrm\Api\Model\Entity\Store;
|
||||||
|
|
||||||
|
use RetailCrm\Api\Component\Serializer\Annotation as JMS;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ProductEditInput
|
||||||
|
*
|
||||||
|
* @category ProductEditInput
|
||||||
|
* @package RetailCrm\Api\Model\Response\Store
|
||||||
|
*/
|
||||||
|
class ProductEditInput
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*
|
||||||
|
* @JMS\Type("int")
|
||||||
|
* @JMS\SerializedName("id")
|
||||||
|
*/
|
||||||
|
public $id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*
|
||||||
|
* @JMS\Type("string")
|
||||||
|
* @JMS\SerializedName("article")
|
||||||
|
*/
|
||||||
|
public $article;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*
|
||||||
|
* @JMS\Type("string")
|
||||||
|
* @JMS\SerializedName("name")
|
||||||
|
*/
|
||||||
|
public $name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*
|
||||||
|
* @JMS\Type("string")
|
||||||
|
* @JMS\SerializedName("url")
|
||||||
|
*/
|
||||||
|
public $url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*
|
||||||
|
* @JMS\Type("string")
|
||||||
|
* @JMS\SerializedName("description")
|
||||||
|
*/
|
||||||
|
public $description;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool
|
||||||
|
*
|
||||||
|
* @JMS\Type("bool")
|
||||||
|
* @JMS\SerializedName("popular")
|
||||||
|
*/
|
||||||
|
public $popular;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool
|
||||||
|
*
|
||||||
|
* @JMS\Type("bool")
|
||||||
|
* @JMS\SerializedName("stock")
|
||||||
|
*/
|
||||||
|
public $stock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool
|
||||||
|
*
|
||||||
|
* @JMS\Type("bool")
|
||||||
|
* @JMS\SerializedName("novelty")
|
||||||
|
*/
|
||||||
|
public $novelty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool
|
||||||
|
*
|
||||||
|
* @JMS\Type("bool")
|
||||||
|
* @JMS\SerializedName("recommended")
|
||||||
|
*/
|
||||||
|
public $recommended;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \RetailCrm\Api\Model\Entity\Store\ProductEditGroupInput[]
|
||||||
|
*
|
||||||
|
* @JMS\Type("array<RetailCrm\Api\Model\Entity\Store\ProductEditGroupInput>")
|
||||||
|
* @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;
|
||||||
|
}
|
23
src/Model/Entity/Store/ProductEditNotFoundResponse.php
Normal file
23
src/Model/Entity/Store/ProductEditNotFoundResponse.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PHP version 7.3
|
||||||
|
*
|
||||||
|
* @category ProductEditNotFoundResponse
|
||||||
|
* @package RetailCrm\Api\Model\Request\Store
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace RetailCrm\Api\Model\Entity\Store;
|
||||||
|
|
||||||
|
use RetailCrm\Api\Component\Serializer\Annotation as JMS;
|
||||||
|
use RetailCrm\Api\Model\Entity\FixExternalRow;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ProductEditNotFoundResponse
|
||||||
|
*
|
||||||
|
* @category ProductEditNotFoundResponse
|
||||||
|
* @package RetailCrm\Api\Model\Entity\Store
|
||||||
|
*/
|
||||||
|
class ProductEditNotFoundResponse extends FixExternalRow
|
||||||
|
{
|
||||||
|
}
|
43
src/Model/Request/Store/ProductBatchEditRequest.php
Normal file
43
src/Model/Request/Store/ProductBatchEditRequest.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PHP version 7.3
|
||||||
|
*
|
||||||
|
* @category ProductBatchEditRequest
|
||||||
|
* @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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ProductBatchEditRequest
|
||||||
|
*
|
||||||
|
* @category ProductBatchEditRequest
|
||||||
|
* @package RetailCrm\Api\Model\Response\Store
|
||||||
|
*/
|
||||||
|
class ProductBatchEditRequest implements RequestInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var \RetailCrm\Api\Model\Entity\Store\ProductEditInput[]
|
||||||
|
*
|
||||||
|
* @Form\Type("RetailCrm\Api\Model\Entity\Store\ProductEditInput[]")
|
||||||
|
* @Form\SerializedName("products")
|
||||||
|
* @Form\JsonField()
|
||||||
|
*/
|
||||||
|
public $products;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ProductBatchEditRequest constructor.
|
||||||
|
*
|
||||||
|
* @param \RetailCrm\Api\Model\Entity\Store\ProductEditInput[] $products
|
||||||
|
*/
|
||||||
|
public function __construct(array $products = [])
|
||||||
|
{
|
||||||
|
if (count($products) > 0) {
|
||||||
|
$this->products = $products;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
39
src/Model/Response/Store/ProductBatchEditResponse.php
Normal file
39
src/Model/Response/Store/ProductBatchEditResponse.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PHP version 7.3
|
||||||
|
*
|
||||||
|
* @category ProductBatchEditResponse
|
||||||
|
* @package RetailCrm\Api\Model\Request\Store
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace RetailCrm\Api\Model\Response\Store;
|
||||||
|
|
||||||
|
use RetailCrm\Api\Model\Response\SuccessResponse;
|
||||||
|
use RetailCrm\Api\Component\Serializer\Annotation as JMS;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ProductBatchEditResponse
|
||||||
|
*
|
||||||
|
* @category ProductBatchEditResponse
|
||||||
|
* @package RetailCrm\Api\Model\Response\Store
|
||||||
|
* @SuppressWarnings(PHPMD.LongVariable)
|
||||||
|
*/
|
||||||
|
class ProductBatchEditResponse extends SuccessResponse
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*
|
||||||
|
* @JMS\Type("int")
|
||||||
|
* @JMS\SerializedName("processedProductsCount")
|
||||||
|
*/
|
||||||
|
public $processedProductsCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \RetailCrm\Api\Model\Entity\Store\ProductEditNotFoundResponse[]
|
||||||
|
*
|
||||||
|
* @JMS\Type("array<RetailCrm\Api\Model\Entity\Store\ProductEditNotFoundResponse>")
|
||||||
|
* @JMS\SerializedName("notFoundProducts")
|
||||||
|
*/
|
||||||
|
public $notFoundProducts;
|
||||||
|
}
|
@ -13,12 +13,14 @@ use RetailCrm\Api\Enum\RequestMethod;
|
|||||||
use RetailCrm\Api\Model\Request\Store\InventoriesRequest;
|
use RetailCrm\Api\Model\Request\Store\InventoriesRequest;
|
||||||
use RetailCrm\Api\Model\Request\Store\InventoriesUploadRequest;
|
use RetailCrm\Api\Model\Request\Store\InventoriesUploadRequest;
|
||||||
use RetailCrm\Api\Model\Request\Store\PricesUploadRequest;
|
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\ProductGroupsRequest;
|
||||||
use RetailCrm\Api\Model\Request\Store\ProductPropertiesRequest;
|
use RetailCrm\Api\Model\Request\Store\ProductPropertiesRequest;
|
||||||
use RetailCrm\Api\Model\Request\Store\ProductsRequest;
|
use RetailCrm\Api\Model\Request\Store\ProductsRequest;
|
||||||
use RetailCrm\Api\Model\Response\Store\InventoriesResponse;
|
use RetailCrm\Api\Model\Response\Store\InventoriesResponse;
|
||||||
use RetailCrm\Api\Model\Response\Store\InventoriesUploadResponse;
|
use RetailCrm\Api\Model\Response\Store\InventoriesUploadResponse;
|
||||||
use RetailCrm\Api\Model\Response\Store\PricesUploadResponse;
|
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\ProductGroupsResponse;
|
||||||
use RetailCrm\Api\Model\Response\Store\ProductPropertiesResponse;
|
use RetailCrm\Api\Model\Response\Store\ProductPropertiesResponse;
|
||||||
use RetailCrm\Api\Model\Response\Store\ProductsResponse;
|
use RetailCrm\Api\Model\Response\Store\ProductsResponse;
|
||||||
@ -413,4 +415,81 @@ class Store extends AbstractApiResourceGroup
|
|||||||
);
|
);
|
||||||
return $response;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@ use RetailCrm\Api\Model\Entity\Store\Inventory;
|
|||||||
use RetailCrm\Api\Model\Entity\Store\Offer;
|
use RetailCrm\Api\Model\Entity\Store\Offer;
|
||||||
use RetailCrm\Api\Model\Entity\Store\PriceUploadInput;
|
use RetailCrm\Api\Model\Entity\Store\PriceUploadInput;
|
||||||
use RetailCrm\Api\Model\Entity\Store\PriceUploadPricesInput;
|
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\InventoryFilterType;
|
||||||
use RetailCrm\Api\Model\Filter\Store\ProductFilterType;
|
use RetailCrm\Api\Model\Filter\Store\ProductFilterType;
|
||||||
use RetailCrm\Api\Model\Filter\Store\ProductGroupFilterType;
|
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\InventoriesRequest;
|
||||||
use RetailCrm\Api\Model\Request\Store\InventoriesUploadRequest;
|
use RetailCrm\Api\Model\Request\Store\InventoriesUploadRequest;
|
||||||
use RetailCrm\Api\Model\Request\Store\PricesUploadRequest;
|
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\ProductGroupsRequest;
|
||||||
use RetailCrm\Api\Model\Request\Store\ProductPropertiesRequest;
|
use RetailCrm\Api\Model\Request\Store\ProductPropertiesRequest;
|
||||||
use RetailCrm\Api\Model\Request\Store\ProductsRequest;
|
use RetailCrm\Api\Model\Request\Store\ProductsRequest;
|
||||||
@ -622,4 +625,46 @@ EOF;
|
|||||||
|
|
||||||
self::assertModelEqualsToResponse($json, $response);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user