diff --git a/src/Model/Cart/CartWithModificationsResult.php b/src/Model/Cart/CartWithModificationsResult.php index fe5592b68..ab90c72bb 100644 --- a/src/Model/Cart/CartWithModificationsResult.php +++ b/src/Model/Cart/CartWithModificationsResult.php @@ -270,15 +270,18 @@ public function getPayment(): ?Payment } /** - * @return string|null + * @return \Shopsys\FrontendApiBundle\Model\Cart\PromoCodeData|null */ - public function getPromoCode(): ?string + public function getPromoCode(): ?PromoCodeData { if ($this->cart->getFirstAppliedPromoCode() === null) { return null; } - return $this->cart->getFirstAppliedPromoCode()->getCode(); + return new PromoCodeData( + $this->cart->getFirstAppliedPromoCode()->getCode(), + $this->cart->getFirstAppliedPromoCode()->getDiscountType(), + ); } /** diff --git a/src/Model/Cart/PromoCodeData.php b/src/Model/Cart/PromoCodeData.php new file mode 100644 index 000000000..586e2f82f --- /dev/null +++ b/src/Model/Cart/PromoCodeData.php @@ -0,0 +1,18 @@ +getProductsTotalPriceAfterAppliedDiscounts(); - if ($this->freeTransportAndPaymentFacade->isActive($domainId)) { + $isFreeTransportAndPaymentPromoCodeApplied = $orderInput->isFreeTransportAndPaymentPromoCodeApplied(); + + if ($this->freeTransportAndPaymentFacade->isActive($domainId, $isFreeTransportAndPaymentPromoCodeApplied)) { $amountWithVatForFreeTransport = $this->freeTransportAndPaymentFacade->getRemainingPriceWithVat( $productsPrice->getPriceWithVat(), $domainId, + $isFreeTransportAndPaymentPromoCodeApplied, ); $this->cartWithModificationsResult->setRemainingAmountWithVatForFreeTransport($amountWithVatForFreeTransport); diff --git a/src/Model/Resolver/Price/PriceQuery.php b/src/Model/Resolver/Price/PriceQuery.php index 83fa65fb0..cff613cd3 100644 --- a/src/Model/Resolver/Price/PriceQuery.php +++ b/src/Model/Resolver/Price/PriceQuery.php @@ -112,6 +112,7 @@ public function priceByPaymentQuery( $order->getCurrency(), $order->getTotalProductsPrice(), $order->getDomainId(), + $order->isFreeTransportAndPaymentApplied(), ); } diff --git a/src/Resources/config/graphql-types/EnumType/PromoCodeTypeEnumDecorator.types.yaml b/src/Resources/config/graphql-types/EnumType/PromoCodeTypeEnumDecorator.types.yaml new file mode 100644 index 000000000..4df544431 --- /dev/null +++ b/src/Resources/config/graphql-types/EnumType/PromoCodeTypeEnumDecorator.types.yaml @@ -0,0 +1,15 @@ +PromoCodeTypeEnumDecorator: + type: enum + decorator: true + config: + description: "One of possible promo code types" + values: + percent: + value: '@=constant("Shopsys\\FrameworkBundle\\Model\\Order\\PromoCode\\PromoCodeTypeEnum::DISCOUNT_TYPE_PERCENT")' + description: "Discount type percent" + nominal: + value: '@=constant("Shopsys\\FrameworkBundle\\Model\\Order\\PromoCode\\PromoCodeTypeEnum::DISCOUNT_TYPE_NOMINAL")' + description: "Discount type nominal" + free_transport_payment: + value: '@=constant("Shopsys\\FrameworkBundle\\Model\\Order\\PromoCode\\PromoCodeTypeEnum::DISCOUNT_TYPE_FREE_TRANSPORT_PAYMENT")' + description: "Discount type free transport and payment" diff --git a/src/Resources/config/graphql-types/ModelType/Cart/CartDecorator.types.yaml b/src/Resources/config/graphql-types/ModelType/Cart/CartDecorator.types.yaml index 8e78f0e8f..2c76eaa81 100644 --- a/src/Resources/config/graphql-types/ModelType/Cart/CartDecorator.types.yaml +++ b/src/Resources/config/graphql-types/ModelType/Cart/CartDecorator.types.yaml @@ -19,7 +19,7 @@ CartDecorator: type: "String" description: "Selected pickup place identifier if provided" promoCode: - type: "String" + type: "PromoCode" description: "Applied promo code if provided" modifications: type: "CartModificationsResult!" diff --git a/src/Resources/config/graphql-types/ModelType/Cart/PromoCodeDecorator.types.yaml b/src/Resources/config/graphql-types/ModelType/Cart/PromoCodeDecorator.types.yaml new file mode 100644 index 000000000..cfbdf5c7a --- /dev/null +++ b/src/Resources/config/graphql-types/ModelType/Cart/PromoCodeDecorator.types.yaml @@ -0,0 +1,11 @@ +PromoCodeDecorator: + type: object + decorator: true + config: + fields: + code: + type: "String!" + description: "Code of the promo code" + type: + type: "PromoCodeTypeEnum!" + description: "Type of the promo code"