From 2b02c0e11613d3ea289cb4df8c491636f3a9a3b2 Mon Sep 17 00:00:00 2001 From: Danila Date: Thu, 7 Sep 2023 10:10:26 +0300 Subject: [PATCH 1/4] Add functionality from recent updates to the library --- .../Entity/Loyalty/SerializedLoyaltyOrder.php | 8 ++ src/Model/Entity/Orders/LinkedOrder.php | 39 +++++++ src/Model/Entity/Orders/Order.php | 8 ++ src/Model/Entity/Orders/OrderLink.php | 40 +++++++ src/Model/Entity/References/PriceType.php | 8 ++ src/Model/Entity/Store/OfferPrice.php | 8 ++ src/Model/Entity/Users/User.php | 8 ++ src/Model/Filter/Orders/OrderFilter.php | 8 ++ src/ResourceGroup/WebAnalytics.php | 96 +++++++++++++++++ tests/src/ResourceGroup/WebAnalyticsTest.php | 100 ++++++++++++++++++ 10 files changed, 323 insertions(+) create mode 100644 src/Model/Entity/Orders/LinkedOrder.php create mode 100644 src/Model/Entity/Orders/OrderLink.php create mode 100644 tests/src/ResourceGroup/WebAnalyticsTest.php diff --git a/src/Model/Entity/Loyalty/SerializedLoyaltyOrder.php b/src/Model/Entity/Loyalty/SerializedLoyaltyOrder.php index 53ea74e..966efda 100644 --- a/src/Model/Entity/Loyalty/SerializedLoyaltyOrder.php +++ b/src/Model/Entity/Loyalty/SerializedLoyaltyOrder.php @@ -116,4 +116,12 @@ class SerializedLoyaltyOrder * @JMS\SerializedName("items") */ public $items; + + /** + * @var string + * + * @JMS\Type("string") + * @JMS\SerializedName("currency") + */ + public $currency; } diff --git a/src/Model/Entity/Orders/LinkedOrder.php b/src/Model/Entity/Orders/LinkedOrder.php new file mode 100644 index 0000000..3224377 --- /dev/null +++ b/src/Model/Entity/Orders/LinkedOrder.php @@ -0,0 +1,39 @@ +") + * @JMS\SerializedName("links") + */ + public $links; + /** * @var bool * diff --git a/src/Model/Entity/Orders/OrderLink.php b/src/Model/Entity/Orders/OrderLink.php new file mode 100644 index 0000000..dc4bb87 --- /dev/null +++ b/src/Model/Entity/Orders/OrderLink.php @@ -0,0 +1,40 @@ +") + * @JMS\SerializedName("order") + */ + public $order; + + /** + * @var DateTime + * + * @JMS\Type("DateTime<'Y-m-d H:i:s'>") + * @JMS\SerializedName("createdAt") + */ + public $createdAt; +} diff --git a/src/Model/Entity/References/PriceType.php b/src/Model/Entity/References/PriceType.php index da5c282..1e4ac6c 100644 --- a/src/Model/Entity/References/PriceType.php +++ b/src/Model/Entity/References/PriceType.php @@ -75,6 +75,14 @@ class PriceType */ public $filterExpression; + /** + * @var string + * + * @JMS\Type("string") + * @JMS\SerializedName("currency") + */ + public $currency; + /** * @var \RetailCrm\Api\Model\Entity\References\GeoHierarchyRow[] * diff --git a/src/Model/Entity/Store/OfferPrice.php b/src/Model/Entity/Store/OfferPrice.php index c03f829..32072c7 100644 --- a/src/Model/Entity/Store/OfferPrice.php +++ b/src/Model/Entity/Store/OfferPrice.php @@ -42,4 +42,12 @@ class OfferPrice * @JMS\SerializedName("ordering") */ public $ordering; + + /** + * @var string + * + * @JMS\Type("string") + * @JMS\SerializedName("currency") + */ + public $currency; } diff --git a/src/Model/Entity/Users/User.php b/src/Model/Entity/Users/User.php index 2ce95d1..320e78a 100644 --- a/src/Model/Entity/Users/User.php +++ b/src/Model/Entity/Users/User.php @@ -76,6 +76,14 @@ class User */ public $patronymic; + /** + * @var string + * + * @JMS\Type("string") + * @JMS\SerializedName("position") + */ + public $position; + /** * @var string * diff --git a/src/Model/Filter/Orders/OrderFilter.php b/src/Model/Filter/Orders/OrderFilter.php index e551537..481a7a3 100644 --- a/src/Model/Filter/Orders/OrderFilter.php +++ b/src/Model/Filter/Orders/OrderFilter.php @@ -512,6 +512,14 @@ class OrderFilter */ public $deliveryTypes; + /** + * @var string[] + * + * @Form\Type("string[]") + * @Form\SerializedName("deliveryServices") + */ + public $deliveryServices; + /** * @var string[] * diff --git a/src/ResourceGroup/WebAnalytics.php b/src/ResourceGroup/WebAnalytics.php index cf85087..1ed500f 100644 --- a/src/ResourceGroup/WebAnalytics.php +++ b/src/ResourceGroup/WebAnalytics.php @@ -15,6 +15,7 @@ use RetailCrm\Api\Model\Request\WebAnalytics\SourcesUploadRequest; use RetailCrm\Api\Model\Response\WebAnalytics\ClientIdUploadResponse; use RetailCrm\Api\Model\Response\WebAnalytics\SourcesUploadResponse; +// TODO комментарий + тест /** * Class WebAnalytics * @@ -26,6 +27,56 @@ use RetailCrm\Api\Model\Response\WebAnalytics\SourcesUploadResponse; class WebAnalytics extends AbstractApiResourceGroup { /** + * + * Makes POST "/api/v5/web-analytics/client-ids/upload" request. + * + * Example: + * ```php + * use RetailCrm\Api\Factory\SimpleClientFactory; + * use RetailCrm\Api\Interfaces\ApiExceptionInterface; + * use RetailCrm\Api\Model\Entity\WebAnalytics\Customer; + * use RetailCrm\Api\Model\Entity\WebAnalytics\Order; + * use RetailCrm\Api\Model\Entity\WebAnalytics\Source; + * use RetailCrm\Api\Model\Request\WebAnalytics\SourcesUploadRequest; + * + * $client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey'); + * + * $entity = new Source(); + * $entity->source = "sourse"; + * $entity->medium = "medium"; + * $entity->campaign = "campaign"; + * $entity->keyword = "keyword"; + * $entity->content = "content"; + * $entity->clientId = "10"; + * $entity->order = new Order(); + * $entity->order->id = 10; + * $entity->order->externalId = "externalId"; + * $entity->order->number = "number"; + * $entity->customer = new Customer(); + * $entity->customer->id = 10; + * $entity->customer->externalId = 'externalId'; + * + * $request = new SourcesUploadRequest([$entity]); + * + * try { + * $response = $client->webAnalytics->sourcesUpload($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 'Upload is successful'; + * ``` + * * @param \RetailCrm\Api\Model\Request\WebAnalytics\SourcesUploadRequest $request * * @return \RetailCrm\Api\Model\Response\WebAnalytics\SourcesUploadResponse @@ -53,6 +104,51 @@ class WebAnalytics extends AbstractApiResourceGroup } /** + * + * Makes POST "/api/v5/web-analytics/client-ids/upload" request. + * + * Example: + * ```php + * use RetailCrm\Api\Factory\SimpleClientFactory; + * use RetailCrm\Api\Interfaces\ApiExceptionInterface; + * use RetailCrm\Api\Model\Entity\WebAnalytics\ClientId; + * use RetailCrm\Api\Model\Entity\WebAnalytics\Customer; + * use RetailCrm\Api\Model\Entity\WebAnalytics\Order; + * use RetailCrm\Api\Model\Request\WebAnalytics\ClientIdUploadRequest; + * + * $client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey'); + * + * $entity = new ClientId(); + * $entity->value = 'value'; + * $entity->order = new Order(); + * $entity->order->id = 10; + * $entity->order->externalId = 'externalId'; + * $entity->order->number = 'number'; + * $entity->customer = new Customer(); + * $entity->customer->id = 10; + * $entity->customer->externalId = 'externalId'; + * + * $request = new ClientIdUploadRequest([$entity]); + * + * try { + * $response = $client->webAnalytics->clientIdsUpload($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 'Upload is successful'; + * ``` + * * @param \RetailCrm\Api\Model\Request\WebAnalytics\ClientIdUploadRequest $request * * @return \RetailCrm\Api\Model\Response\WebAnalytics\ClientIdUploadResponse diff --git a/tests/src/ResourceGroup/WebAnalyticsTest.php b/tests/src/ResourceGroup/WebAnalyticsTest.php new file mode 100644 index 0000000..dd08fa0 --- /dev/null +++ b/tests/src/ResourceGroup/WebAnalyticsTest.php @@ -0,0 +1,100 @@ +value = 'value'; + $entity->order = new Order(); + $entity->order->id = 10; + $entity->order->externalId = 'externalId'; + $entity->order->number = 'number'; + $entity->customer = new Customer(); + $entity->customer->id = 10; + $entity->customer->externalId = 'externalId'; + + $request = new ClientIdUploadRequest([$entity]); + + $mock = static::createApiMockBuilder('web-analytics/client-ids/upload'); + $mock->matchMethod(RequestMethod::POST) + ->matchBody(self::encodeForm($request)) + ->reply(201) + ->withBody($json); + + $client = TestClientFactory::createClient($mock->getClient()); + $response = $client->webAnalytics->clientIdsUpload($request); + + self::assertModelEqualsToResponse($json, $response); + } + + public function testSourcesUpload(): void + { + $json = <<<'EOF' +{ + "success": true +} +EOF; + + $entity = new Source(); + $entity->source = "sourse"; + $entity->medium = "medium"; + $entity->campaign = "campaign"; + $entity->keyword = "keyword"; + $entity->content = "content"; + $entity->clientId = "10"; + $entity->order = new Order(); + $entity->order->id = 10; + $entity->order->externalId = "externalId"; + $entity->order->number = "number"; + $entity->customer = new Customer(); + $entity->customer->id = 10; + $entity->customer->externalId = 'externalId'; + + $request = new SourcesUploadRequest([$entity]); + + $mock = static::createApiMockBuilder('web-analytics/sources/upload'); + $mock->matchMethod(RequestMethod::POST) + ->matchBody(self::encodeForm($request)) + ->reply(201) + ->withBody($json); + + $client = TestClientFactory::createClient($mock->getClient()); + $response = $client->webAnalytics->sourcesUpload($request); + + self::assertModelEqualsToResponse($json, $response); + } +} From b6afd339060a808137ed3a61da55a95df5213ff1 Mon Sep 17 00:00:00 2001 From: Danila Date: Thu, 7 Sep 2023 10:16:41 +0300 Subject: [PATCH 2/4] Add functionality from recent updates to the library --- src/Model/Entity/Orders/LinkedOrder.php | 6 ++++++ src/Model/Entity/Orders/OrderLink.php | 6 ++++++ src/ResourceGroup/WebAnalytics.php | 1 - 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Model/Entity/Orders/LinkedOrder.php b/src/Model/Entity/Orders/LinkedOrder.php index 3224377..4747ab2 100644 --- a/src/Model/Entity/Orders/LinkedOrder.php +++ b/src/Model/Entity/Orders/LinkedOrder.php @@ -11,6 +11,12 @@ namespace RetailCrm\Api\Model\Entity\Orders; use RetailCrm\Api\Component\Serializer\Annotation as JMS; +/** + * Class LinkedOrder + * + * @category LinkedOrder + * @package RetailCrm\Api\Model\Entity\Orders + */ class LinkedOrder { /** diff --git a/src/Model/Entity/Orders/OrderLink.php b/src/Model/Entity/Orders/OrderLink.php index dc4bb87..de909c2 100644 --- a/src/Model/Entity/Orders/OrderLink.php +++ b/src/Model/Entity/Orders/OrderLink.php @@ -12,6 +12,12 @@ namespace RetailCrm\Api\Model\Entity\Orders; use DateTime; use RetailCrm\Api\Component\Serializer\Annotation as JMS; +/** + * Class OrderLink + * + * @category OrderLink + * @package RetailCrm\Api\Model\Entity\Orders + */ class OrderLink { /** diff --git a/src/ResourceGroup/WebAnalytics.php b/src/ResourceGroup/WebAnalytics.php index 1ed500f..b15356f 100644 --- a/src/ResourceGroup/WebAnalytics.php +++ b/src/ResourceGroup/WebAnalytics.php @@ -15,7 +15,6 @@ use RetailCrm\Api\Model\Request\WebAnalytics\SourcesUploadRequest; use RetailCrm\Api\Model\Response\WebAnalytics\ClientIdUploadResponse; use RetailCrm\Api\Model\Response\WebAnalytics\SourcesUploadResponse; -// TODO комментарий + тест /** * Class WebAnalytics * From 974b0cc8eff8737ef68f68b58a7c85b182752dc5 Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Tue, 3 Oct 2023 09:57:46 +0300 Subject: [PATCH 3/4] update ubuntu version for phpstan --- .github/workflows/code_quality.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code_quality.yml b/.github/workflows/code_quality.yml index ab5113f..10f149a 100644 --- a/.github/workflows/code_quality.yml +++ b/.github/workflows/code_quality.yml @@ -32,7 +32,7 @@ jobs: target_directory: 'src' phpstan: name: PHPStan - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest steps: - name: Check out code into the workspace uses: actions/checkout@v2 From 19f2b3dcd14e9a6af3c6bd34f0c17d4de8c84129 Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Tue, 3 Oct 2023 10:02:39 +0300 Subject: [PATCH 4/4] fix for phpstan --- src/Model/Request/References/CurrenciesCreateRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/Request/References/CurrenciesCreateRequest.php b/src/Model/Request/References/CurrenciesCreateRequest.php index d3cd46d..edc4e7f 100644 --- a/src/Model/Request/References/CurrenciesCreateRequest.php +++ b/src/Model/Request/References/CurrenciesCreateRequest.php @@ -22,7 +22,7 @@ use RetailCrm\Api\Model\Entity\References\Currency; class CurrenciesCreateRequest implements RequestInterface { /** - * @var \RetailCrm\Api\Model\Entity\References\Currency + * @var \RetailCrm\Api\Model\Entity\References\Currency|null * * @Form\Type("RetailCrm\Api\Model\Entity\References\Currency") * @Form\SerializedName("currency")