1
0
mirror of synced 2024-11-22 21:06:01 +03:00

skeleton for feed solution

This commit is contained in:
Pavel 2020-10-01 17:27:18 +03:00
parent 694b59d3b8
commit 5ee9f2a1fc
9 changed files with 281 additions and 30 deletions

View File

@ -95,23 +95,6 @@ class SerializerFactory implements FactoryInterface
'json', 'json',
$returnNull $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( $registry->registerHandler(
GraphNavigatorInterface::DIRECTION_SERIALIZATION, GraphNavigatorInterface::DIRECTION_SERIALIZATION,
'FileItemInterface', 'FileItemInterface',
@ -124,18 +107,6 @@ class SerializerFactory implements FactoryInterface
'json', 'json',
$returnNull $returnNull
); );
$registry->registerHandler(
GraphNavigatorInterface::DIRECTION_SERIALIZATION,
'FileItemInterface',
'xml',
$returnSame
);
$registry->registerHandler(
GraphNavigatorInterface::DIRECTION_DESERIALIZATION,
'FileItemInterface',
'xml',
$returnNull
);
})->addDefaultHandlers() })->addDefaultHandlers()
->setSerializationVisitor('json', new JsonSerializationVisitorFactory()) ->setSerializationVisitor('json', new JsonSerializationVisitorFactory())
->setDeserializationVisitor('json', new JsonDeserializationVisitorFactory()) ->setDeserializationVisitor('json', new JsonDeserializationVisitorFactory())

View File

@ -143,6 +143,9 @@ class TopRequestFactory implements TopRequestFactoryInterface
return $this->makeMultipartRequest($appData->getServiceUrl(), $requestData); 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); $queryData = http_build_query($requestData);
return $this->requestFactory return $this->requestFactory

View File

@ -0,0 +1,44 @@
<?php
/**
* PHP version 7.4
*
* @category SingleItemRequestDto
* @package RetailCrm\Model\Request\AliExpress\Data
* @author RetailCRM <integration@retailcrm.ru>
* @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 <integration@retailcrm.ru>
* @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;
}

View File

@ -0,0 +1,76 @@
<?php
/**
* PHP version 7.4
*
* @category SolutionFeedSubmit
* @package RetailCrm\Model\Request\AliExpress
* @author RetailCRM <integration@retailcrm.ru>
* @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 <integration@retailcrm.ru>
* @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<RetailCrm\Model\Request\AliExpress\Data\SingleItemRequestDto>")
* @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;
}
}

View File

@ -0,0 +1,37 @@
<?php
/**
* PHP version 7.4
*
* @category SolutionFeedSubmitResponseData
* @package RetailCrm\Model\Response\AliExpress\Data
* @author RetailCRM <integration@retailcrm.ru>
* @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 <integration@retailcrm.ru>
* @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;
}

View File

@ -0,0 +1,37 @@
<?php
/**
* PHP version 7.4
*
* @category SolutionFeedSubmitResponse
* @package RetailCrm\Model\Response\AliExpress
* @author RetailCRM <integration@retailcrm.ru>
* @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 <integration@retailcrm.ru>
* @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;
}

View File

@ -13,7 +13,6 @@
namespace RetailCrm\Model\Response\AliExpress; namespace RetailCrm\Model\Response\AliExpress;
use RetailCrm\Model\Response\BaseResponse; use RetailCrm\Model\Response\BaseResponse;
use JMS\Serializer\Annotation as JMS; use JMS\Serializer\Annotation as JMS;
/** /**

View File

@ -0,0 +1,37 @@
<?php
/**
* PHP version 7.4
*
* @category FakeDataRequestDto
* @package RetailCrm\Test
* @author RetailCRM <integration@retailcrm.ru>
* @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 <integration@retailcrm.ru>
* @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;
}

View File

@ -18,15 +18,20 @@ use RetailCrm\Builder\ClientBuilder;
use RetailCrm\Component\AppData; use RetailCrm\Component\AppData;
use RetailCrm\Component\Constants; use RetailCrm\Component\Constants;
use RetailCrm\Model\Entity\CategoryInfo; use RetailCrm\Model\Entity\CategoryInfo;
use RetailCrm\Model\Request\AliExpress\Data\SingleItemRequestDto;
use RetailCrm\Model\Request\AliExpress\PostproductRedefiningCategoryForecast; use RetailCrm\Model\Request\AliExpress\PostproductRedefiningCategoryForecast;
use RetailCrm\Model\Request\AliExpress\SolutionFeedSubmit;
use RetailCrm\Model\Request\AliExpress\SolutionSellerCategoryTreeQuery; use RetailCrm\Model\Request\AliExpress\SolutionSellerCategoryTreeQuery;
use RetailCrm\Model\Request\Taobao\HttpDnsGetRequest; 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\SolutionSellerCategoryTreeQueryResponseData;
use RetailCrm\Model\Response\AliExpress\Data\SolutionSellerCategoryTreeQueryResponseDataChildrenCategoryList; use RetailCrm\Model\Response\AliExpress\Data\SolutionSellerCategoryTreeQueryResponseDataChildrenCategoryList;
use RetailCrm\Model\Response\AliExpress\PostproductRedefiningCategoryForecastResponse; use RetailCrm\Model\Response\AliExpress\PostproductRedefiningCategoryForecastResponse;
use RetailCrm\Model\Response\AliExpress\SolutionFeedSubmitResponse;
use RetailCrm\Model\Response\AliExpress\SolutionSellerCategoryTreeQueryResponse; use RetailCrm\Model\Response\AliExpress\SolutionSellerCategoryTreeQueryResponse;
use RetailCrm\Model\Response\ErrorResponseBody; use RetailCrm\Model\Response\ErrorResponseBody;
use RetailCrm\Model\Response\Taobao\HttpDnsGetResponse; use RetailCrm\Model\Response\Taobao\HttpDnsGetResponse;
use RetailCrm\Test\FakeDataRequestDto;
use RetailCrm\Test\TestCase; use RetailCrm\Test\TestCase;
use RetailCrm\Test\RequestMatcher; use RetailCrm\Test\RequestMatcher;
@ -216,4 +221,46 @@ EOF;
self::assertEquals('24000011', $response->responseData->result->errorCode); self::assertEquals('24000011', $response->responseData->result->errorCode);
self::assertTrue($response->responseData->result->success); 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);
}
} }