Skip to content

Commit

Permalink
[shopsys] promo code for free transport and payment (#3625)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitek-rostislav authored Dec 17, 2024
2 parents 79d3a7f + bdc0999 commit 3e453b7
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/Model/Cart/CartWithModificationsResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
}

/**
Expand Down
18 changes: 18 additions & 0 deletions src/Model/Cart/PromoCodeData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Shopsys\FrontendApiBundle\Model\Cart;

class PromoCodeData
{
/**
* @param string $code
* @param string $type
*/
public function __construct(
public readonly string $code,
public readonly string $type,
) {
}
}
5 changes: 4 additions & 1 deletion src/Model/Cart/TransportAndPaymentWatcherFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,13 @@ public function checkTransportAndPayment(

$productsPrice = $orderData->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);
Expand Down
1 change: 1 addition & 0 deletions src/Model/Resolver/Price/PriceQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public function priceByPaymentQuery(
$order->getCurrency(),
$order->getTotalProductsPrice(),
$order->getDomainId(),
$order->isFreeTransportAndPaymentApplied(),
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
Expand Down
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 3e453b7

Please sign in to comment.