diff --git a/src/Factory/SerializerFactory.php b/src/Factory/SerializerFactory.php index 793ce3a..c49053c 100644 --- a/src/Factory/SerializerFactory.php +++ b/src/Factory/SerializerFactory.php @@ -95,23 +95,6 @@ class SerializerFactory implements FactoryInterface 'json', $returnNull ); - $registry->registerHandler( - GraphNavigatorInterface::DIRECTION_SERIALIZATION, - 'RequestDtoInterface', - 'xml', - function ($visitor, $obj, array $type) use ($container) { - /** @var SerializerInterface $serializer */ - $serializer = $container->get(Constants::SERIALIZER); - - return $serializer->serialize($obj, 'xml'); - } - ); - $registry->registerHandler( - GraphNavigatorInterface::DIRECTION_DESERIALIZATION, - 'RequestDtoInterface', - 'xml', - $returnNull - ); $registry->registerHandler( GraphNavigatorInterface::DIRECTION_SERIALIZATION, 'FileItemInterface', @@ -124,18 +107,6 @@ class SerializerFactory implements FactoryInterface 'json', $returnNull ); - $registry->registerHandler( - GraphNavigatorInterface::DIRECTION_SERIALIZATION, - 'FileItemInterface', - 'xml', - $returnSame - ); - $registry->registerHandler( - GraphNavigatorInterface::DIRECTION_DESERIALIZATION, - 'FileItemInterface', - 'xml', - $returnNull - ); })->addDefaultHandlers() ->setSerializationVisitor('json', new JsonSerializationVisitorFactory()) ->setDeserializationVisitor('json', new JsonDeserializationVisitorFactory()) diff --git a/src/Factory/TopRequestFactory.php b/src/Factory/TopRequestFactory.php index e88a344..074155e 100644 --- a/src/Factory/TopRequestFactory.php +++ b/src/Factory/TopRequestFactory.php @@ -143,6 +143,9 @@ class TopRequestFactory implements TopRequestFactoryInterface return $this->makeMultipartRequest($appData->getServiceUrl(), $requestData); } + //TODO + // And how this call should process arrays? It will process them, yes. + // But in which format AliExpress TOP expects that? Should definitely check that. $queryData = http_build_query($requestData); return $this->requestFactory diff --git a/src/Model/Request/AliExpress/Data/SingleItemRequestDto.php b/src/Model/Request/AliExpress/Data/SingleItemRequestDto.php new file mode 100644 index 0000000..5f17eab --- /dev/null +++ b/src/Model/Request/AliExpress/Data/SingleItemRequestDto.php @@ -0,0 +1,44 @@ + + * @license http://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see http://help.retailcrm.ru + */ + +namespace RetailCrm\Model\Request\AliExpress\Data; + +use JMS\Serializer\Annotation as JMS; + +/** + * Class SingleItemRequestDto + * + * @category SingleItemRequestDto + * @package RetailCrm\Model\Request\AliExpress\Data + * @author RetailDriver LLC + * @license https://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see https://help.retailcrm.ru + */ +class SingleItemRequestDto +{ + /** + * @var \RetailCrm\Interfaces\RequestDtoInterface $itemContent + * + * @JMS\Type("RetailCrm\Interfaces\RequestDtoInterface") + * @JMS\SerializedName("item_content") + */ + public $itemContent; + + /** + * @var string $itemContentId + * + * @JMS\Type("string") + * @JMS\SerializedName("item_content_id") + */ + public $itemContentId; +} diff --git a/src/Model/Request/AliExpress/SolutionFeedSubmit.php b/src/Model/Request/AliExpress/SolutionFeedSubmit.php new file mode 100644 index 0000000..b7205fd --- /dev/null +++ b/src/Model/Request/AliExpress/SolutionFeedSubmit.php @@ -0,0 +1,76 @@ + + * @license http://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see http://help.retailcrm.ru + */ + +namespace RetailCrm\Model\Request\AliExpress; + +use JMS\Serializer\Annotation as JMS; +use RetailCrm\Model\Request\AliExpress\Data\SingleItemRequestDto; +use RetailCrm\Model\Request\BaseRequest; +use RetailCrm\Model\Response\AliExpress\SolutionFeedSubmitResponse; +use Symfony\Component\Validator\Constraints as Assert; + +/** + * Class SolutionFeedSubmit + * + * @category SolutionFeedSubmit + * @package RetailCrm\Model\Request\AliExpress + * @author RetailDriver LLC + * @license https://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see https://help.retailcrm.ru + */ +class SolutionFeedSubmit extends BaseRequest +{ + public const PRODUCT_CREATE = 'PRODUCT_CREATE'; + public const PRODUCT_FULL_UPDATE = 'PRODUCT_FULL_UPDATE'; + public const PRODUCT_STOCKS_UPDATE = 'PRODUCT_STOCKS_UPDATE'; + public const PRODUCT_PRICES_UPDATE = 'PRODUCT_PRICES_UPDATE'; + + /** + * @var string $operationType + * + * @JMS\Type("string") + * @JMS\SerializedName("operation_type") + * @Assert\Choice({ + * "PRODUCT_CREATE", + * "PRODUCT_FULL_UPDATE", + * "PRODUCT_STOCKS_UPDATE", + * "PRODUCT_PRICES_UPDATE" + * }) + */ + public $operationType; + + /** + * @var SingleItemRequestDto[] $itemList + * + * @JMS\Type("array") + * @JMS\SerializedName("item_list") + * @Assert\NotBlank() + */ + public $itemList; + + /** + * @inheritDoc + */ + public function getMethod(): string + { + return 'aliexpress.solution.feed.submit'; + } + + /** + * @inheritDoc + */ + public function getExpectedResponse(): string + { + return SolutionFeedSubmitResponse::class; + } +} diff --git a/src/Model/Response/AliExpress/Data/SolutionFeedSubmitResponseData.php b/src/Model/Response/AliExpress/Data/SolutionFeedSubmitResponseData.php new file mode 100644 index 0000000..1a76129 --- /dev/null +++ b/src/Model/Response/AliExpress/Data/SolutionFeedSubmitResponseData.php @@ -0,0 +1,37 @@ + + * @license http://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see http://help.retailcrm.ru + */ + +namespace RetailCrm\Model\Response\AliExpress\Data; + +use RetailCrm\Model\Response\AbstractResponseData; +use JMS\Serializer\Annotation as JMS; + +/** + * Class SolutionFeedSubmitResponseData + * + * @category SolutionFeedSubmitResponseData + * @package RetailCrm\Model\Response\AliExpress\Data + * @author RetailDriver LLC + * @license https://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see https://help.retailcrm.ru + */ +class SolutionFeedSubmitResponseData extends AbstractResponseData +{ + /** + * @var int $jobId + * + * @JMS\Type("int") + * @JMS\SerializedName("job_id") + */ + public $jobId; +} diff --git a/src/Model/Response/AliExpress/SolutionFeedSubmitResponse.php b/src/Model/Response/AliExpress/SolutionFeedSubmitResponse.php new file mode 100644 index 0000000..c5ae222 --- /dev/null +++ b/src/Model/Response/AliExpress/SolutionFeedSubmitResponse.php @@ -0,0 +1,37 @@ + + * @license http://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see http://help.retailcrm.ru + */ + +namespace RetailCrm\Model\Response\AliExpress; + +use RetailCrm\Model\Response\BaseResponse; +use JMS\Serializer\Annotation as JMS; + +/** + * Class SolutionFeedSubmitResponse + * + * @category SolutionFeedSubmitResponse + * @package RetailCrm\Model\Response\AliExpress + * @author RetailDriver LLC + * @license https://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see https://help.retailcrm.ru + */ +class SolutionFeedSubmitResponse extends BaseResponse +{ + /** + * @var \RetailCrm\Model\Response\AliExpress\Data\SolutionFeedSubmitResponseData $responseData + * + * @JMS\Type("RetailCrm\Model\Response\AliExpress\Data\SolutionFeedSubmitResponseData") + * @JMS\SerializedName("aliexpress_solution_feed_submit_response") + */ + public $responseData; +} diff --git a/src/Model/Response/AliExpress/SolutionSellerCategoryTreeQueryResponse.php b/src/Model/Response/AliExpress/SolutionSellerCategoryTreeQueryResponse.php index 70be81c..b303638 100644 --- a/src/Model/Response/AliExpress/SolutionSellerCategoryTreeQueryResponse.php +++ b/src/Model/Response/AliExpress/SolutionSellerCategoryTreeQueryResponse.php @@ -13,7 +13,6 @@ namespace RetailCrm\Model\Response\AliExpress; use RetailCrm\Model\Response\BaseResponse; - use JMS\Serializer\Annotation as JMS; /** diff --git a/tests/RetailCrm/Test/FakeDataRequestDto.php b/tests/RetailCrm/Test/FakeDataRequestDto.php new file mode 100644 index 0000000..253ad1c --- /dev/null +++ b/tests/RetailCrm/Test/FakeDataRequestDto.php @@ -0,0 +1,37 @@ + + * @license http://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see http://help.retailcrm.ru + */ + +namespace RetailCrm\Test; + +use RetailCrm\Interfaces\RequestDtoInterface; +use JMS\Serializer\Annotation as JMS; + +/** + * Class FakeDataRequestDto + * + * @category FakeDataRequestDto + * @package RetailCrm\Test + * @author RetailDriver LLC + * @license https://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see https://help.retailcrm.ru + */ +class FakeDataRequestDto implements RequestDtoInterface +{ + /** + * @var string $code + * + * @JMS\Type("string") + * @JMS\SerializedName("code") + */ + public $code; +} diff --git a/tests/RetailCrm/Tests/TopClient/ClientTest.php b/tests/RetailCrm/Tests/TopClient/ClientTest.php index 7d27366..b4082bf 100644 --- a/tests/RetailCrm/Tests/TopClient/ClientTest.php +++ b/tests/RetailCrm/Tests/TopClient/ClientTest.php @@ -18,15 +18,20 @@ use RetailCrm\Builder\ClientBuilder; use RetailCrm\Component\AppData; use RetailCrm\Component\Constants; use RetailCrm\Model\Entity\CategoryInfo; +use RetailCrm\Model\Request\AliExpress\Data\SingleItemRequestDto; use RetailCrm\Model\Request\AliExpress\PostproductRedefiningCategoryForecast; +use RetailCrm\Model\Request\AliExpress\SolutionFeedSubmit; use RetailCrm\Model\Request\AliExpress\SolutionSellerCategoryTreeQuery; use RetailCrm\Model\Request\Taobao\HttpDnsGetRequest; +use RetailCrm\Model\Response\AliExpress\Data\SolutionFeedSubmitResponseData; use RetailCrm\Model\Response\AliExpress\Data\SolutionSellerCategoryTreeQueryResponseData; use RetailCrm\Model\Response\AliExpress\Data\SolutionSellerCategoryTreeQueryResponseDataChildrenCategoryList; use RetailCrm\Model\Response\AliExpress\PostproductRedefiningCategoryForecastResponse; +use RetailCrm\Model\Response\AliExpress\SolutionFeedSubmitResponse; use RetailCrm\Model\Response\AliExpress\SolutionSellerCategoryTreeQueryResponse; use RetailCrm\Model\Response\ErrorResponseBody; use RetailCrm\Model\Response\Taobao\HttpDnsGetResponse; +use RetailCrm\Test\FakeDataRequestDto; use RetailCrm\Test\TestCase; use RetailCrm\Test\RequestMatcher; @@ -216,4 +221,46 @@ EOF; self::assertEquals('24000011', $response->responseData->result->errorCode); self::assertTrue($response->responseData->result->success); } + + public function testClientAliexpressSolutionFeedSubmit() + { + $json = <<<'EOF' +{ + "aliexpress_solution_feed_submit_response":{ + "job_id":200000000060024475 + } +} +EOF; + + $mock = self::getMockClient(); + $mock->on( + RequestMatcher::createMatcher('api.taobao.com') + ->setPath('/router/rest') + ->setOptionalQueryParams([ + 'app_key' => self::getEnvAppKey(), + 'method' => 'aliexpress.solution.feed.submit' + ]), + $this->responseJson(200, $json) + ); + $client = ClientBuilder::create() + ->setContainer($this->getContainer($mock)) + ->setAppData($this->getEnvAppData()) + ->setAuthenticator($this->getEnvTokenAuthenticator()) + ->build(); + $dto = new FakeDataRequestDto(); + $item = new SingleItemRequestDto(); + $request = new SolutionFeedSubmit(); + + $dto->code = 'code'; + $item->itemContent = $dto; + $item->itemContentId = 'A00000000Y1'; + $request->operationType = SolutionFeedSubmit::PRODUCT_PRICES_UPDATE; + $request->itemList = [$item]; + + /** @var SolutionFeedSubmitResponse $response */ + $response = $client->sendAuthenticatedRequest($request); + + self::assertInstanceOf(SolutionFeedSubmitResponseData::class, $response->responseData); + self::assertEquals(200000000060024475, $response->responseData->jobId); + } }