From 232c22a55712ffc23ad78ec2f23977860e4a0e1c Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Mon, 11 Mar 2024 18:24:44 +0300 Subject: [PATCH] fix customer tags support --- .../Generator/SerializerGenerator.php | 16 ++++++++++++++++ tests/src/ResourceGroup/CustomersTest.php | 17 ++++++++--------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/Component/Serializer/Generator/SerializerGenerator.php b/src/Component/Serializer/Generator/SerializerGenerator.php index 9288246..b4a903d 100644 --- a/src/Component/Serializer/Generator/SerializerGenerator.php +++ b/src/Component/Serializer/Generator/SerializerGenerator.php @@ -23,6 +23,7 @@ use RetailCrm\Api\Component\Serializer\Template\CustomSerialization; use RetailCrm\Api\Component\Serializer\Type\PropertyTypeMixed; use RetailCrm\Api\Interfaces\Orders\CustomerInterface; use RetailCrm\Api\Model\Entity\Customers\Customer; +use RetailCrm\Api\Model\Entity\Customers\CustomerTag; use RetailCrm\Api\Model\Entity\CustomersCorporate\CustomerCorporate; use RetailCrm\Api\Model\Entity\CustomersCorporate\SerializedRelationAbstractCustomer; use RetailCrm\Api\Model\Entity\Orders\SerializedRelationCustomer; @@ -152,6 +153,10 @@ final class SerializerGenerator ); } + if ($classMetadata->getClassName() === CustomerTag::class) { + return $this->generateForCustomerTag($arrayPath, $modelPath); + } + $stack[$classMetadata->getClassName()] = ($stack[$classMetadata->getClassName()] ?? 0) + 1; $code = ''; @@ -242,6 +247,17 @@ final class SerializerGenerator ); } + /** + * @param string $arrayPath + * @param string $modelPath + * + * @return string + */ + private function generateForCustomerTag(string $arrayPath, string $modelPath): string + { + return $this->templating->renderAssign($arrayPath, $modelPath . '->name'); + } + /** * @param list $serializerGroups * @param array $stack diff --git a/tests/src/ResourceGroup/CustomersTest.php b/tests/src/ResourceGroup/CustomersTest.php index bf1691e..3b99ed9 100644 --- a/tests/src/ResourceGroup/CustomersTest.php +++ b/tests/src/ResourceGroup/CustomersTest.php @@ -2698,15 +2698,14 @@ EOF; $response = $client->customers->get(4770, $request); self::assertModelsCallback($json, $response, static function ($expected, $actual) { - // TODO: Check if it's really necessary to do tag conversion here. Maybe underlying serializer is broken. -// $actualTags = $actual['customer']['tags']; -// $actual['customer']['tags'] = array_filter( -// array_map(static function ($tag) use ($actualTags) { -// if (in_array($tag['name'], $actualTags, true)) { -// return $tag; -// } -// }, $expected['customer']['tags']) -// ); + $actualTags = $actual['customer']['tags']; + $actual['customer']['tags'] = array_filter( + array_map(static function ($tag) use ($actualTags) { + if (in_array($tag['name'], $actualTags, true)) { + return $tag; + } + }, $expected['customer']['tags']) + ); $expected['customer']['marginSumm'] = (float)$expected['customer']['marginSumm']; $expected['customer']['totalSumm'] = (float)$expected['customer']['totalSumm'];