diff --git a/changes.md b/changes.md index 117d08944c9..1b23124ca2b 100644 --- a/changes.md +++ b/changes.md @@ -16,3 +16,30 @@ - added method `$apiRoot->withProjectKey()->channels()->withKey()->delete()` + +
+Added Type(s) + +- added type `CartDiscountPatternTarget` +- added type `CountOnCustomLineItemUnits` +- added type `CountOnLineItemUnits` +- added type `PatternComponent` +
+ + +
+Added Property(s) + +- added property `applicationMode` to type `CartDiscountValueFixed` +- added property `applicationMode` to type `CartDiscountValueFixedDraft` +
+ +**History changes** + +
+Added Type(s) + +- added type `ChangeTargetPatternChangeValue` +- added type `PatternComponent` +
+ diff --git a/lib/commercetools-api/src/Models/Cart/CartAddCustomLineItemAction.php b/lib/commercetools-api/src/Models/Cart/CartAddCustomLineItemAction.php index 60fa3bb439c..afc6a050bf7 100644 --- a/lib/commercetools-api/src/Models/Cart/CartAddCustomLineItemAction.php +++ b/lib/commercetools-api/src/Models/Cart/CartAddCustomLineItemAction.php @@ -105,8 +105,7 @@ public function getCustom(); /** * * diff --git a/lib/commercetools-api/src/Models/Cart/CartAddCustomLineItemActionBuilder.php b/lib/commercetools-api/src/Models/Cart/CartAddCustomLineItemActionBuilder.php index 023bcc6dbcd..3c3bb1a14ac 100644 --- a/lib/commercetools-api/src/Models/Cart/CartAddCustomLineItemActionBuilder.php +++ b/lib/commercetools-api/src/Models/Cart/CartAddCustomLineItemActionBuilder.php @@ -192,8 +192,7 @@ public function getCustom() /** * * diff --git a/lib/commercetools-api/src/Models/Cart/CartAddCustomLineItemActionModel.php b/lib/commercetools-api/src/Models/Cart/CartAddCustomLineItemActionModel.php index 06b545027f7..aa544dda91a 100644 --- a/lib/commercetools-api/src/Models/Cart/CartAddCustomLineItemActionModel.php +++ b/lib/commercetools-api/src/Models/Cart/CartAddCustomLineItemActionModel.php @@ -333,8 +333,7 @@ public function getCustom() /** * * diff --git a/lib/commercetools-api/src/Models/Cart/CustomLineItem.php b/lib/commercetools-api/src/Models/Cart/CustomLineItem.php index 43bbffe0be5..af2b9ad0cd6 100644 --- a/lib/commercetools-api/src/Models/Cart/CustomLineItem.php +++ b/lib/commercetools-api/src/Models/Cart/CustomLineItem.php @@ -175,7 +175,7 @@ public function getCustom(); public function getShippingDetails(); /** - *

Indicates whether Cart Discounts with a matching CartDiscountCustomLineItemsTarget are applied to the Custom Line Item.

+ *

Indicates whether Cart Discounts with a matching CartDiscountCustomLineItemsTarget, MultiBuyCustomLineItemsTarget, or CartDiscountPatternTarget are applied to the Custom Line Item.

* * @return null|string diff --git a/lib/commercetools-api/src/Models/Cart/CustomLineItemBuilder.php b/lib/commercetools-api/src/Models/Cart/CustomLineItemBuilder.php index 4e269f3d59d..948743a4ba7 100644 --- a/lib/commercetools-api/src/Models/Cart/CustomLineItemBuilder.php +++ b/lib/commercetools-api/src/Models/Cart/CustomLineItemBuilder.php @@ -320,7 +320,7 @@ public function getShippingDetails() } /** - *

Indicates whether Cart Discounts with a matching CartDiscountCustomLineItemsTarget are applied to the Custom Line Item.

+ *

Indicates whether Cart Discounts with a matching CartDiscountCustomLineItemsTarget, MultiBuyCustomLineItemsTarget, or CartDiscountPatternTarget are applied to the Custom Line Item.

* * @return null|string diff --git a/lib/commercetools-api/src/Models/Cart/CustomLineItemDraft.php b/lib/commercetools-api/src/Models/Cart/CustomLineItemDraft.php index 1755d0538ad..741bf81dc59 100644 --- a/lib/commercetools-api/src/Models/Cart/CustomLineItemDraft.php +++ b/lib/commercetools-api/src/Models/Cart/CustomLineItemDraft.php @@ -105,8 +105,7 @@ public function getShippingDetails(); /** * * diff --git a/lib/commercetools-api/src/Models/Cart/CustomLineItemDraftBuilder.php b/lib/commercetools-api/src/Models/Cart/CustomLineItemDraftBuilder.php index b07ae9e5605..06c71925b52 100644 --- a/lib/commercetools-api/src/Models/Cart/CustomLineItemDraftBuilder.php +++ b/lib/commercetools-api/src/Models/Cart/CustomLineItemDraftBuilder.php @@ -192,8 +192,7 @@ public function getShippingDetails() /** * * diff --git a/lib/commercetools-api/src/Models/Cart/CustomLineItemDraftModel.php b/lib/commercetools-api/src/Models/Cart/CustomLineItemDraftModel.php index d0a75496d86..83c0e98de93 100644 --- a/lib/commercetools-api/src/Models/Cart/CustomLineItemDraftModel.php +++ b/lib/commercetools-api/src/Models/Cart/CustomLineItemDraftModel.php @@ -306,8 +306,7 @@ public function getShippingDetails() /** * * diff --git a/lib/commercetools-api/src/Models/Cart/CustomLineItemModel.php b/lib/commercetools-api/src/Models/Cart/CustomLineItemModel.php index 20907b674a9..46da3e9252b 100644 --- a/lib/commercetools-api/src/Models/Cart/CustomLineItemModel.php +++ b/lib/commercetools-api/src/Models/Cart/CustomLineItemModel.php @@ -513,7 +513,7 @@ public function getShippingDetails() } /** - *

Indicates whether Cart Discounts with a matching CartDiscountCustomLineItemsTarget are applied to the Custom Line Item.

+ *

Indicates whether Cart Discounts with a matching CartDiscountCustomLineItemsTarget, MultiBuyCustomLineItemsTarget, or CartDiscountPatternTarget are applied to the Custom Line Item.

* * * @return null|string diff --git a/lib/commercetools-api/src/Models/CartDiscount/CartDiscountPatternTarget.php b/lib/commercetools-api/src/Models/CartDiscount/CartDiscountPatternTarget.php new file mode 100644 index 00000000000..d945eabd0be --- /dev/null +++ b/lib/commercetools-api/src/Models/CartDiscount/CartDiscountPatternTarget.php @@ -0,0 +1,77 @@ +Units of a (Custom) Line Item that trigger a discount application.

+ *

Based on the availability of matching units, the triggerPattern can match multiple times, effecting the number of times the discount will be applied. + * To further limit the discount application, set the maxOccurrence.

+ *

If empty or not set, the Discount will apply indefinitely.

+ * + + * @return null|PatternComponentCollection + */ + public function getTriggerPattern(); + + /** + *

Units of (Custom) Line Items on which the Discount is applied.

+ *

Based on the availability of matching units and the limits from the triggerPattern or maxOccurence, the targetPattern can match multiple times.

+ * + + * @return null|PatternComponentCollection + */ + public function getTargetPattern(); + + /** + *

Maximum number of times the Discount can apply on a Cart.

+ *

If empty or not set, the Discount will apply indefinitely.

+ * + + * @return null|int + */ + public function getMaxOccurrence(); + + /** + *

Determines which of the matching units of (Custom) Line Items are discounted.

+ * + + * @return null|string + */ + public function getSelectionMode(); + + /** + * @param ?PatternComponentCollection $triggerPattern + */ + public function setTriggerPattern(?PatternComponentCollection $triggerPattern): void; + + /** + * @param ?PatternComponentCollection $targetPattern + */ + public function setTargetPattern(?PatternComponentCollection $targetPattern): void; + + /** + * @param ?int $maxOccurrence + */ + public function setMaxOccurrence(?int $maxOccurrence): void; + + /** + * @param ?string $selectionMode + */ + public function setSelectionMode(?string $selectionMode): void; +} diff --git a/lib/commercetools-api/src/Models/CartDiscount/CartDiscountPatternTargetBuilder.php b/lib/commercetools-api/src/Models/CartDiscount/CartDiscountPatternTargetBuilder.php new file mode 100644 index 00000000000..3b9afa3aadf --- /dev/null +++ b/lib/commercetools-api/src/Models/CartDiscount/CartDiscountPatternTargetBuilder.php @@ -0,0 +1,155 @@ + + */ +final class CartDiscountPatternTargetBuilder implements Builder +{ + /** + + * @var ?PatternComponentCollection + */ + private $triggerPattern; + + /** + + * @var ?PatternComponentCollection + */ + private $targetPattern; + + /** + + * @var ?int + */ + private $maxOccurrence; + + /** + + * @var ?string + */ + private $selectionMode; + + /** + *

Units of a (Custom) Line Item that trigger a discount application.

+ *

Based on the availability of matching units, the triggerPattern can match multiple times, effecting the number of times the discount will be applied. + * To further limit the discount application, set the maxOccurrence.

+ *

If empty or not set, the Discount will apply indefinitely.

+ * + + * @return null|PatternComponentCollection + */ + public function getTriggerPattern() + { + return $this->triggerPattern; + } + + /** + *

Units of (Custom) Line Items on which the Discount is applied.

+ *

Based on the availability of matching units and the limits from the triggerPattern or maxOccurence, the targetPattern can match multiple times.

+ * + + * @return null|PatternComponentCollection + */ + public function getTargetPattern() + { + return $this->targetPattern; + } + + /** + *

Maximum number of times the Discount can apply on a Cart.

+ *

If empty or not set, the Discount will apply indefinitely.

+ * + + * @return null|int + */ + public function getMaxOccurrence() + { + return $this->maxOccurrence; + } + + /** + *

Determines which of the matching units of (Custom) Line Items are discounted.

+ * + + * @return null|string + */ + public function getSelectionMode() + { + return $this->selectionMode; + } + + /** + * @param ?PatternComponentCollection $triggerPattern + * @return $this + */ + public function withTriggerPattern(?PatternComponentCollection $triggerPattern) + { + $this->triggerPattern = $triggerPattern; + + return $this; + } + + /** + * @param ?PatternComponentCollection $targetPattern + * @return $this + */ + public function withTargetPattern(?PatternComponentCollection $targetPattern) + { + $this->targetPattern = $targetPattern; + + return $this; + } + + /** + * @param ?int $maxOccurrence + * @return $this + */ + public function withMaxOccurrence(?int $maxOccurrence) + { + $this->maxOccurrence = $maxOccurrence; + + return $this; + } + + /** + * @param ?string $selectionMode + * @return $this + */ + public function withSelectionMode(?string $selectionMode) + { + $this->selectionMode = $selectionMode; + + return $this; + } + + + public function build(): CartDiscountPatternTarget + { + return new CartDiscountPatternTargetModel( + $this->triggerPattern, + $this->targetPattern, + $this->maxOccurrence, + $this->selectionMode + ); + } + + public static function of(): CartDiscountPatternTargetBuilder + { + return new self(); + } +} diff --git a/lib/commercetools-api/src/Models/CartDiscount/CartDiscountPatternTargetCollection.php b/lib/commercetools-api/src/Models/CartDiscount/CartDiscountPatternTargetCollection.php new file mode 100644 index 00000000000..b3ace6dd412 --- /dev/null +++ b/lib/commercetools-api/src/Models/CartDiscount/CartDiscountPatternTargetCollection.php @@ -0,0 +1,56 @@ + + * @method CartDiscountPatternTarget current() + * @method CartDiscountPatternTarget end() + * @method CartDiscountPatternTarget at($offset) + */ +class CartDiscountPatternTargetCollection extends CartDiscountTargetCollection +{ + /** + * @psalm-assert CartDiscountPatternTarget $value + * @psalm-param CartDiscountPatternTarget|stdClass $value + * @throws InvalidArgumentException + * + * @return CartDiscountPatternTargetCollection + */ + public function add($value) + { + if (!$value instanceof CartDiscountPatternTarget) { + throw new InvalidArgumentException(); + } + $this->store($value); + + return $this; + } + + /** + * @psalm-return callable(int):?CartDiscountPatternTarget + */ + protected function mapper() + { + return function (?int $index): ?CartDiscountPatternTarget { + $data = $this->get($index); + if ($data instanceof stdClass) { + /** @var CartDiscountPatternTarget $data */ + $data = CartDiscountPatternTargetModel::of($data); + $this->set($data, $index); + } + + return $data; + }; + } +} diff --git a/lib/commercetools-api/src/Models/CartDiscount/CartDiscountPatternTargetModel.php b/lib/commercetools-api/src/Models/CartDiscount/CartDiscountPatternTargetModel.php new file mode 100644 index 00000000000..00bf6bbcfdd --- /dev/null +++ b/lib/commercetools-api/src/Models/CartDiscount/CartDiscountPatternTargetModel.php @@ -0,0 +1,206 @@ +triggerPattern = $triggerPattern; + $this->targetPattern = $targetPattern; + $this->maxOccurrence = $maxOccurrence; + $this->selectionMode = $selectionMode; + $this->type = $type ?? self::DISCRIMINATOR_VALUE; + } + + /** + * + * @return null|string + */ + public function getType() + { + if (is_null($this->type)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_TYPE); + if (is_null($data)) { + return null; + } + $this->type = (string) $data; + } + + return $this->type; + } + + /** + *

Units of a (Custom) Line Item that trigger a discount application.

+ *

Based on the availability of matching units, the triggerPattern can match multiple times, effecting the number of times the discount will be applied. + * To further limit the discount application, set the maxOccurrence.

+ *

If empty or not set, the Discount will apply indefinitely.

+ * + * + * @return null|PatternComponentCollection + */ + public function getTriggerPattern() + { + if (is_null($this->triggerPattern)) { + /** @psalm-var ?list $data */ + $data = $this->raw(self::FIELD_TRIGGER_PATTERN); + if (is_null($data)) { + return null; + } + $this->triggerPattern = PatternComponentCollection::fromArray($data); + } + + return $this->triggerPattern; + } + + /** + *

Units of (Custom) Line Items on which the Discount is applied.

+ *

Based on the availability of matching units and the limits from the triggerPattern or maxOccurence, the targetPattern can match multiple times.

+ * + * + * @return null|PatternComponentCollection + */ + public function getTargetPattern() + { + if (is_null($this->targetPattern)) { + /** @psalm-var ?list $data */ + $data = $this->raw(self::FIELD_TARGET_PATTERN); + if (is_null($data)) { + return null; + } + $this->targetPattern = PatternComponentCollection::fromArray($data); + } + + return $this->targetPattern; + } + + /** + *

Maximum number of times the Discount can apply on a Cart.

+ *

If empty or not set, the Discount will apply indefinitely.

+ * + * + * @return null|int + */ + public function getMaxOccurrence() + { + if (is_null($this->maxOccurrence)) { + /** @psalm-var ?int $data */ + $data = $this->raw(self::FIELD_MAX_OCCURRENCE); + if (is_null($data)) { + return null; + } + $this->maxOccurrence = (int) $data; + } + + return $this->maxOccurrence; + } + + /** + *

Determines which of the matching units of (Custom) Line Items are discounted.

+ * + * + * @return null|string + */ + public function getSelectionMode() + { + if (is_null($this->selectionMode)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_SELECTION_MODE); + if (is_null($data)) { + return null; + } + $this->selectionMode = (string) $data; + } + + return $this->selectionMode; + } + + + /** + * @param ?PatternComponentCollection $triggerPattern + */ + public function setTriggerPattern(?PatternComponentCollection $triggerPattern): void + { + $this->triggerPattern = $triggerPattern; + } + + /** + * @param ?PatternComponentCollection $targetPattern + */ + public function setTargetPattern(?PatternComponentCollection $targetPattern): void + { + $this->targetPattern = $targetPattern; + } + + /** + * @param ?int $maxOccurrence + */ + public function setMaxOccurrence(?int $maxOccurrence): void + { + $this->maxOccurrence = $maxOccurrence; + } + + /** + * @param ?string $selectionMode + */ + public function setSelectionMode(?string $selectionMode): void + { + $this->selectionMode = $selectionMode; + } +} diff --git a/lib/commercetools-api/src/Models/CartDiscount/CartDiscountTargetModel.php b/lib/commercetools-api/src/Models/CartDiscount/CartDiscountTargetModel.php index f4f64430e79..f2c31a97fc0 100644 --- a/lib/commercetools-api/src/Models/CartDiscount/CartDiscountTargetModel.php +++ b/lib/commercetools-api/src/Models/CartDiscount/CartDiscountTargetModel.php @@ -35,6 +35,7 @@ final class CartDiscountTargetModel extends JsonObjectModel implements CartDisco 'lineItems' => CartDiscountLineItemsTargetModel::class, 'multiBuyCustomLineItems' => MultiBuyCustomLineItemsTargetModel::class, 'multiBuyLineItems' => MultiBuyLineItemsTargetModel::class, + 'pattern' => CartDiscountPatternTargetModel::class, 'shipping' => CartDiscountShippingCostTargetModel::class, 'totalPrice' => CartDiscountTotalPriceTargetModel::class, ]; diff --git a/lib/commercetools-api/src/Models/CartDiscount/CartDiscountValueFixed.php b/lib/commercetools-api/src/Models/CartDiscount/CartDiscountValueFixed.php index 1b7c1cfcc03..6ae4436cbce 100644 --- a/lib/commercetools-api/src/Models/CartDiscount/CartDiscountValueFixed.php +++ b/lib/commercetools-api/src/Models/CartDiscount/CartDiscountValueFixed.php @@ -15,6 +15,7 @@ interface CartDiscountValueFixed extends CartDiscountValue { public const FIELD_MONEY = 'money'; + public const FIELD_APPLICATION_MODE = 'applicationMode'; /** *

Money values in cent precision or high precision of different currencies.

@@ -24,8 +25,22 @@ interface CartDiscountValueFixed extends CartDiscountValue */ public function getMoney(); + /** + *

Indicates how the discount is applied on CartDiscountLineItemTarget or CartDiscountCustomLineItemTarget.

+ *

For CartDiscountPatternTarget, the mode can also be ProportionateDistribution or EvenDistribution.

+ * + + * @return null|string + */ + public function getApplicationMode(); + /** * @param ?TypedMoneyCollection $money */ public function setMoney(?TypedMoneyCollection $money): void; + + /** + * @param ?string $applicationMode + */ + public function setApplicationMode(?string $applicationMode): void; } diff --git a/lib/commercetools-api/src/Models/CartDiscount/CartDiscountValueFixedBuilder.php b/lib/commercetools-api/src/Models/CartDiscount/CartDiscountValueFixedBuilder.php index 22905edbc1c..5c1924f0620 100644 --- a/lib/commercetools-api/src/Models/CartDiscount/CartDiscountValueFixedBuilder.php +++ b/lib/commercetools-api/src/Models/CartDiscount/CartDiscountValueFixedBuilder.php @@ -27,6 +27,12 @@ final class CartDiscountValueFixedBuilder implements Builder */ private $money; + /** + + * @var ?string + */ + private $applicationMode; + /** *

Money values in cent precision or high precision of different currencies.

* @@ -38,6 +44,18 @@ public function getMoney() return $this->money; } + /** + *

Indicates how the discount is applied on CartDiscountLineItemTarget or CartDiscountCustomLineItemTarget.

+ *

For CartDiscountPatternTarget, the mode can also be ProportionateDistribution or EvenDistribution.

+ * + + * @return null|string + */ + public function getApplicationMode() + { + return $this->applicationMode; + } + /** * @param ?TypedMoneyCollection $money * @return $this @@ -49,11 +67,23 @@ public function withMoney(?TypedMoneyCollection $money) return $this; } + /** + * @param ?string $applicationMode + * @return $this + */ + public function withApplicationMode(?string $applicationMode) + { + $this->applicationMode = $applicationMode; + + return $this; + } + public function build(): CartDiscountValueFixed { return new CartDiscountValueFixedModel( - $this->money + $this->money, + $this->applicationMode ); } diff --git a/lib/commercetools-api/src/Models/CartDiscount/CartDiscountValueFixedDraft.php b/lib/commercetools-api/src/Models/CartDiscount/CartDiscountValueFixedDraft.php index b85dfd61f83..8c9cc2c92bf 100644 --- a/lib/commercetools-api/src/Models/CartDiscount/CartDiscountValueFixedDraft.php +++ b/lib/commercetools-api/src/Models/CartDiscount/CartDiscountValueFixedDraft.php @@ -15,6 +15,7 @@ interface CartDiscountValueFixedDraft extends CartDiscountValueDraft { public const FIELD_MONEY = 'money'; + public const FIELD_APPLICATION_MODE = 'applicationMode'; /** *

Money values provided either in cent precision or high precision for different currencies. @@ -26,8 +27,22 @@ interface CartDiscountValueFixedDraft extends CartDiscountValueDraft */ public function getMoney(); + /** + *

Determines how the discount applies on CartDiscountLineItemTarget or CartDiscountCustomLineItemTarget.

+ *

For CartDiscountPatternTarget, you can also set the mode to ProportionateDistribution or EvenDistribution.

+ * + + * @return null|string + */ + public function getApplicationMode(); + /** * @param ?MoneyCollection $money */ public function setMoney(?MoneyCollection $money): void; + + /** + * @param ?string $applicationMode + */ + public function setApplicationMode(?string $applicationMode): void; } diff --git a/lib/commercetools-api/src/Models/CartDiscount/CartDiscountValueFixedDraftBuilder.php b/lib/commercetools-api/src/Models/CartDiscount/CartDiscountValueFixedDraftBuilder.php index caae790dd66..d145f4bc030 100644 --- a/lib/commercetools-api/src/Models/CartDiscount/CartDiscountValueFixedDraftBuilder.php +++ b/lib/commercetools-api/src/Models/CartDiscount/CartDiscountValueFixedDraftBuilder.php @@ -27,6 +27,12 @@ final class CartDiscountValueFixedDraftBuilder implements Builder */ private $money; + /** + + * @var ?string + */ + private $applicationMode; + /** *

Money values provided either in cent precision or high precision for different currencies. * A fixed Cart Discount will match a price only if the array contains a value with the same currency. For example, if it contains 10€ and 15$, the matching € price will be discounted by 10€ and the matching $ price will be discounted to 15$. If the array has multiple values of the same currency, the API returns an InvalidOperation error.

@@ -40,6 +46,18 @@ public function getMoney() return $this->money; } + /** + *

Determines how the discount applies on CartDiscountLineItemTarget or CartDiscountCustomLineItemTarget.

+ *

For CartDiscountPatternTarget, you can also set the mode to ProportionateDistribution or EvenDistribution.

+ * + + * @return null|string + */ + public function getApplicationMode() + { + return $this->applicationMode; + } + /** * @param ?MoneyCollection $money * @return $this @@ -51,11 +69,23 @@ public function withMoney(?MoneyCollection $money) return $this; } + /** + * @param ?string $applicationMode + * @return $this + */ + public function withApplicationMode(?string $applicationMode) + { + $this->applicationMode = $applicationMode; + + return $this; + } + public function build(): CartDiscountValueFixedDraft { return new CartDiscountValueFixedDraftModel( - $this->money + $this->money, + $this->applicationMode ); } diff --git a/lib/commercetools-api/src/Models/CartDiscount/CartDiscountValueFixedDraftModel.php b/lib/commercetools-api/src/Models/CartDiscount/CartDiscountValueFixedDraftModel.php index 40db3693450..bfa4f12760d 100644 --- a/lib/commercetools-api/src/Models/CartDiscount/CartDiscountValueFixedDraftModel.php +++ b/lib/commercetools-api/src/Models/CartDiscount/CartDiscountValueFixedDraftModel.php @@ -33,15 +33,23 @@ final class CartDiscountValueFixedDraftModel extends JsonObjectModel implements */ protected $money; + /** + * + * @var ?string + */ + protected $applicationMode; + /** * @psalm-suppress MissingParamType */ public function __construct( ?MoneyCollection $money = null, + ?string $applicationMode = null, ?string $type = null ) { $this->money = $money; + $this->applicationMode = $applicationMode; $this->type = $type ?? self::DISCRIMINATOR_VALUE; } @@ -85,6 +93,27 @@ public function getMoney() return $this->money; } + /** + *

Determines how the discount applies on CartDiscountLineItemTarget or CartDiscountCustomLineItemTarget.

+ *

For CartDiscountPatternTarget, you can also set the mode to ProportionateDistribution or EvenDistribution.

+ * + * + * @return null|string + */ + public function getApplicationMode() + { + if (is_null($this->applicationMode)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_APPLICATION_MODE); + if (is_null($data)) { + return null; + } + $this->applicationMode = (string) $data; + } + + return $this->applicationMode; + } + /** * @param ?MoneyCollection $money @@ -93,4 +122,12 @@ public function setMoney(?MoneyCollection $money): void { $this->money = $money; } + + /** + * @param ?string $applicationMode + */ + public function setApplicationMode(?string $applicationMode): void + { + $this->applicationMode = $applicationMode; + } } diff --git a/lib/commercetools-api/src/Models/CartDiscount/CartDiscountValueFixedModel.php b/lib/commercetools-api/src/Models/CartDiscount/CartDiscountValueFixedModel.php index d6661486540..c72c29adb32 100644 --- a/lib/commercetools-api/src/Models/CartDiscount/CartDiscountValueFixedModel.php +++ b/lib/commercetools-api/src/Models/CartDiscount/CartDiscountValueFixedModel.php @@ -33,15 +33,23 @@ final class CartDiscountValueFixedModel extends JsonObjectModel implements CartD */ protected $money; + /** + * + * @var ?string + */ + protected $applicationMode; + /** * @psalm-suppress MissingParamType */ public function __construct( ?TypedMoneyCollection $money = null, + ?string $applicationMode = null, ?string $type = null ) { $this->money = $money; + $this->applicationMode = $applicationMode; $this->type = $type ?? self::DISCRIMINATOR_VALUE; } @@ -83,6 +91,27 @@ public function getMoney() return $this->money; } + /** + *

Indicates how the discount is applied on CartDiscountLineItemTarget or CartDiscountCustomLineItemTarget.

+ *

For CartDiscountPatternTarget, the mode can also be ProportionateDistribution or EvenDistribution.

+ * + * + * @return null|string + */ + public function getApplicationMode() + { + if (is_null($this->applicationMode)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_APPLICATION_MODE); + if (is_null($data)) { + return null; + } + $this->applicationMode = (string) $data; + } + + return $this->applicationMode; + } + /** * @param ?TypedMoneyCollection $money @@ -91,4 +120,12 @@ public function setMoney(?TypedMoneyCollection $money): void { $this->money = $money; } + + /** + * @param ?string $applicationMode + */ + public function setApplicationMode(?string $applicationMode): void + { + $this->applicationMode = $applicationMode; + } } diff --git a/lib/commercetools-api/src/Models/CartDiscount/CountOnCustomLineItemUnits.php b/lib/commercetools-api/src/Models/CartDiscount/CountOnCustomLineItemUnits.php new file mode 100644 index 00000000000..46cae5daf3e --- /dev/null +++ b/lib/commercetools-api/src/Models/CartDiscount/CountOnCustomLineItemUnits.php @@ -0,0 +1,79 @@ +Valid CustomLineItem predicate that determines the units participating in the Discount.

+ * + + * @return null|string + */ + public function getPredicate(); + + /** + *

Minimum number of units of a Custom Line Item that match the predicate.

+ * + + * @return null|int + */ + public function getMinCount(); + + /** + *

Maximum number of units of a Custom Line Item that match the predicate. + * There might be more units matching the predicate, but they will not be participating to the resulting set.

+ *

The value must be greater than or equal to minCount. + * If not provided, the component will match all units that satisfy the predicate.

+ * + + * @return null|int + */ + public function getMaxCount(); + + /** + *

Number of units of a Custom Line Item to exclude on every application of the Discount.

+ *

Set only when configuring the targetPattern.

+ *

The units matched first (satisfying the pattern component) will be excluded from the resulting set. + * The minCountand maxCount are considered only after the exclusion. Pattern components are matched only if any further units satisfying the pattern component exist. + * For example, if 5 jeans are required but only 3 should be discounted, the excludeCount value must be 2.

+ * + + * @return null|int + */ + public function getExcludeCount(); + + /** + * @param ?string $predicate + */ + public function setPredicate(?string $predicate): void; + + /** + * @param ?int $minCount + */ + public function setMinCount(?int $minCount): void; + + /** + * @param ?int $maxCount + */ + public function setMaxCount(?int $maxCount): void; + + /** + * @param ?int $excludeCount + */ + public function setExcludeCount(?int $excludeCount): void; +} diff --git a/lib/commercetools-api/src/Models/CartDiscount/CountOnCustomLineItemUnitsBuilder.php b/lib/commercetools-api/src/Models/CartDiscount/CountOnCustomLineItemUnitsBuilder.php new file mode 100644 index 00000000000..d237137608a --- /dev/null +++ b/lib/commercetools-api/src/Models/CartDiscount/CountOnCustomLineItemUnitsBuilder.php @@ -0,0 +1,157 @@ + + */ +final class CountOnCustomLineItemUnitsBuilder implements Builder +{ + /** + + * @var ?string + */ + private $predicate; + + /** + + * @var ?int + */ + private $minCount; + + /** + + * @var ?int + */ + private $maxCount; + + /** + + * @var ?int + */ + private $excludeCount; + + /** + *

Valid CustomLineItem predicate that determines the units participating in the Discount.

+ * + + * @return null|string + */ + public function getPredicate() + { + return $this->predicate; + } + + /** + *

Minimum number of units of a Custom Line Item that match the predicate.

+ * + + * @return null|int + */ + public function getMinCount() + { + return $this->minCount; + } + + /** + *

Maximum number of units of a Custom Line Item that match the predicate. + * There might be more units matching the predicate, but they will not be participating to the resulting set.

+ *

The value must be greater than or equal to minCount. + * If not provided, the component will match all units that satisfy the predicate.

+ * + + * @return null|int + */ + public function getMaxCount() + { + return $this->maxCount; + } + + /** + *

Number of units of a Custom Line Item to exclude on every application of the Discount.

+ *

Set only when configuring the targetPattern.

+ *

The units matched first (satisfying the pattern component) will be excluded from the resulting set. + * The minCountand maxCount are considered only after the exclusion. Pattern components are matched only if any further units satisfying the pattern component exist. + * For example, if 5 jeans are required but only 3 should be discounted, the excludeCount value must be 2.

+ * + + * @return null|int + */ + public function getExcludeCount() + { + return $this->excludeCount; + } + + /** + * @param ?string $predicate + * @return $this + */ + public function withPredicate(?string $predicate) + { + $this->predicate = $predicate; + + return $this; + } + + /** + * @param ?int $minCount + * @return $this + */ + public function withMinCount(?int $minCount) + { + $this->minCount = $minCount; + + return $this; + } + + /** + * @param ?int $maxCount + * @return $this + */ + public function withMaxCount(?int $maxCount) + { + $this->maxCount = $maxCount; + + return $this; + } + + /** + * @param ?int $excludeCount + * @return $this + */ + public function withExcludeCount(?int $excludeCount) + { + $this->excludeCount = $excludeCount; + + return $this; + } + + + public function build(): CountOnCustomLineItemUnits + { + return new CountOnCustomLineItemUnitsModel( + $this->predicate, + $this->minCount, + $this->maxCount, + $this->excludeCount + ); + } + + public static function of(): CountOnCustomLineItemUnitsBuilder + { + return new self(); + } +} diff --git a/lib/commercetools-api/src/Models/CartDiscount/CountOnCustomLineItemUnitsCollection.php b/lib/commercetools-api/src/Models/CartDiscount/CountOnCustomLineItemUnitsCollection.php new file mode 100644 index 00000000000..c5c10633723 --- /dev/null +++ b/lib/commercetools-api/src/Models/CartDiscount/CountOnCustomLineItemUnitsCollection.php @@ -0,0 +1,56 @@ + + * @method CountOnCustomLineItemUnits current() + * @method CountOnCustomLineItemUnits end() + * @method CountOnCustomLineItemUnits at($offset) + */ +class CountOnCustomLineItemUnitsCollection extends PatternComponentCollection +{ + /** + * @psalm-assert CountOnCustomLineItemUnits $value + * @psalm-param CountOnCustomLineItemUnits|stdClass $value + * @throws InvalidArgumentException + * + * @return CountOnCustomLineItemUnitsCollection + */ + public function add($value) + { + if (!$value instanceof CountOnCustomLineItemUnits) { + throw new InvalidArgumentException(); + } + $this->store($value); + + return $this; + } + + /** + * @psalm-return callable(int):?CountOnCustomLineItemUnits + */ + protected function mapper() + { + return function (?int $index): ?CountOnCustomLineItemUnits { + $data = $this->get($index); + if ($data instanceof stdClass) { + /** @var CountOnCustomLineItemUnits $data */ + $data = CountOnCustomLineItemUnitsModel::of($data); + $this->set($data, $index); + } + + return $data; + }; + } +} diff --git a/lib/commercetools-api/src/Models/CartDiscount/CountOnCustomLineItemUnitsModel.php b/lib/commercetools-api/src/Models/CartDiscount/CountOnCustomLineItemUnitsModel.php new file mode 100644 index 00000000000..f4658fc80e7 --- /dev/null +++ b/lib/commercetools-api/src/Models/CartDiscount/CountOnCustomLineItemUnitsModel.php @@ -0,0 +1,208 @@ +predicate = $predicate; + $this->minCount = $minCount; + $this->maxCount = $maxCount; + $this->excludeCount = $excludeCount; + $this->type = $type ?? self::DISCRIMINATOR_VALUE; + } + + /** + * + * @return null|string + */ + public function getType() + { + if (is_null($this->type)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_TYPE); + if (is_null($data)) { + return null; + } + $this->type = (string) $data; + } + + return $this->type; + } + + /** + *

Valid CustomLineItem predicate that determines the units participating in the Discount.

+ * + * + * @return null|string + */ + public function getPredicate() + { + if (is_null($this->predicate)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_PREDICATE); + if (is_null($data)) { + return null; + } + $this->predicate = (string) $data; + } + + return $this->predicate; + } + + /** + *

Minimum number of units of a Custom Line Item that match the predicate.

+ * + * + * @return null|int + */ + public function getMinCount() + { + if (is_null($this->minCount)) { + /** @psalm-var ?int $data */ + $data = $this->raw(self::FIELD_MIN_COUNT); + if (is_null($data)) { + return null; + } + $this->minCount = (int) $data; + } + + return $this->minCount; + } + + /** + *

Maximum number of units of a Custom Line Item that match the predicate. + * There might be more units matching the predicate, but they will not be participating to the resulting set.

+ *

The value must be greater than or equal to minCount. + * If not provided, the component will match all units that satisfy the predicate.

+ * + * + * @return null|int + */ + public function getMaxCount() + { + if (is_null($this->maxCount)) { + /** @psalm-var ?int $data */ + $data = $this->raw(self::FIELD_MAX_COUNT); + if (is_null($data)) { + return null; + } + $this->maxCount = (int) $data; + } + + return $this->maxCount; + } + + /** + *

Number of units of a Custom Line Item to exclude on every application of the Discount.

+ *

Set only when configuring the targetPattern.

+ *

The units matched first (satisfying the pattern component) will be excluded from the resulting set. + * The minCountand maxCount are considered only after the exclusion. Pattern components are matched only if any further units satisfying the pattern component exist. + * For example, if 5 jeans are required but only 3 should be discounted, the excludeCount value must be 2.

+ * + * + * @return null|int + */ + public function getExcludeCount() + { + if (is_null($this->excludeCount)) { + /** @psalm-var ?int $data */ + $data = $this->raw(self::FIELD_EXCLUDE_COUNT); + if (is_null($data)) { + return null; + } + $this->excludeCount = (int) $data; + } + + return $this->excludeCount; + } + + + /** + * @param ?string $predicate + */ + public function setPredicate(?string $predicate): void + { + $this->predicate = $predicate; + } + + /** + * @param ?int $minCount + */ + public function setMinCount(?int $minCount): void + { + $this->minCount = $minCount; + } + + /** + * @param ?int $maxCount + */ + public function setMaxCount(?int $maxCount): void + { + $this->maxCount = $maxCount; + } + + /** + * @param ?int $excludeCount + */ + public function setExcludeCount(?int $excludeCount): void + { + $this->excludeCount = $excludeCount; + } +} diff --git a/lib/commercetools-api/src/Models/CartDiscount/CountOnLineItemUnits.php b/lib/commercetools-api/src/Models/CartDiscount/CountOnLineItemUnits.php new file mode 100644 index 00000000000..27c9089db04 --- /dev/null +++ b/lib/commercetools-api/src/Models/CartDiscount/CountOnLineItemUnits.php @@ -0,0 +1,79 @@ +Valid LineItem predicate that determines the units participating in the Discount.

+ * + + * @return null|string + */ + public function getPredicate(); + + /** + *

Minimum number of units of a Line Item that match the predicate.

+ * + + * @return null|int + */ + public function getMinCount(); + + /** + *

Maximum number of units of a Line Item that match the predicate. + * There might be more units matching the predicate, but they will not be participating to the resulting set.

+ *

The value must be greater than or equal to minCount. + * If not provided, the component will match all units that satisfy the predicate.

+ * + + * @return null|int + */ + public function getMaxCount(); + + /** + *

Number of units of a Line Item to exclude on every application of the Discount.

+ *

Set only when configuring the targetPattern.

+ *

The units matched first (satisfying the pattern component) will be excluded from the resulting set. + * The minCountand maxCount are considered only after the exclusion. Pattern components are matched only if any further units satisfying the pattern component exist. + * For example, if 5 jeans are required but only 3 should be discounted, the excludeCount value must be 2.

+ * + + * @return null|int + */ + public function getExcludeCount(); + + /** + * @param ?string $predicate + */ + public function setPredicate(?string $predicate): void; + + /** + * @param ?int $minCount + */ + public function setMinCount(?int $minCount): void; + + /** + * @param ?int $maxCount + */ + public function setMaxCount(?int $maxCount): void; + + /** + * @param ?int $excludeCount + */ + public function setExcludeCount(?int $excludeCount): void; +} diff --git a/lib/commercetools-api/src/Models/CartDiscount/CountOnLineItemUnitsBuilder.php b/lib/commercetools-api/src/Models/CartDiscount/CountOnLineItemUnitsBuilder.php new file mode 100644 index 00000000000..ea51c60960e --- /dev/null +++ b/lib/commercetools-api/src/Models/CartDiscount/CountOnLineItemUnitsBuilder.php @@ -0,0 +1,157 @@ + + */ +final class CountOnLineItemUnitsBuilder implements Builder +{ + /** + + * @var ?string + */ + private $predicate; + + /** + + * @var ?int + */ + private $minCount; + + /** + + * @var ?int + */ + private $maxCount; + + /** + + * @var ?int + */ + private $excludeCount; + + /** + *

Valid LineItem predicate that determines the units participating in the Discount.

+ * + + * @return null|string + */ + public function getPredicate() + { + return $this->predicate; + } + + /** + *

Minimum number of units of a Line Item that match the predicate.

+ * + + * @return null|int + */ + public function getMinCount() + { + return $this->minCount; + } + + /** + *

Maximum number of units of a Line Item that match the predicate. + * There might be more units matching the predicate, but they will not be participating to the resulting set.

+ *

The value must be greater than or equal to minCount. + * If not provided, the component will match all units that satisfy the predicate.

+ * + + * @return null|int + */ + public function getMaxCount() + { + return $this->maxCount; + } + + /** + *

Number of units of a Line Item to exclude on every application of the Discount.

+ *

Set only when configuring the targetPattern.

+ *

The units matched first (satisfying the pattern component) will be excluded from the resulting set. + * The minCountand maxCount are considered only after the exclusion. Pattern components are matched only if any further units satisfying the pattern component exist. + * For example, if 5 jeans are required but only 3 should be discounted, the excludeCount value must be 2.

+ * + + * @return null|int + */ + public function getExcludeCount() + { + return $this->excludeCount; + } + + /** + * @param ?string $predicate + * @return $this + */ + public function withPredicate(?string $predicate) + { + $this->predicate = $predicate; + + return $this; + } + + /** + * @param ?int $minCount + * @return $this + */ + public function withMinCount(?int $minCount) + { + $this->minCount = $minCount; + + return $this; + } + + /** + * @param ?int $maxCount + * @return $this + */ + public function withMaxCount(?int $maxCount) + { + $this->maxCount = $maxCount; + + return $this; + } + + /** + * @param ?int $excludeCount + * @return $this + */ + public function withExcludeCount(?int $excludeCount) + { + $this->excludeCount = $excludeCount; + + return $this; + } + + + public function build(): CountOnLineItemUnits + { + return new CountOnLineItemUnitsModel( + $this->predicate, + $this->minCount, + $this->maxCount, + $this->excludeCount + ); + } + + public static function of(): CountOnLineItemUnitsBuilder + { + return new self(); + } +} diff --git a/lib/commercetools-api/src/Models/CartDiscount/CountOnLineItemUnitsCollection.php b/lib/commercetools-api/src/Models/CartDiscount/CountOnLineItemUnitsCollection.php new file mode 100644 index 00000000000..5cb59c0fada --- /dev/null +++ b/lib/commercetools-api/src/Models/CartDiscount/CountOnLineItemUnitsCollection.php @@ -0,0 +1,56 @@ + + * @method CountOnLineItemUnits current() + * @method CountOnLineItemUnits end() + * @method CountOnLineItemUnits at($offset) + */ +class CountOnLineItemUnitsCollection extends PatternComponentCollection +{ + /** + * @psalm-assert CountOnLineItemUnits $value + * @psalm-param CountOnLineItemUnits|stdClass $value + * @throws InvalidArgumentException + * + * @return CountOnLineItemUnitsCollection + */ + public function add($value) + { + if (!$value instanceof CountOnLineItemUnits) { + throw new InvalidArgumentException(); + } + $this->store($value); + + return $this; + } + + /** + * @psalm-return callable(int):?CountOnLineItemUnits + */ + protected function mapper() + { + return function (?int $index): ?CountOnLineItemUnits { + $data = $this->get($index); + if ($data instanceof stdClass) { + /** @var CountOnLineItemUnits $data */ + $data = CountOnLineItemUnitsModel::of($data); + $this->set($data, $index); + } + + return $data; + }; + } +} diff --git a/lib/commercetools-api/src/Models/CartDiscount/CountOnLineItemUnitsModel.php b/lib/commercetools-api/src/Models/CartDiscount/CountOnLineItemUnitsModel.php new file mode 100644 index 00000000000..6bbb4d3f61c --- /dev/null +++ b/lib/commercetools-api/src/Models/CartDiscount/CountOnLineItemUnitsModel.php @@ -0,0 +1,208 @@ +predicate = $predicate; + $this->minCount = $minCount; + $this->maxCount = $maxCount; + $this->excludeCount = $excludeCount; + $this->type = $type ?? self::DISCRIMINATOR_VALUE; + } + + /** + * + * @return null|string + */ + public function getType() + { + if (is_null($this->type)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_TYPE); + if (is_null($data)) { + return null; + } + $this->type = (string) $data; + } + + return $this->type; + } + + /** + *

Valid LineItem predicate that determines the units participating in the Discount.

+ * + * + * @return null|string + */ + public function getPredicate() + { + if (is_null($this->predicate)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_PREDICATE); + if (is_null($data)) { + return null; + } + $this->predicate = (string) $data; + } + + return $this->predicate; + } + + /** + *

Minimum number of units of a Line Item that match the predicate.

+ * + * + * @return null|int + */ + public function getMinCount() + { + if (is_null($this->minCount)) { + /** @psalm-var ?int $data */ + $data = $this->raw(self::FIELD_MIN_COUNT); + if (is_null($data)) { + return null; + } + $this->minCount = (int) $data; + } + + return $this->minCount; + } + + /** + *

Maximum number of units of a Line Item that match the predicate. + * There might be more units matching the predicate, but they will not be participating to the resulting set.

+ *

The value must be greater than or equal to minCount. + * If not provided, the component will match all units that satisfy the predicate.

+ * + * + * @return null|int + */ + public function getMaxCount() + { + if (is_null($this->maxCount)) { + /** @psalm-var ?int $data */ + $data = $this->raw(self::FIELD_MAX_COUNT); + if (is_null($data)) { + return null; + } + $this->maxCount = (int) $data; + } + + return $this->maxCount; + } + + /** + *

Number of units of a Line Item to exclude on every application of the Discount.

+ *

Set only when configuring the targetPattern.

+ *

The units matched first (satisfying the pattern component) will be excluded from the resulting set. + * The minCountand maxCount are considered only after the exclusion. Pattern components are matched only if any further units satisfying the pattern component exist. + * For example, if 5 jeans are required but only 3 should be discounted, the excludeCount value must be 2.

+ * + * + * @return null|int + */ + public function getExcludeCount() + { + if (is_null($this->excludeCount)) { + /** @psalm-var ?int $data */ + $data = $this->raw(self::FIELD_EXCLUDE_COUNT); + if (is_null($data)) { + return null; + } + $this->excludeCount = (int) $data; + } + + return $this->excludeCount; + } + + + /** + * @param ?string $predicate + */ + public function setPredicate(?string $predicate): void + { + $this->predicate = $predicate; + } + + /** + * @param ?int $minCount + */ + public function setMinCount(?int $minCount): void + { + $this->minCount = $minCount; + } + + /** + * @param ?int $maxCount + */ + public function setMaxCount(?int $maxCount): void + { + $this->maxCount = $maxCount; + } + + /** + * @param ?int $excludeCount + */ + public function setExcludeCount(?int $excludeCount): void + { + $this->excludeCount = $excludeCount; + } +} diff --git a/lib/commercetools-api/src/Models/CartDiscount/PatternComponent.php b/lib/commercetools-api/src/Models/CartDiscount/PatternComponent.php new file mode 100644 index 00000000000..6b0a8c93f5d --- /dev/null +++ b/lib/commercetools-api/src/Models/CartDiscount/PatternComponent.php @@ -0,0 +1,24 @@ + + */ +final class PatternComponentBuilder implements Builder +{ + public function build(): PatternComponent + { + return new PatternComponentModel( + ); + } + + public static function of(): PatternComponentBuilder + { + return new self(); + } +} diff --git a/lib/commercetools-api/src/Models/CartDiscount/PatternComponentCollection.php b/lib/commercetools-api/src/Models/CartDiscount/PatternComponentCollection.php new file mode 100644 index 00000000000..a276c22fdec --- /dev/null +++ b/lib/commercetools-api/src/Models/CartDiscount/PatternComponentCollection.php @@ -0,0 +1,60 @@ + + * @psalm-method T current() + * @psalm-method T end() + * @psalm-method T at($offset) + * @method PatternComponent current() + * @method PatternComponent end() + * @method PatternComponent at($offset) + */ +class PatternComponentCollection extends MapperSequence +{ + /** + * @psalm-assert T $value + * @psalm-param T|stdClass $value + * @throws InvalidArgumentException + * + * @return PatternComponentCollection + */ + public function add($value) + { + if (!$value instanceof PatternComponent) { + throw new InvalidArgumentException(); + } + $this->store($value); + + return $this; + } + + /** + * @psalm-return callable(int):?T + */ + protected function mapper() + { + return function (?int $index): ?PatternComponent { + $data = $this->get($index); + if ($data instanceof stdClass) { + /** @var T $data */ + $data = PatternComponentModel::of($data); + $this->set($data, $index); + } + + return $data; + }; + } +} diff --git a/lib/commercetools-api/src/Models/CartDiscount/PatternComponentModel.php b/lib/commercetools-api/src/Models/CartDiscount/PatternComponentModel.php new file mode 100644 index 00000000000..198d8918422 --- /dev/null +++ b/lib/commercetools-api/src/Models/CartDiscount/PatternComponentModel.php @@ -0,0 +1,95 @@ + > + * + */ + private static $discriminatorClasses = [ + 'CountOnCustomLineItemUnits' => CountOnCustomLineItemUnitsModel::class, + 'CountOnLineItemUnits' => CountOnLineItemUnitsModel::class, + ]; + + /** + * @psalm-suppress MissingParamType + */ + public function __construct( + ?string $type = null + ) { + $this->type = $type; + } + + /** + * + * @return null|string + */ + public function getType() + { + if (is_null($this->type)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_TYPE); + if (is_null($data)) { + return null; + } + $this->type = (string) $data; + } + + return $this->type; + } + + + + + + /** + * @psalm-param stdClass|array $value + * @psalm-return class-string + */ + public static function resolveDiscriminatorClass($value): string + { + $fieldName = PatternComponent::DISCRIMINATOR_FIELD; + if (is_object($value) && isset($value->$fieldName)) { + /** @psalm-var string $discriminatorValue */ + $discriminatorValue = $value->$fieldName; + if (isset(self::$discriminatorClasses[$discriminatorValue])) { + return self::$discriminatorClasses[$discriminatorValue]; + } + } + if (is_array($value) && isset($value[$fieldName])) { + /** @psalm-var string $discriminatorValue */ + $discriminatorValue = $value[$fieldName]; + if (isset(self::$discriminatorClasses[$discriminatorValue])) { + return self::$discriminatorClasses[$discriminatorValue]; + } + } + + /** @psalm-var class-string */ + $type = PatternComponentModel::class; + return $type; + } +} diff --git a/lib/commercetools-api/src/Models/Order/CustomLineItemImportDraft.php b/lib/commercetools-api/src/Models/Order/CustomLineItemImportDraft.php index 8fdb3287b24..c06dcbfa03f 100644 --- a/lib/commercetools-api/src/Models/Order/CustomLineItemImportDraft.php +++ b/lib/commercetools-api/src/Models/Order/CustomLineItemImportDraft.php @@ -89,8 +89,7 @@ public function getTaxCategory(); /** * * diff --git a/lib/commercetools-api/src/Models/Order/CustomLineItemImportDraftBuilder.php b/lib/commercetools-api/src/Models/Order/CustomLineItemImportDraftBuilder.php index b316d7d325f..9e0db3ccf24 100644 --- a/lib/commercetools-api/src/Models/Order/CustomLineItemImportDraftBuilder.php +++ b/lib/commercetools-api/src/Models/Order/CustomLineItemImportDraftBuilder.php @@ -177,8 +177,7 @@ public function getTaxCategory() /** * * diff --git a/lib/commercetools-api/src/Models/Order/CustomLineItemImportDraftModel.php b/lib/commercetools-api/src/Models/Order/CustomLineItemImportDraftModel.php index 1bf37a36d3c..6258d375a29 100644 --- a/lib/commercetools-api/src/Models/Order/CustomLineItemImportDraftModel.php +++ b/lib/commercetools-api/src/Models/Order/CustomLineItemImportDraftModel.php @@ -273,8 +273,7 @@ public function getTaxCategory() /** * * diff --git a/lib/commercetools-api/src/Models/OrderEdit/StagedOrderAddCustomLineItemAction.php b/lib/commercetools-api/src/Models/OrderEdit/StagedOrderAddCustomLineItemAction.php index b87c0c3aa8b..4f4b8b58779 100644 --- a/lib/commercetools-api/src/Models/OrderEdit/StagedOrderAddCustomLineItemAction.php +++ b/lib/commercetools-api/src/Models/OrderEdit/StagedOrderAddCustomLineItemAction.php @@ -98,8 +98,7 @@ public function getShippingDetails(); /** * * diff --git a/lib/commercetools-api/src/Models/OrderEdit/StagedOrderAddCustomLineItemActionBuilder.php b/lib/commercetools-api/src/Models/OrderEdit/StagedOrderAddCustomLineItemActionBuilder.php index 1b49d6471ed..27dab9cbd7b 100644 --- a/lib/commercetools-api/src/Models/OrderEdit/StagedOrderAddCustomLineItemActionBuilder.php +++ b/lib/commercetools-api/src/Models/OrderEdit/StagedOrderAddCustomLineItemActionBuilder.php @@ -185,8 +185,7 @@ public function getShippingDetails() /** * * diff --git a/lib/commercetools-api/src/Models/OrderEdit/StagedOrderAddCustomLineItemActionModel.php b/lib/commercetools-api/src/Models/OrderEdit/StagedOrderAddCustomLineItemActionModel.php index 66cdfe44d44..518322da13d 100644 --- a/lib/commercetools-api/src/Models/OrderEdit/StagedOrderAddCustomLineItemActionModel.php +++ b/lib/commercetools-api/src/Models/OrderEdit/StagedOrderAddCustomLineItemActionModel.php @@ -316,8 +316,7 @@ public function getShippingDetails() /** * * diff --git a/lib/commercetools-history/src/Models/CartDiscount/PatternComponent.php b/lib/commercetools-history/src/Models/CartDiscount/PatternComponent.php new file mode 100644 index 00000000000..4688b2132ae --- /dev/null +++ b/lib/commercetools-history/src/Models/CartDiscount/PatternComponent.php @@ -0,0 +1,25 @@ + + */ +final class PatternComponentBuilder implements Builder +{ + + + + + public function build(): PatternComponent + { + return new PatternComponentModel( + ); + } + + public static function of(): PatternComponentBuilder + { + return new self(); + } +} diff --git a/lib/commercetools-history/src/Models/CartDiscount/PatternComponentCollection.php b/lib/commercetools-history/src/Models/CartDiscount/PatternComponentCollection.php new file mode 100644 index 00000000000..c952ac573d7 --- /dev/null +++ b/lib/commercetools-history/src/Models/CartDiscount/PatternComponentCollection.php @@ -0,0 +1,56 @@ + + * @method PatternComponent current() + * @method PatternComponent end() + * @method PatternComponent at($offset) + */ +class PatternComponentCollection extends MapperSequence +{ + /** + * @psalm-assert PatternComponent $value + * @psalm-param PatternComponent|stdClass $value + * @throws InvalidArgumentException + * + * @return PatternComponentCollection + */ + public function add($value) + { + if (!$value instanceof PatternComponent) { + throw new InvalidArgumentException(); + } + $this->store($value); + + return $this; + } + + /** + * @psalm-return callable(int):?PatternComponent + */ + protected function mapper() + { + return function (?int $index): ?PatternComponent { + $data = $this->get($index); + if ($data instanceof stdClass) { + /** @var PatternComponent $data */ + $data = PatternComponentModel::of($data); + $this->set($data, $index); + } + + return $data; + }; + } +} diff --git a/lib/commercetools-history/src/Models/CartDiscount/PatternComponentModel.php b/lib/commercetools-history/src/Models/CartDiscount/PatternComponentModel.php new file mode 100644 index 00000000000..9d0fe1a2afe --- /dev/null +++ b/lib/commercetools-history/src/Models/CartDiscount/PatternComponentModel.php @@ -0,0 +1,95 @@ + > + * + */ + private static $discriminatorClasses = [ + ]; + + /** + * @psalm-suppress MissingParamType + */ + public function __construct( + ?string $type = null + ) { + $this->type = $type; + + } + + /** + * + * @return null|string + */ + public function getType() + { + if (is_null($this->type)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_TYPE); + if (is_null($data)) { + return null; + } + $this->type = (string) $data; + } + + return $this->type; + } + + + + + + /** + * @psalm-param stdClass|array $value + * @psalm-return class-string + */ + public static function resolveDiscriminatorClass($value): string + { + $fieldName = PatternComponent::DISCRIMINATOR_FIELD; + if (is_object($value) && isset($value->$fieldName)) { + /** @psalm-var string $discriminatorValue */ + $discriminatorValue = $value->$fieldName; + if (isset(self::$discriminatorClasses[$discriminatorValue])) { + return self::$discriminatorClasses[$discriminatorValue]; + } + } + if (is_array($value) && isset($value[$fieldName])) { + /** @psalm-var string $discriminatorValue */ + $discriminatorValue = $value[$fieldName]; + if (isset(self::$discriminatorClasses[$discriminatorValue])) { + return self::$discriminatorClasses[$discriminatorValue]; + } + } + + /** @psalm-var class-string */ + $type = PatternComponentModel::class; + return $type; + } +} diff --git a/lib/commercetools-history/src/Models/ChangeValue/ChangeTargetChangeValueModel.php b/lib/commercetools-history/src/Models/ChangeValue/ChangeTargetChangeValueModel.php index 11260aa09fc..c2d472b7550 100644 --- a/lib/commercetools-history/src/Models/ChangeValue/ChangeTargetChangeValueModel.php +++ b/lib/commercetools-history/src/Models/ChangeValue/ChangeTargetChangeValueModel.php @@ -36,6 +36,7 @@ final class ChangeTargetChangeValueModel extends JsonObjectModel implements Chan 'lineItems' => ChangeTargetLineItemsChangeValueModel::class, 'multiBuyCustomLineItems' => ChangeTargetMultiBuyCustomLineItemsChangeValueModel::class, 'multiBuyLineItems' => ChangeTargetMultiBuyLineItemsChangeValueModel::class, + 'pattern' => ChangeTargetPatternChangeValueModel::class, 'shipping' => ChangeTargetShippingChangeValueModel::class, ]; diff --git a/lib/commercetools-history/src/Models/ChangeValue/ChangeTargetPatternChangeValue.php b/lib/commercetools-history/src/Models/ChangeValue/ChangeTargetPatternChangeValue.php new file mode 100644 index 00000000000..a733416abfb --- /dev/null +++ b/lib/commercetools-history/src/Models/ChangeValue/ChangeTargetPatternChangeValue.php @@ -0,0 +1,81 @@ +Units of a (Custom) Line Item that triggered the discount application.

+ * + + * @return null|PatternComponentCollection + */ + public function getTriggerPattern(); + + /** + *

Units of (Custom) Line Items on which the Discount is applied.

+ * + + * @return null|PatternComponentCollection + */ + public function getTargetPattern(); + + /** + *

Maximum number of times the Discount applies on a Cart.

+ *

If empty, the Discount applies indefinitely.

+ * + + * @return null|int + */ + public function getMaxOccurrence(); + + /** + *

Indicates which of the matching units of (Custom) Line Items were discounted.

+ * + + * @return null|string + */ + public function getSelectionMode(); + + /** + * @param ?PatternComponentCollection $triggerPattern + */ + public function setTriggerPattern(?PatternComponentCollection $triggerPattern): void; + + /** + * @param ?PatternComponentCollection $targetPattern + */ + public function setTargetPattern(?PatternComponentCollection $targetPattern): void; + + /** + * @param ?int $maxOccurrence + */ + public function setMaxOccurrence(?int $maxOccurrence): void; + + /** + * @param ?string $selectionMode + */ + public function setSelectionMode(?string $selectionMode): void; +} diff --git a/lib/commercetools-history/src/Models/ChangeValue/ChangeTargetPatternChangeValueBuilder.php b/lib/commercetools-history/src/Models/ChangeValue/ChangeTargetPatternChangeValueBuilder.php new file mode 100644 index 00000000000..2431ad8ba3f --- /dev/null +++ b/lib/commercetools-history/src/Models/ChangeValue/ChangeTargetPatternChangeValueBuilder.php @@ -0,0 +1,152 @@ + + */ +final class ChangeTargetPatternChangeValueBuilder implements Builder +{ + /** + + * @var ?PatternComponentCollection + */ + private $triggerPattern; + + /** + + * @var ?PatternComponentCollection + */ + private $targetPattern; + + /** + + * @var ?int + */ + private $maxOccurrence; + + /** + + * @var ?string + */ + private $selectionMode; + + /** + *

Units of a (Custom) Line Item that triggered the discount application.

+ * + + * @return null|PatternComponentCollection + */ + public function getTriggerPattern() + { + return $this->triggerPattern; + } + + /** + *

Units of (Custom) Line Items on which the Discount is applied.

+ * + + * @return null|PatternComponentCollection + */ + public function getTargetPattern() + { + return $this->targetPattern; + } + + /** + *

Maximum number of times the Discount applies on a Cart.

+ *

If empty, the Discount applies indefinitely.

+ * + + * @return null|int + */ + public function getMaxOccurrence() + { + return $this->maxOccurrence; + } + + /** + *

Indicates which of the matching units of (Custom) Line Items were discounted.

+ * + + * @return null|string + */ + public function getSelectionMode() + { + return $this->selectionMode; + } + + /** + * @param ?PatternComponentCollection $triggerPattern + * @return $this + */ + public function withTriggerPattern(?PatternComponentCollection $triggerPattern) + { + $this->triggerPattern = $triggerPattern; + + return $this; + } + + /** + * @param ?PatternComponentCollection $targetPattern + * @return $this + */ + public function withTargetPattern(?PatternComponentCollection $targetPattern) + { + $this->targetPattern = $targetPattern; + + return $this; + } + + /** + * @param ?int $maxOccurrence + * @return $this + */ + public function withMaxOccurrence(?int $maxOccurrence) + { + $this->maxOccurrence = $maxOccurrence; + + return $this; + } + + /** + * @param ?string $selectionMode + * @return $this + */ + public function withSelectionMode(?string $selectionMode) + { + $this->selectionMode = $selectionMode; + + return $this; + } + + + public function build(): ChangeTargetPatternChangeValue + { + return new ChangeTargetPatternChangeValueModel( + $this->triggerPattern, + $this->targetPattern, + $this->maxOccurrence, + $this->selectionMode + ); + } + + public static function of(): ChangeTargetPatternChangeValueBuilder + { + return new self(); + } +} diff --git a/lib/commercetools-history/src/Models/ChangeValue/ChangeTargetPatternChangeValueCollection.php b/lib/commercetools-history/src/Models/ChangeValue/ChangeTargetPatternChangeValueCollection.php new file mode 100644 index 00000000000..9c3dc384521 --- /dev/null +++ b/lib/commercetools-history/src/Models/ChangeValue/ChangeTargetPatternChangeValueCollection.php @@ -0,0 +1,56 @@ + + * @method ChangeTargetPatternChangeValue current() + * @method ChangeTargetPatternChangeValue end() + * @method ChangeTargetPatternChangeValue at($offset) + */ +class ChangeTargetPatternChangeValueCollection extends ChangeTargetChangeValueCollection +{ + /** + * @psalm-assert ChangeTargetPatternChangeValue $value + * @psalm-param ChangeTargetPatternChangeValue|stdClass $value + * @throws InvalidArgumentException + * + * @return ChangeTargetPatternChangeValueCollection + */ + public function add($value) + { + if (!$value instanceof ChangeTargetPatternChangeValue) { + throw new InvalidArgumentException(); + } + $this->store($value); + + return $this; + } + + /** + * @psalm-return callable(int):?ChangeTargetPatternChangeValue + */ + protected function mapper() + { + return function (?int $index): ?ChangeTargetPatternChangeValue { + $data = $this->get($index); + if ($data instanceof stdClass) { + /** @var ChangeTargetPatternChangeValue $data */ + $data = ChangeTargetPatternChangeValueModel::of($data); + $this->set($data, $index); + } + + return $data; + }; + } +} diff --git a/lib/commercetools-history/src/Models/ChangeValue/ChangeTargetPatternChangeValueModel.php b/lib/commercetools-history/src/Models/ChangeValue/ChangeTargetPatternChangeValueModel.php new file mode 100644 index 00000000000..4250438d5fd --- /dev/null +++ b/lib/commercetools-history/src/Models/ChangeValue/ChangeTargetPatternChangeValueModel.php @@ -0,0 +1,207 @@ +triggerPattern = $triggerPattern; + $this->targetPattern = $targetPattern; + $this->maxOccurrence = $maxOccurrence; + $this->selectionMode = $selectionMode; + $this->type = $type ?? self::DISCRIMINATOR_VALUE; + } + + /** + * + * @return null|string + */ + public function getType() + { + if (is_null($this->type)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_TYPE); + if (is_null($data)) { + return null; + } + $this->type = (string) $data; + } + + return $this->type; + } + + /** + *

Units of a (Custom) Line Item that triggered the discount application.

+ * + * + * @return null|PatternComponentCollection + */ + public function getTriggerPattern() + { + if (is_null($this->triggerPattern)) { + /** @psalm-var ?list $data */ + $data = $this->raw(self::FIELD_TRIGGER_PATTERN); + if (is_null($data)) { + return null; + } + $this->triggerPattern = PatternComponentCollection::fromArray($data); + } + + return $this->triggerPattern; + } + + /** + *

Units of (Custom) Line Items on which the Discount is applied.

+ * + * + * @return null|PatternComponentCollection + */ + public function getTargetPattern() + { + if (is_null($this->targetPattern)) { + /** @psalm-var ?list $data */ + $data = $this->raw(self::FIELD_TARGET_PATTERN); + if (is_null($data)) { + return null; + } + $this->targetPattern = PatternComponentCollection::fromArray($data); + } + + return $this->targetPattern; + } + + /** + *

Maximum number of times the Discount applies on a Cart.

+ *

If empty, the Discount applies indefinitely.

+ * + * + * @return null|int + */ + public function getMaxOccurrence() + { + if (is_null($this->maxOccurrence)) { + /** @psalm-var ?int $data */ + $data = $this->raw(self::FIELD_MAX_OCCURRENCE); + if (is_null($data)) { + return null; + } + $this->maxOccurrence = (int) $data; + } + + return $this->maxOccurrence; + } + + /** + *

Indicates which of the matching units of (Custom) Line Items were discounted.

+ * + * + * @return null|string + */ + public function getSelectionMode() + { + if (is_null($this->selectionMode)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_SELECTION_MODE); + if (is_null($data)) { + return null; + } + $this->selectionMode = (string) $data; + } + + return $this->selectionMode; + } + + + /** + * @param ?PatternComponentCollection $triggerPattern + */ + public function setTriggerPattern(?PatternComponentCollection $triggerPattern): void + { + $this->triggerPattern = $triggerPattern; + } + + /** + * @param ?PatternComponentCollection $targetPattern + */ + public function setTargetPattern(?PatternComponentCollection $targetPattern): void + { + $this->targetPattern = $targetPattern; + } + + /** + * @param ?int $maxOccurrence + */ + public function setMaxOccurrence(?int $maxOccurrence): void + { + $this->maxOccurrence = $maxOccurrence; + } + + /** + * @param ?string $selectionMode + */ + public function setSelectionMode(?string $selectionMode): void + { + $this->selectionMode = $selectionMode; + } + + + +} diff --git a/references.txt b/references.txt index 6e159582a90..9a6fdcabf61 100644 --- a/references.txt +++ b/references.txt @@ -334,3 +334,4 @@ df53588d26d7953dfdf44166866ca03045f0a70b 99e7aa1c7e3ba67a59b6df3efbaf4e320611c549 269027575a6fd5a2a29387930064a06f22f09bbf 9c2f053d7f45e95984760f59a344e9630d90d843 +175b7fc3843bb9be3aa5932b126d7fb3f1b0596d