Skip to content

Commit

Permalink
FE API: Cart now contains information about the promo code type
Browse files Browse the repository at this point in the history
  • Loading branch information
vitek-rostislav committed Dec 17, 2024
1 parent 2410d05 commit bdc0999
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 4 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,
) {
}
}
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 bdc0999

Please sign in to comment.