From bbfc8a0249f1b93a373e6f2ec0d14004e977f8f6 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 --- src/Model/Resolver/Payment/PaymentResolverMap.php | 3 +++ .../Products/DataMapper/ProductEntityFieldMapper.php | 10 ++++++++++ .../Resolver/Transport/TransportResolverMap.php | 6 ++++++ .../ModelType/Payment/PaymentDecorator.types.yaml | 2 ++ .../ModelType/Product/ProductDecorator.types.yaml | 2 ++ .../Transport/TransportDecorator.types.yaml | 2 ++ .../ModelType/Vat/VatDecorator.types.yaml | 12 ++++++++++++ 7 files changed, 37 insertions(+) create mode 100644 src/Resources/config/graphql-types/ModelType/Vat/VatDecorator.types.yaml diff --git a/src/Model/Resolver/Payment/PaymentResolverMap.php b/src/Model/Resolver/Payment/PaymentResolverMap.php index 32445d785..ae5244664 100644 --- a/src/Model/Resolver/Payment/PaymentResolverMap.php +++ b/src/Model/Resolver/Payment/PaymentResolverMap.php @@ -28,6 +28,9 @@ protected function map(): array 'goPayPaymentMethod' => function (Payment $payment) { return $payment->getGoPayPaymentMethodByDomainId($this->domain->getId()); }, + 'vat' => function (Payment $payment) { + return $payment->getVatForDomain($this->domain->getId()); + }, ], ]; } diff --git a/src/Model/Resolver/Products/DataMapper/ProductEntityFieldMapper.php b/src/Model/Resolver/Products/DataMapper/ProductEntityFieldMapper.php index 130f2ad07..f95518731 100644 --- a/src/Model/Resolver/Products/DataMapper/ProductEntityFieldMapper.php +++ b/src/Model/Resolver/Products/DataMapper/ProductEntityFieldMapper.php @@ -8,6 +8,7 @@ use Overblog\DataLoader\DataLoaderInterface; use Shopsys\FrameworkBundle\Component\Domain\Domain; use Shopsys\FrameworkBundle\Model\Customer\User\CurrentCustomerUser; +use Shopsys\FrameworkBundle\Model\Pricing\Vat\Vat; use Shopsys\FrameworkBundle\Model\Product\Accessory\ProductAccessoryFacade; use Shopsys\FrameworkBundle\Model\Product\Availability\ProductAvailabilityFacade; use Shopsys\FrameworkBundle\Model\Product\Collection\ProductCollectionFacade; @@ -241,4 +242,13 @@ public function getProductType(Product $product): string { return $product->getProductType(); } + + /** + * @param \Shopsys\FrameworkBundle\Model\Product\Product $product + * @return \Shopsys\FrameworkBundle\Model\Pricing\Vat\Vat + */ + public function getVat(Product $product): Vat + { + return $product->getVatForDomain($this->domain->getId()); + } } diff --git a/src/Model/Resolver/Transport/TransportResolverMap.php b/src/Model/Resolver/Transport/TransportResolverMap.php index 81b64efbd..8000ea84d 100644 --- a/src/Model/Resolver/Transport/TransportResolverMap.php +++ b/src/Model/Resolver/Transport/TransportResolverMap.php @@ -5,6 +5,7 @@ namespace Shopsys\FrontendApiBundle\Model\Resolver\Transport; use Overblog\GraphQLBundle\Resolver\ResolverMap; +use Shopsys\FrameworkBundle\Component\Domain\Domain; use Shopsys\FrameworkBundle\Model\Payment\PaymentFacade; use Shopsys\FrameworkBundle\Model\Transport\Transport; @@ -12,9 +13,11 @@ class TransportResolverMap extends ResolverMap { /** * @param \Shopsys\FrameworkBundle\Model\Payment\PaymentFacade $paymentFacade + * @param \Shopsys\FrameworkBundle\Component\Domain\Domain $domain */ public function __construct( protected readonly PaymentFacade $paymentFacade, + protected readonly Domain $domain, ) { } @@ -31,6 +34,9 @@ protected function map(): array 'transportTypeCode' => function (Transport $transport) { return $transport->getType(); }, + 'vat' => function (Transport $transport) { + return $transport->getVatForDomain($this->domain->getId()); + }, ], ]; } diff --git a/src/Resources/config/graphql-types/ModelType/Payment/PaymentDecorator.types.yaml b/src/Resources/config/graphql-types/ModelType/Payment/PaymentDecorator.types.yaml index 7326fc8af..6e7bc580a 100644 --- a/src/Resources/config/graphql-types/ModelType/Payment/PaymentDecorator.types.yaml +++ b/src/Resources/config/graphql-types/ModelType/Payment/PaymentDecorator.types.yaml @@ -52,3 +52,5 @@ PaymentDecorator: type: type: "String!" description: "Type of payment" + vat: + type: "Vat!" diff --git a/src/Resources/config/graphql-types/ModelType/Product/ProductDecorator.types.yaml b/src/Resources/config/graphql-types/ModelType/Product/ProductDecorator.types.yaml index 754cb494a..955a29b35 100644 --- a/src/Resources/config/graphql-types/ModelType/Product/ProductDecorator.types.yaml +++ b/src/Resources/config/graphql-types/ModelType/Product/ProductDecorator.types.yaml @@ -78,3 +78,5 @@ ProductDecorator: type: "Boolean!" productType: type: "ProductTypeEnum!" + vat: + type: "Vat!" diff --git a/src/Resources/config/graphql-types/ModelType/Transport/TransportDecorator.types.yaml b/src/Resources/config/graphql-types/ModelType/Transport/TransportDecorator.types.yaml index f54ab09ab..9889eb013 100644 --- a/src/Resources/config/graphql-types/ModelType/Transport/TransportDecorator.types.yaml +++ b/src/Resources/config/graphql-types/ModelType/Transport/TransportDecorator.types.yaml @@ -41,3 +41,5 @@ TransportDecorator: transportTypeCode: type: "TransportTypeEnum!" description: "Code of transport type" + vat: + type: "Vat!" diff --git a/src/Resources/config/graphql-types/ModelType/Vat/VatDecorator.types.yaml b/src/Resources/config/graphql-types/ModelType/Vat/VatDecorator.types.yaml new file mode 100644 index 000000000..6795337f7 --- /dev/null +++ b/src/Resources/config/graphql-types/ModelType/Vat/VatDecorator.types.yaml @@ -0,0 +1,12 @@ +VatDecorator: + type: object + decorator: true + config: + description: "Represents a vat" + fields: + name: + type: "String!" + description: "Vat name" + percent: + type: "String!" + description: "Vat percent"