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`
+Added Type(s)
+
+- added type `ChangeTargetPatternChangeValue`
+- added type `PatternComponent`
+
Standard, Cart Discounts with a matching CartDiscountCustomLineItemsTarget
- * are applied to the Custom Line Item.Standard, Cart Discounts with a matching CartDiscountCustomLineItemsTarget, MultiBuyCustomLineItemsTarget, or CartDiscountPatternTarget are applied to the Custom Line Item.External, Cart Discounts are not considered on the Custom Line Item.Standard, Cart Discounts with a matching CartDiscountCustomLineItemsTarget
- * are applied to the Custom Line Item.Standard, Cart Discounts with a matching CartDiscountCustomLineItemsTarget, MultiBuyCustomLineItemsTarget, or CartDiscountPatternTarget are applied to the Custom Line Item.External, Cart Discounts are not considered on the Custom Line Item.Standard, Cart Discounts with a matching CartDiscountCustomLineItemsTarget
- * are applied to the Custom Line Item.Standard, Cart Discounts with a matching CartDiscountCustomLineItemsTarget, MultiBuyCustomLineItemsTarget, or CartDiscountPatternTarget are applied to the Custom Line Item.External, Cart Discounts are not considered on the Custom Line Item.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(); /** *Standard, Cart Discounts with a matching CartDiscountCustomLineItemsTarget
- * are applied to the Custom Line Item.Standard, Cart Discounts with a matching CartDiscountCustomLineItemsTarget, MultiBuyCustomLineItemsTarget, or CartDiscountPatternTarget are applied to the Custom Line Item.External, Cart Discounts are not considered on the Custom Line Item.Standard, Cart Discounts with a matching CartDiscountCustomLineItemsTarget
- * are applied to the Custom Line Item.Standard, Cart Discounts with a matching CartDiscountCustomLineItemsTarget, MultiBuyCustomLineItemsTarget, or CartDiscountPatternTarget are applied to the Custom Line Item.External, Cart Discounts are not considered on the Custom Line Item.Standard, Cart Discounts with a matching CartDiscountCustomLineItemsTarget
- * are applied to the Custom Line Item.Standard, Cart Discounts with a matching CartDiscountCustomLineItemsTarget, MultiBuyCustomLineItemsTarget, or CartDiscountPatternTarget are applied to the Custom Line Item.External, Cart Discounts are not considered on the Custom Line Item.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.
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.
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 ?listUnits 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.
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.
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.
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.
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.
Determines how the discount applies on CartDiscountLineItemTarget or CartDiscountCustomLineItemTarget.
+ *For CartDiscountPatternTarget, you can also set the mode to ProportionateDistribution or EvenDistribution.
Indicates how the discount is applied on CartDiscountLineItemTarget or CartDiscountCustomLineItemTarget.
+ *For CartDiscountPatternTarget, the mode can also be ProportionateDistribution or EvenDistribution.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Standard, Cart Discounts with a matching CartDiscountCustomLineItemsTarget
- * are applied to the Custom Line Item.Standard, Cart Discounts with a matching CartDiscountCustomLineItemsTarget, MultiBuyCustomLineItemsTarget, or CartDiscountPatternTarget are applied to the Custom Line Item.External, Cart Discounts are not considered on the Custom Line Item.Standard, Cart Discounts with a matching CartDiscountCustomLineItemsTarget
- * are applied to the Custom Line Item.Standard, Cart Discounts with a matching CartDiscountCustomLineItemsTarget, MultiBuyCustomLineItemsTarget, or CartDiscountPatternTarget are applied to the Custom Line Item.External, Cart Discounts are not considered on the Custom Line Item.Standard, Cart Discounts with a matching CartDiscountCustomLineItemsTarget
- * are applied to the Custom Line Item.Standard, Cart Discounts with a matching CartDiscountCustomLineItemsTarget, MultiBuyCustomLineItemsTarget, or CartDiscountPatternTarget are applied to the Custom Line Item.External, Cart Discounts are not considered on the Custom Line Item.Standard, Cart Discounts with a matching CartDiscountCustomLineItemsTarget
- * are applied to the Custom Line Item.Standard, Cart Discounts with a matching CartDiscountCustomLineItemsTarget, MultiBuyCustomLineItemsTarget, or CartDiscountPatternTarget are applied to the Custom Line Item.External, Cart Discounts are not considered on the Custom Line Item.Standard, Cart Discounts with a matching CartDiscountCustomLineItemsTarget
- * are applied to the Custom Line Item.Standard, Cart Discounts with a matching CartDiscountCustomLineItemsTarget, MultiBuyCustomLineItemsTarget, or CartDiscountPatternTarget are applied to the Custom Line Item.External, Cart Discounts are not considered on the Custom Line Item.Standard, Cart Discounts with a matching CartDiscountCustomLineItemsTarget
- * are applied to the Custom Line Item.Standard, Cart Discounts with a matching CartDiscountCustomLineItemsTarget, MultiBuyCustomLineItemsTarget, or CartDiscountPatternTarget are applied to the Custom Line Item.External, Cart Discounts are not considered on the Custom Line Item.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 ?listUnits of (Custom) Line Items on which the Discount is applied.
+ * + * + * @return null|PatternComponentCollection + */ + public function getTargetPattern() + { + if (is_null($this->targetPattern)) { + /** @psalm-var ?listMaximum 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