From eae90850dc98b48ffb777274d32ef50f12a78cee 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 efe2d477d1..0eca2c0976 100644 --- a/src/Model/Product/Elasticsearch/ProductExportRepository.php +++ b/src/Model/Product/Elasticsearch/ProductExportRepository.php @@ -188,7 +188,7 @@ protected function getExportedFieldValue(int $domainId, Product $product, string ProductExportFieldProvider::HREFLANG_LINKS => $this->hreflangLinksFacade->getForProduct($product, $domainId), ProductExportFieldProvider::PRODUCT_TYPE => $this->extractProductType($product, $domainId), ProductExportFieldProvider::PRIORITY_BY_PRODUCT_TYPE => $this->extractPriorityByProductType($product, $domainId), - + ProductExportFieldProvider::VAT => $this->extractVat($product, $domainId), default => throw new InvalidArgumentException(sprintf('There is no definition for exporting "%s" field to Elasticsearch', $field)), }; } @@ -484,4 +484,16 @@ protected function reset(): void { $this->inMemoryCache->deleteAllItemsInNamespace(static::VARIANTS_CACHE_NAMESPACE); } + + /** + * @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 5c77b9efe0..c12427172f 100644 --- a/src/Model/Product/Elasticsearch/Scope/ProductExportFieldProvider.php +++ b/src/Model/Product/Elasticsearch/Scope/ProductExportFieldProvider.php @@ -45,6 +45,7 @@ class ProductExportFieldProvider public const string HREFLANG_LINKS = 'hreflang_links'; public const string PRODUCT_TYPE = 'product_type'; public const string PRIORITY_BY_PRODUCT_TYPE = 'priority_by_product_type'; + public const string VAT = 'vat'; /** * @return string[] diff --git a/src/Model/Product/Search/ProductElasticsearchConverter.php b/src/Model/Product/Search/ProductElasticsearchConverter.php index 3f0fab70fc..bbace695a2 100644 --- a/src/Model/Product/Search/ProductElasticsearchConverter.php +++ b/src/Model/Product/Search/ProductElasticsearchConverter.php @@ -57,6 +57,8 @@ public function fillEmptyFields(array $product): array $result['product_type'] = $product['product_type'] ?? ProductTypeEnum::TYPE_BASIC; $result['priority_by_product_type'] = $product['priority_by_product_type'] ?? 0; + $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 5ba1a1d797..f39ee5752e 100644 --- a/tests/Unit/Model/Product/Search/ProductElasticsearchConverterTest.php +++ b/tests/Unit/Model/Product/Search/ProductElasticsearchConverterTest.php @@ -55,6 +55,7 @@ public function testFillEmptyFields(): void 'hreflang_links' => [], 'product_type' => 'basic', 'priority_by_product_type' => 0, + 'vat' => ['percent' => '0'], ]; $converter = new ProductElasticsearchConverter(); @@ -122,6 +123,7 @@ public function testFillEmptyParameterFields(): void 'hreflang_links' => [], 'product_type' => 'basic', 'priority_by_product_type' => 0, + 'vat' => ['percent' => '0'], ]; $converter = new ProductElasticsearchConverter();