Skip to content

Commit

Permalink
added Vat to frontend API for product, transport and payment
Browse files Browse the repository at this point in the history
- also updated Convertim implementation
  • Loading branch information
TomasLudvik committed Nov 7, 2024
1 parent edfd8a2 commit eae9085
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Model/Product/Elasticsearch/ProductExportRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
};
}
Expand Down Expand Up @@ -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(),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down
2 changes: 2 additions & 0 deletions src/Model/Product/Search/ProductElasticsearchConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function testFillEmptyFields(): void
'hreflang_links' => [],
'product_type' => 'basic',
'priority_by_product_type' => 0,
'vat' => ['percent' => '0'],
];

$converter = new ProductElasticsearchConverter();
Expand Down Expand Up @@ -122,6 +123,7 @@ public function testFillEmptyParameterFields(): void
'hreflang_links' => [],
'product_type' => 'basic',
'priority_by_product_type' => 0,
'vat' => ['percent' => '0'],
];

$converter = new ProductElasticsearchConverter();
Expand Down

0 comments on commit eae9085

Please sign in to comment.