From f0e58086badc37ed46d7bee57c6569cc7556c068 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=CC=81s=CC=8C=20Ludvik?= Date: Thu, 31 Oct 2024 16:06:07 +0100 Subject: [PATCH] added Vat to frontend API for product, transport and payment - also updated Convertim implementation --- .../Elasticsearch/ProductExportRepository.php | 14 +++++++++++++- .../Scope/ProductExportFieldProvider.php | 1 + .../Search/ProductElasticsearchConverter.php | 2 ++ .../Search/ProductElasticsearchConverterTest.php | 2 ++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Model/Product/Elasticsearch/ProductExportRepository.php b/src/Model/Product/Elasticsearch/ProductExportRepository.php index 139d72bf2a..12ad028b9a 100644 --- a/src/Model/Product/Elasticsearch/ProductExportRepository.php +++ b/src/Model/Product/Elasticsearch/ProductExportRepository.php @@ -192,7 +192,7 @@ protected function getExportedFieldValue(int $domainId, Product $product, string ProductExportFieldProvider::AVAILABLE_STORES_COUNT => $this->productAvailabilityFacade->getAvailableStoresCount($product, $domainId), ProductExportFieldProvider::STORE_AVAILABILITIES_INFORMATION => $this->extractStoreAvailabilitiesInformation($product, $domainId), ProductExportFieldProvider::AVAILABILITY_STATUS => $this->productAvailabilityFacade->getProductAvailabilityStatusByDomainId($product, $domainId), - + ProductExportFieldProvider::VAT => $this->extractVat($product, $domainId), default => throw new InvalidArgumentException(sprintf('There is no definition for exporting "%s" field to Elasticsearch', $field)), }; } @@ -513,4 +513,16 @@ protected function extractStoreAvailabilitiesInformation(Product $product, int $ return $result; } + + /** + * @param \Shopsys\FrameworkBundle\Model\Product\Product $product + * @param int $domainId + * @return array + */ + protected function extractVat(Product $product, int $domainId): array + { + return [ + 'percent' => $product->getVatForDomain($domainId)->getPercent(), + ]; + } } diff --git a/src/Model/Product/Elasticsearch/Scope/ProductExportFieldProvider.php b/src/Model/Product/Elasticsearch/Scope/ProductExportFieldProvider.php index 921ba11d7c..47948d2a0a 100644 --- a/src/Model/Product/Elasticsearch/Scope/ProductExportFieldProvider.php +++ b/src/Model/Product/Elasticsearch/Scope/ProductExportFieldProvider.php @@ -49,6 +49,7 @@ class ProductExportFieldProvider public const string AVAILABLE_STORES_COUNT = 'available_stores_count'; public const string STORE_AVAILABILITIES_INFORMATION = 'store_availabilities_information'; public const string AVAILABILITY_STATUS = 'availability_status'; + public const string VAT = 'vat'; /** * @return string[] diff --git a/src/Model/Product/Search/ProductElasticsearchConverter.php b/src/Model/Product/Search/ProductElasticsearchConverter.php index 542e9c2264..504d806fe3 100644 --- a/src/Model/Product/Search/ProductElasticsearchConverter.php +++ b/src/Model/Product/Search/ProductElasticsearchConverter.php @@ -69,6 +69,8 @@ public function fillEmptyFields(array $product): array $result[ProductExportFieldProvider::UUID] = $product[ProductExportFieldProvider::UUID] ?? '00000000-0000-0000-0000-000000000000'; $result[ProductExportFieldProvider::UNIT] = $product[ProductExportFieldProvider::UNIT] ?? ''; + $result['vat'] = $product['vat'] ?? ['percent' => '0']; + return $result; } diff --git a/tests/Unit/Model/Product/Search/ProductElasticsearchConverterTest.php b/tests/Unit/Model/Product/Search/ProductElasticsearchConverterTest.php index 371b2bb1e2..f3c517005f 100644 --- a/tests/Unit/Model/Product/Search/ProductElasticsearchConverterTest.php +++ b/tests/Unit/Model/Product/Search/ProductElasticsearchConverterTest.php @@ -63,6 +63,7 @@ public function testFillEmptyFields(): void 'stock_quantity' => null, 'uuid' => '00000000-0000-0000-0000-000000000000', 'unit' => '', + 'vat' => ['percent' => '0'], ]; $converter = new ProductElasticsearchConverter(); @@ -138,6 +139,7 @@ public function testFillEmptyParameterFields(): void 'stock_quantity' => null, 'uuid' => '00000000-0000-0000-0000-000000000000', 'unit' => '', + 'vat' => ['percent' => '0'], ]; $converter = new ProductElasticsearchConverter();