From 7539e7cf54c99d1a6886df084491d17aebaf6ccb Mon Sep 17 00:00:00 2001
From: Auto Mation
Date: Wed, 19 Aug 2020 17:24:44 +0000
Subject: [PATCH] TASK: Updating import SDK
---
lib/commercetools-base/gen.properties | 2 +-
lib/commercetools-import-tests/gen.properties | 2 +-
lib/commercetools-import/gen.properties | 2 +-
.../src/Models/Common/DiscountedPrice.php | 6 +-
.../Models/Common/DiscountedPriceBuilder.php | 14 +-
.../Models/Common/DiscountedPriceModel.php | 14 +-
.../src/Models/Common/HighPrecisionMoney.php | 27 +++
.../Common/HighPrecisionMoneyBuilder.php | 136 +++++++++++++
.../Common/HighPrecisionMoneyCollection.php | 54 +++++
.../Models/Common/HighPrecisionMoneyModel.php | 184 +++++++++++++++++
.../src/Models/Common/Money.php | 26 +--
.../src/Models/Common/MoneyBuilder.php | 25 +++
.../src/Models/Common/MoneyModel.php | 56 ++++++
.../src/Models/Common/PriceTier.php | 6 +-
.../src/Models/Common/PriceTierBuilder.php | 14 +-
.../src/Models/Common/PriceTierModel.php | 14 +-
.../src/Models/Common/TypedMoney.php | 58 ++++++
.../src/Models/Common/TypedMoneyBuilder.php | 111 ++++++++++
.../Models/Common/TypedMoneyCollection.php | 54 +++++
.../src/Models/Common/TypedMoneyModel.php | 189 ++++++++++++++++++
.../src/Models/Customfields/MoneyField.php | 8 +-
.../Models/Customfields/MoneyFieldBuilder.php | 18 +-
.../Models/Customfields/MoneyFieldModel.php | 18 +-
.../src/Models/Prices/PriceImport.php | 8 +-
.../src/Models/Prices/PriceImportBuilder.php | 18 +-
.../src/Models/Prices/PriceImportModel.php | 18 +-
.../Models/Productdrafts/PriceDraftImport.php | 8 +-
.../Productdrafts/PriceDraftImportBuilder.php | 18 +-
.../Productdrafts/PriceDraftImportModel.php | 18 +-
.../Models/Productvariants/MoneyAttribute.php | 8 +-
.../Productvariants/MoneyAttributeBuilder.php | 18 +-
.../Productvariants/MoneyAttributeModel.php | 18 +-
.../Productvariants/MoneySetAttribute.php | 8 +-
.../MoneySetAttributeBuilder.php | 10 +-
.../MoneySetAttributeModel.php | 14 +-
35 files changed, 1036 insertions(+), 166 deletions(-)
create mode 100644 lib/commercetools-import/src/Models/Common/HighPrecisionMoney.php
create mode 100644 lib/commercetools-import/src/Models/Common/HighPrecisionMoneyBuilder.php
create mode 100644 lib/commercetools-import/src/Models/Common/HighPrecisionMoneyCollection.php
create mode 100644 lib/commercetools-import/src/Models/Common/HighPrecisionMoneyModel.php
create mode 100644 lib/commercetools-import/src/Models/Common/TypedMoney.php
create mode 100644 lib/commercetools-import/src/Models/Common/TypedMoneyBuilder.php
create mode 100644 lib/commercetools-import/src/Models/Common/TypedMoneyCollection.php
create mode 100644 lib/commercetools-import/src/Models/Common/TypedMoneyModel.php
diff --git a/lib/commercetools-base/gen.properties b/lib/commercetools-base/gen.properties
index d873e13e15b..b6ac13a28c9 100644
--- a/lib/commercetools-base/gen.properties
+++ b/lib/commercetools-base/gen.properties
@@ -1 +1 @@
-hash=e731df5dde29eb223f6396f8b01f3c95930f2362
+hash=971b10acb4fa6e8cb9ea4187b4109b82725e110e
diff --git a/lib/commercetools-import-tests/gen.properties b/lib/commercetools-import-tests/gen.properties
index d873e13e15b..b6ac13a28c9 100644
--- a/lib/commercetools-import-tests/gen.properties
+++ b/lib/commercetools-import-tests/gen.properties
@@ -1 +1 @@
-hash=e731df5dde29eb223f6396f8b01f3c95930f2362
+hash=971b10acb4fa6e8cb9ea4187b4109b82725e110e
diff --git a/lib/commercetools-import/gen.properties b/lib/commercetools-import/gen.properties
index d873e13e15b..b6ac13a28c9 100644
--- a/lib/commercetools-import/gen.properties
+++ b/lib/commercetools-import/gen.properties
@@ -1 +1 @@
-hash=e731df5dde29eb223f6396f8b01f3c95930f2362
+hash=971b10acb4fa6e8cb9ea4187b4109b82725e110e
diff --git a/lib/commercetools-import/src/Models/Common/DiscountedPrice.php b/lib/commercetools-import/src/Models/Common/DiscountedPrice.php
index 03607cb2c89..b4fcf8f9181 100644
--- a/lib/commercetools-import/src/Models/Common/DiscountedPrice.php
+++ b/lib/commercetools-import/src/Models/Common/DiscountedPrice.php
@@ -17,7 +17,7 @@ interface DiscountedPrice extends JsonObject
public const FIELD_DISCOUNT = 'discount';
/**
- * @return null|Money
+ * @return null|TypedMoney
*/
public function getValue();
@@ -29,9 +29,9 @@ public function getValue();
public function getDiscount();
/**
- * @param ?Money $value
+ * @param ?TypedMoney $value
*/
- public function setValue(?Money $value): void;
+ public function setValue(?TypedMoney $value): void;
/**
* @param ?ProductDiscountKeyReference $discount
diff --git a/lib/commercetools-import/src/Models/Common/DiscountedPriceBuilder.php b/lib/commercetools-import/src/Models/Common/DiscountedPriceBuilder.php
index 2b2f8cc3fb3..1ac38af1808 100644
--- a/lib/commercetools-import/src/Models/Common/DiscountedPriceBuilder.php
+++ b/lib/commercetools-import/src/Models/Common/DiscountedPriceBuilder.php
@@ -21,7 +21,7 @@
final class DiscountedPriceBuilder implements Builder
{
/**
- * @var null|Money|MoneyBuilder
+ * @var null|TypedMoney|TypedMoneyBuilder
*/
private $value;
@@ -31,11 +31,11 @@ final class DiscountedPriceBuilder implements Builder
private $discount;
/**
- * @return null|Money
+ * @return null|TypedMoney
*/
public function getValue()
{
- return $this->value instanceof MoneyBuilder ? $this->value->build() : $this->value;
+ return $this->value instanceof TypedMoneyBuilder ? $this->value->build() : $this->value;
}
/**
@@ -49,10 +49,10 @@ public function getDiscount()
}
/**
- * @param ?Money $value
+ * @param ?TypedMoney $value
* @return $this
*/
- public function withValue(?Money $value)
+ public function withValue(?TypedMoney $value)
{
$this->value = $value;
@@ -73,7 +73,7 @@ public function withDiscount(?ProductDiscountKeyReference $discount)
/**
* @return $this
*/
- public function withValueBuilder(?MoneyBuilder $value)
+ public function withValueBuilder(?TypedMoneyBuilder $value)
{
$this->value = $value;
@@ -93,7 +93,7 @@ public function withDiscountBuilder(?ProductDiscountKeyReferenceBuilder $discoun
public function build(): DiscountedPrice
{
return new DiscountedPriceModel(
- $this->value instanceof MoneyBuilder ? $this->value->build() : $this->value,
+ $this->value instanceof TypedMoneyBuilder ? $this->value->build() : $this->value,
$this->discount instanceof ProductDiscountKeyReferenceBuilder ? $this->discount->build() : $this->discount
);
}
diff --git a/lib/commercetools-import/src/Models/Common/DiscountedPriceModel.php b/lib/commercetools-import/src/Models/Common/DiscountedPriceModel.php
index 8598f5fcfd8..5afe45f311d 100644
--- a/lib/commercetools-import/src/Models/Common/DiscountedPriceModel.php
+++ b/lib/commercetools-import/src/Models/Common/DiscountedPriceModel.php
@@ -20,7 +20,7 @@
final class DiscountedPriceModel extends JsonObjectModel implements DiscountedPrice
{
/**
- * @var ?Money
+ * @var ?TypedMoney
*/
protected $value;
@@ -34,7 +34,7 @@ final class DiscountedPriceModel extends JsonObjectModel implements DiscountedPr
* @psalm-suppress MissingParamType
*/
public function __construct(
- ?Money $value = null,
+ ?TypedMoney $value = null,
?ProductDiscountKeyReference $discount = null
) {
$this->value = $value;
@@ -42,7 +42,7 @@ public function __construct(
}
/**
- * @return null|Money
+ * @return null|TypedMoney
*/
public function getValue()
{
@@ -52,8 +52,8 @@ public function getValue()
if (is_null($data)) {
return null;
}
-
- $this->value = MoneyModel::of($data);
+ $className = TypedMoneyModel::resolveDiscriminatorClass($data);
+ $this->value = $className::of($data);
}
return $this->value;
@@ -81,9 +81,9 @@ public function getDiscount()
/**
- * @param ?Money $value
+ * @param ?TypedMoney $value
*/
- public function setValue(?Money $value): void
+ public function setValue(?TypedMoney $value): void
{
$this->value = $value;
}
diff --git a/lib/commercetools-import/src/Models/Common/HighPrecisionMoney.php b/lib/commercetools-import/src/Models/Common/HighPrecisionMoney.php
new file mode 100644
index 00000000000..6ba39166ed1
--- /dev/null
+++ b/lib/commercetools-import/src/Models/Common/HighPrecisionMoney.php
@@ -0,0 +1,27 @@
+
+ */
+final class HighPrecisionMoneyBuilder implements Builder
+{
+ /**
+ * @var ?int
+ */
+ private $fractionDigits;
+
+ /**
+ * @var ?int
+ */
+ private $centAmount;
+
+ /**
+ * @var ?string
+ */
+ private $currencyCode;
+
+ /**
+ * @var ?int
+ */
+ private $preciseAmount;
+
+ /**
+ * @return null|int
+ */
+ public function getFractionDigits()
+ {
+ return $this->fractionDigits;
+ }
+
+ /**
+ * @return null|int
+ */
+ public function getCentAmount()
+ {
+ return $this->centAmount;
+ }
+
+ /**
+ * The currency code compliant to ISO 4217.
+ *
+ * @return null|string
+ */
+ public function getCurrencyCode()
+ {
+ return $this->currencyCode;
+ }
+
+ /**
+ * @return null|int
+ */
+ public function getPreciseAmount()
+ {
+ return $this->preciseAmount;
+ }
+
+ /**
+ * @param ?int $fractionDigits
+ * @return $this
+ */
+ public function withFractionDigits(?int $fractionDigits)
+ {
+ $this->fractionDigits = $fractionDigits;
+
+ return $this;
+ }
+
+ /**
+ * @param ?int $centAmount
+ * @return $this
+ */
+ public function withCentAmount(?int $centAmount)
+ {
+ $this->centAmount = $centAmount;
+
+ return $this;
+ }
+
+ /**
+ * @param ?string $currencyCode
+ * @return $this
+ */
+ public function withCurrencyCode(?string $currencyCode)
+ {
+ $this->currencyCode = $currencyCode;
+
+ return $this;
+ }
+
+ /**
+ * @param ?int $preciseAmount
+ * @return $this
+ */
+ public function withPreciseAmount(?int $preciseAmount)
+ {
+ $this->preciseAmount = $preciseAmount;
+
+ return $this;
+ }
+
+
+ public function build(): HighPrecisionMoney
+ {
+ return new HighPrecisionMoneyModel(
+ $this->fractionDigits,
+ $this->centAmount,
+ $this->currencyCode,
+ $this->preciseAmount
+ );
+ }
+
+ public static function of(): HighPrecisionMoneyBuilder
+ {
+ return new self();
+ }
+}
diff --git a/lib/commercetools-import/src/Models/Common/HighPrecisionMoneyCollection.php b/lib/commercetools-import/src/Models/Common/HighPrecisionMoneyCollection.php
new file mode 100644
index 00000000000..9c9a82d1cf3
--- /dev/null
+++ b/lib/commercetools-import/src/Models/Common/HighPrecisionMoneyCollection.php
@@ -0,0 +1,54 @@
+
+ * @method HighPrecisionMoney current()
+ * @method HighPrecisionMoney at($offset)
+ */
+class HighPrecisionMoneyCollection extends MapperSequence
+{
+ /**
+ * @psalm-assert HighPrecisionMoney $value
+ * @psalm-param HighPrecisionMoney|stdClass $value
+ * @throws InvalidArgumentException
+ *
+ * @return HighPrecisionMoneyCollection
+ */
+ public function add($value)
+ {
+ if (!$value instanceof HighPrecisionMoney) {
+ throw new InvalidArgumentException();
+ }
+ $this->store($value);
+
+ return $this;
+ }
+
+ /**
+ * @psalm-return callable(int):?HighPrecisionMoney
+ */
+ protected function mapper()
+ {
+ return function (int $index): ?HighPrecisionMoney {
+ $data = $this->get($index);
+ if ($data instanceof stdClass) {
+ $data = HighPrecisionMoneyModel::of($data);
+ $this->set($data, $index);
+ }
+
+ return $data;
+ };
+ }
+}
diff --git a/lib/commercetools-import/src/Models/Common/HighPrecisionMoneyModel.php b/lib/commercetools-import/src/Models/Common/HighPrecisionMoneyModel.php
new file mode 100644
index 00000000000..76720a662b6
--- /dev/null
+++ b/lib/commercetools-import/src/Models/Common/HighPrecisionMoneyModel.php
@@ -0,0 +1,184 @@
+fractionDigits = $fractionDigits;
+ $this->centAmount = $centAmount;
+ $this->currencyCode = $currencyCode;
+ $this->preciseAmount = $preciseAmount;
+ $this->type = static::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;
+ }
+
+ /**
+ * @return null|int
+ */
+ public function getFractionDigits()
+ {
+ if (is_null($this->fractionDigits)) {
+ /** @psalm-var ?int $data */
+ $data = $this->raw(self::FIELD_FRACTION_DIGITS);
+ if (is_null($data)) {
+ return null;
+ }
+ $this->fractionDigits = (int) $data;
+ }
+
+ return $this->fractionDigits;
+ }
+
+ /**
+ * @return null|int
+ */
+ public function getCentAmount()
+ {
+ if (is_null($this->centAmount)) {
+ /** @psalm-var ?int $data */
+ $data = $this->raw(self::FIELD_CENT_AMOUNT);
+ if (is_null($data)) {
+ return null;
+ }
+ $this->centAmount = (int) $data;
+ }
+
+ return $this->centAmount;
+ }
+
+ /**
+ * The currency code compliant to ISO 4217.
+ *
+ * @return null|string
+ */
+ public function getCurrencyCode()
+ {
+ if (is_null($this->currencyCode)) {
+ /** @psalm-var ?string $data */
+ $data = $this->raw(self::FIELD_CURRENCY_CODE);
+ if (is_null($data)) {
+ return null;
+ }
+ $this->currencyCode = (string) $data;
+ }
+
+ return $this->currencyCode;
+ }
+
+ /**
+ * @return null|int
+ */
+ public function getPreciseAmount()
+ {
+ if (is_null($this->preciseAmount)) {
+ /** @psalm-var ?int $data */
+ $data = $this->raw(self::FIELD_PRECISE_AMOUNT);
+ if (is_null($data)) {
+ return null;
+ }
+ $this->preciseAmount = (int) $data;
+ }
+
+ return $this->preciseAmount;
+ }
+
+
+ /**
+ * @param ?int $fractionDigits
+ */
+ public function setFractionDigits(?int $fractionDigits): void
+ {
+ $this->fractionDigits = $fractionDigits;
+ }
+
+ /**
+ * @param ?int $centAmount
+ */
+ public function setCentAmount(?int $centAmount): void
+ {
+ $this->centAmount = $centAmount;
+ }
+
+ /**
+ * @param ?string $currencyCode
+ */
+ public function setCurrencyCode(?string $currencyCode): void
+ {
+ $this->currencyCode = $currencyCode;
+ }
+
+ /**
+ * @param ?int $preciseAmount
+ */
+ public function setPreciseAmount(?int $preciseAmount): void
+ {
+ $this->preciseAmount = $preciseAmount;
+ }
+}
diff --git a/lib/commercetools-import/src/Models/Common/Money.php b/lib/commercetools-import/src/Models/Common/Money.php
index f631c3f3e2b..fe4bc1eb646 100644
--- a/lib/commercetools-import/src/Models/Common/Money.php
+++ b/lib/commercetools-import/src/Models/Common/Money.php
@@ -11,30 +11,6 @@
use Commercetools\Base\DateTimeImmutableCollection;
use Commercetools\Base\JsonObject;
-interface Money extends JsonObject
+interface Money extends TypedMoney
{
- public const FIELD_CENT_AMOUNT = 'centAmount';
- public const FIELD_CURRENCY_CODE = 'currencyCode';
-
- /**
- * @return null|int
- */
- public function getCentAmount();
-
- /**
- * The currency code compliant to ISO 4217.
- *
- * @return null|string
- */
- public function getCurrencyCode();
-
- /**
- * @param ?int $centAmount
- */
- public function setCentAmount(?int $centAmount): void;
-
- /**
- * @param ?string $currencyCode
- */
- public function setCurrencyCode(?string $currencyCode): void;
}
diff --git a/lib/commercetools-import/src/Models/Common/MoneyBuilder.php b/lib/commercetools-import/src/Models/Common/MoneyBuilder.php
index d0bf90b7c48..0f57d64a3c5 100644
--- a/lib/commercetools-import/src/Models/Common/MoneyBuilder.php
+++ b/lib/commercetools-import/src/Models/Common/MoneyBuilder.php
@@ -20,6 +20,11 @@
*/
final class MoneyBuilder implements Builder
{
+ /**
+ * @var ?int
+ */
+ private $fractionDigits;
+
/**
* @var ?int
*/
@@ -30,6 +35,14 @@ final class MoneyBuilder implements Builder
*/
private $currencyCode;
+ /**
+ * @return null|int
+ */
+ public function getFractionDigits()
+ {
+ return $this->fractionDigits;
+ }
+
/**
* @return null|int
*/
@@ -48,6 +61,17 @@ public function getCurrencyCode()
return $this->currencyCode;
}
+ /**
+ * @param ?int $fractionDigits
+ * @return $this
+ */
+ public function withFractionDigits(?int $fractionDigits)
+ {
+ $this->fractionDigits = $fractionDigits;
+
+ return $this;
+ }
+
/**
* @param ?int $centAmount
* @return $this
@@ -74,6 +98,7 @@ public function withCurrencyCode(?string $currencyCode)
public function build(): Money
{
return new MoneyModel(
+ $this->fractionDigits,
$this->centAmount,
$this->currencyCode
);
diff --git a/lib/commercetools-import/src/Models/Common/MoneyModel.php b/lib/commercetools-import/src/Models/Common/MoneyModel.php
index 0834f684004..404e767c527 100644
--- a/lib/commercetools-import/src/Models/Common/MoneyModel.php
+++ b/lib/commercetools-import/src/Models/Common/MoneyModel.php
@@ -19,6 +19,17 @@
*/
final class MoneyModel extends JsonObjectModel implements Money
{
+ public const DISCRIMINATOR_VALUE = 'centPrecision';
+ /**
+ * @var ?string
+ */
+ protected $type;
+
+ /**
+ * @var ?int
+ */
+ protected $fractionDigits;
+
/**
* @var ?int
*/
@@ -34,11 +45,48 @@ final class MoneyModel extends JsonObjectModel implements Money
* @psalm-suppress MissingParamType
*/
public function __construct(
+ ?int $fractionDigits = null,
?int $centAmount = null,
?string $currencyCode = null
) {
+ $this->fractionDigits = $fractionDigits;
$this->centAmount = $centAmount;
$this->currencyCode = $currencyCode;
+ $this->type = static::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;
+ }
+
+ /**
+ * @return null|int
+ */
+ public function getFractionDigits()
+ {
+ if (is_null($this->fractionDigits)) {
+ /** @psalm-var ?int $data */
+ $data = $this->raw(self::FIELD_FRACTION_DIGITS);
+ if (is_null($data)) {
+ return null;
+ }
+ $this->fractionDigits = (int) $data;
+ }
+
+ return $this->fractionDigits;
}
/**
@@ -78,6 +126,14 @@ public function getCurrencyCode()
}
+ /**
+ * @param ?int $fractionDigits
+ */
+ public function setFractionDigits(?int $fractionDigits): void
+ {
+ $this->fractionDigits = $fractionDigits;
+ }
+
/**
* @param ?int $centAmount
*/
diff --git a/lib/commercetools-import/src/Models/Common/PriceTier.php b/lib/commercetools-import/src/Models/Common/PriceTier.php
index 99a5dda511a..63f7fe69c93 100644
--- a/lib/commercetools-import/src/Models/Common/PriceTier.php
+++ b/lib/commercetools-import/src/Models/Common/PriceTier.php
@@ -26,7 +26,7 @@ public function getMinimumQuantity();
/**
* The currency of a price tier is always the same as the currency of the base Price.
*
- * @return null|Money
+ * @return null|TypedMoney
*/
public function getValue();
@@ -36,7 +36,7 @@ public function getValue();
public function setMinimumQuantity(?int $minimumQuantity): void;
/**
- * @param ?Money $value
+ * @param ?TypedMoney $value
*/
- public function setValue(?Money $value): void;
+ public function setValue(?TypedMoney $value): void;
}
diff --git a/lib/commercetools-import/src/Models/Common/PriceTierBuilder.php b/lib/commercetools-import/src/Models/Common/PriceTierBuilder.php
index c695cce78a7..96788513507 100644
--- a/lib/commercetools-import/src/Models/Common/PriceTierBuilder.php
+++ b/lib/commercetools-import/src/Models/Common/PriceTierBuilder.php
@@ -26,7 +26,7 @@ final class PriceTierBuilder implements Builder
private $minimumQuantity;
/**
- * @var null|Money|MoneyBuilder
+ * @var null|TypedMoney|TypedMoneyBuilder
*/
private $value;
@@ -43,11 +43,11 @@ public function getMinimumQuantity()
/**
* The currency of a price tier is always the same as the currency of the base Price.
*
- * @return null|Money
+ * @return null|TypedMoney
*/
public function getValue()
{
- return $this->value instanceof MoneyBuilder ? $this->value->build() : $this->value;
+ return $this->value instanceof TypedMoneyBuilder ? $this->value->build() : $this->value;
}
/**
@@ -62,10 +62,10 @@ public function withMinimumQuantity(?int $minimumQuantity)
}
/**
- * @param ?Money $value
+ * @param ?TypedMoney $value
* @return $this
*/
- public function withValue(?Money $value)
+ public function withValue(?TypedMoney $value)
{
$this->value = $value;
@@ -75,7 +75,7 @@ public function withValue(?Money $value)
/**
* @return $this
*/
- public function withValueBuilder(?MoneyBuilder $value)
+ public function withValueBuilder(?TypedMoneyBuilder $value)
{
$this->value = $value;
@@ -86,7 +86,7 @@ public function build(): PriceTier
{
return new PriceTierModel(
$this->minimumQuantity,
- $this->value instanceof MoneyBuilder ? $this->value->build() : $this->value
+ $this->value instanceof TypedMoneyBuilder ? $this->value->build() : $this->value
);
}
diff --git a/lib/commercetools-import/src/Models/Common/PriceTierModel.php b/lib/commercetools-import/src/Models/Common/PriceTierModel.php
index dabb446768a..d87ac6befeb 100644
--- a/lib/commercetools-import/src/Models/Common/PriceTierModel.php
+++ b/lib/commercetools-import/src/Models/Common/PriceTierModel.php
@@ -25,7 +25,7 @@ final class PriceTierModel extends JsonObjectModel implements PriceTier
protected $minimumQuantity;
/**
- * @var ?Money
+ * @var ?TypedMoney
*/
protected $value;
@@ -35,7 +35,7 @@ final class PriceTierModel extends JsonObjectModel implements PriceTier
*/
public function __construct(
?int $minimumQuantity = null,
- ?Money $value = null
+ ?TypedMoney $value = null
) {
$this->minimumQuantity = $minimumQuantity;
$this->value = $value;
@@ -63,7 +63,7 @@ public function getMinimumQuantity()
/**
* The currency of a price tier is always the same as the currency of the base Price.
*
- * @return null|Money
+ * @return null|TypedMoney
*/
public function getValue()
{
@@ -73,8 +73,8 @@ public function getValue()
if (is_null($data)) {
return null;
}
-
- $this->value = MoneyModel::of($data);
+ $className = TypedMoneyModel::resolveDiscriminatorClass($data);
+ $this->value = $className::of($data);
}
return $this->value;
@@ -90,9 +90,9 @@ public function setMinimumQuantity(?int $minimumQuantity): void
}
/**
- * @param ?Money $value
+ * @param ?TypedMoney $value
*/
- public function setValue(?Money $value): void
+ public function setValue(?TypedMoney $value): void
{
$this->value = $value;
}
diff --git a/lib/commercetools-import/src/Models/Common/TypedMoney.php b/lib/commercetools-import/src/Models/Common/TypedMoney.php
new file mode 100644
index 00000000000..92c80ccab69
--- /dev/null
+++ b/lib/commercetools-import/src/Models/Common/TypedMoney.php
@@ -0,0 +1,58 @@
+The currency code compliant to ISO 4217.
+ *
+ * @return null|string
+ */
+ public function getCurrencyCode();
+
+ /**
+ * @param ?int $fractionDigits
+ */
+ public function setFractionDigits(?int $fractionDigits): void;
+
+ /**
+ * @param ?int $centAmount
+ */
+ public function setCentAmount(?int $centAmount): void;
+
+ /**
+ * @param ?string $currencyCode
+ */
+ public function setCurrencyCode(?string $currencyCode): void;
+}
diff --git a/lib/commercetools-import/src/Models/Common/TypedMoneyBuilder.php b/lib/commercetools-import/src/Models/Common/TypedMoneyBuilder.php
new file mode 100644
index 00000000000..82f3b4d2204
--- /dev/null
+++ b/lib/commercetools-import/src/Models/Common/TypedMoneyBuilder.php
@@ -0,0 +1,111 @@
+
+ */
+final class TypedMoneyBuilder implements Builder
+{
+ /**
+ * @var ?int
+ */
+ private $fractionDigits;
+
+ /**
+ * @var ?int
+ */
+ private $centAmount;
+
+ /**
+ * @var ?string
+ */
+ private $currencyCode;
+
+ /**
+ * @return null|int
+ */
+ public function getFractionDigits()
+ {
+ return $this->fractionDigits;
+ }
+
+ /**
+ * @return null|int
+ */
+ public function getCentAmount()
+ {
+ return $this->centAmount;
+ }
+
+ /**
+ * The currency code compliant to ISO 4217.
+ *
+ * @return null|string
+ */
+ public function getCurrencyCode()
+ {
+ return $this->currencyCode;
+ }
+
+ /**
+ * @param ?int $fractionDigits
+ * @return $this
+ */
+ public function withFractionDigits(?int $fractionDigits)
+ {
+ $this->fractionDigits = $fractionDigits;
+
+ return $this;
+ }
+
+ /**
+ * @param ?int $centAmount
+ * @return $this
+ */
+ public function withCentAmount(?int $centAmount)
+ {
+ $this->centAmount = $centAmount;
+
+ return $this;
+ }
+
+ /**
+ * @param ?string $currencyCode
+ * @return $this
+ */
+ public function withCurrencyCode(?string $currencyCode)
+ {
+ $this->currencyCode = $currencyCode;
+
+ return $this;
+ }
+
+
+ public function build(): TypedMoney
+ {
+ return new TypedMoneyModel(
+ $this->fractionDigits,
+ $this->centAmount,
+ $this->currencyCode
+ );
+ }
+
+ public static function of(): TypedMoneyBuilder
+ {
+ return new self();
+ }
+}
diff --git a/lib/commercetools-import/src/Models/Common/TypedMoneyCollection.php b/lib/commercetools-import/src/Models/Common/TypedMoneyCollection.php
new file mode 100644
index 00000000000..0ab9970f83f
--- /dev/null
+++ b/lib/commercetools-import/src/Models/Common/TypedMoneyCollection.php
@@ -0,0 +1,54 @@
+
+ * @method TypedMoney current()
+ * @method TypedMoney at($offset)
+ */
+class TypedMoneyCollection extends MapperSequence
+{
+ /**
+ * @psalm-assert TypedMoney $value
+ * @psalm-param TypedMoney|stdClass $value
+ * @throws InvalidArgumentException
+ *
+ * @return TypedMoneyCollection
+ */
+ public function add($value)
+ {
+ if (!$value instanceof TypedMoney) {
+ throw new InvalidArgumentException();
+ }
+ $this->store($value);
+
+ return $this;
+ }
+
+ /**
+ * @psalm-return callable(int):?TypedMoney
+ */
+ protected function mapper()
+ {
+ return function (int $index): ?TypedMoney {
+ $data = $this->get($index);
+ if ($data instanceof stdClass) {
+ $data = TypedMoneyModel::of($data);
+ $this->set($data, $index);
+ }
+
+ return $data;
+ };
+ }
+}
diff --git a/lib/commercetools-import/src/Models/Common/TypedMoneyModel.php b/lib/commercetools-import/src/Models/Common/TypedMoneyModel.php
new file mode 100644
index 00000000000..63b04386af0
--- /dev/null
+++ b/lib/commercetools-import/src/Models/Common/TypedMoneyModel.php
@@ -0,0 +1,189 @@
+ >
+ *
+ */
+ private static $discriminatorClasses = [
+ 'centPrecision' => MoneyModel::class,
+ 'highPrecision' => HighPrecisionMoneyModel::class,
+ ];
+
+ /**
+ * @psalm-suppress MissingParamType
+ */
+ public function __construct(
+ ?int $fractionDigits = null,
+ ?int $centAmount = null,
+ ?string $currencyCode = null
+ ) {
+ $this->fractionDigits = $fractionDigits;
+ $this->centAmount = $centAmount;
+ $this->currencyCode = $currencyCode;
+ $this->type = static::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;
+ }
+
+ /**
+ * @return null|int
+ */
+ public function getFractionDigits()
+ {
+ if (is_null($this->fractionDigits)) {
+ /** @psalm-var ?int $data */
+ $data = $this->raw(self::FIELD_FRACTION_DIGITS);
+ if (is_null($data)) {
+ return null;
+ }
+ $this->fractionDigits = (int) $data;
+ }
+
+ return $this->fractionDigits;
+ }
+
+ /**
+ * @return null|int
+ */
+ public function getCentAmount()
+ {
+ if (is_null($this->centAmount)) {
+ /** @psalm-var ?int $data */
+ $data = $this->raw(self::FIELD_CENT_AMOUNT);
+ if (is_null($data)) {
+ return null;
+ }
+ $this->centAmount = (int) $data;
+ }
+
+ return $this->centAmount;
+ }
+
+ /**
+ * The currency code compliant to ISO 4217.
+ *
+ * @return null|string
+ */
+ public function getCurrencyCode()
+ {
+ if (is_null($this->currencyCode)) {
+ /** @psalm-var ?string $data */
+ $data = $this->raw(self::FIELD_CURRENCY_CODE);
+ if (is_null($data)) {
+ return null;
+ }
+ $this->currencyCode = (string) $data;
+ }
+
+ return $this->currencyCode;
+ }
+
+
+ /**
+ * @param ?int $fractionDigits
+ */
+ public function setFractionDigits(?int $fractionDigits): void
+ {
+ $this->fractionDigits = $fractionDigits;
+ }
+
+ /**
+ * @param ?int $centAmount
+ */
+ public function setCentAmount(?int $centAmount): void
+ {
+ $this->centAmount = $centAmount;
+ }
+
+ /**
+ * @param ?string $currencyCode
+ */
+ public function setCurrencyCode(?string $currencyCode): void
+ {
+ $this->currencyCode = $currencyCode;
+ }
+
+
+
+ /**
+ * @psalm-param stdClass|array $value
+ * @psalm-return class-string
+ */
+ public static function resolveDiscriminatorClass($value): string
+ {
+ $fieldName = TypedMoney::DISCRIMINATOR_FIELD;
+ if (is_object($value) && isset($value->$fieldName)) {
+ /** @psalm-var string $discriminatorValue */
+ $discriminatorValue = $value->$fieldName;
+ if (isset(static::$discriminatorClasses[$discriminatorValue])) {
+ return static::$discriminatorClasses[$discriminatorValue];
+ }
+ }
+ if (is_array($value) && isset($value[$fieldName])) {
+ /** @psalm-var string $discriminatorValue */
+ $discriminatorValue = $value[$fieldName];
+ if (isset(static::$discriminatorClasses[$discriminatorValue])) {
+ return static::$discriminatorClasses[$discriminatorValue];
+ }
+ }
+
+ /** @psalm-var class-string */
+ $type = TypedMoneyModel::class;
+ return $type;
+ }
+}
diff --git a/lib/commercetools-import/src/Models/Customfields/MoneyField.php b/lib/commercetools-import/src/Models/Customfields/MoneyField.php
index 2977525e524..a0f56e43c76 100644
--- a/lib/commercetools-import/src/Models/Customfields/MoneyField.php
+++ b/lib/commercetools-import/src/Models/Customfields/MoneyField.php
@@ -10,19 +10,19 @@
use Commercetools\Base\DateTimeImmutableCollection;
use Commercetools\Base\JsonObject;
-use Commercetools\Import\Models\Common\Money;
+use Commercetools\Import\Models\Common\TypedMoney;
interface MoneyField extends CustomField
{
public const FIELD_VALUE = 'value';
/**
- * @return null|Money
+ * @return null|TypedMoney
*/
public function getValue();
/**
- * @param ?Money $value
+ * @param ?TypedMoney $value
*/
- public function setValue(?Money $value): void;
+ public function setValue(?TypedMoney $value): void;
}
diff --git a/lib/commercetools-import/src/Models/Customfields/MoneyFieldBuilder.php b/lib/commercetools-import/src/Models/Customfields/MoneyFieldBuilder.php
index 94b9e495623..965bfa7e7cb 100644
--- a/lib/commercetools-import/src/Models/Customfields/MoneyFieldBuilder.php
+++ b/lib/commercetools-import/src/Models/Customfields/MoneyFieldBuilder.php
@@ -13,8 +13,8 @@
use Commercetools\Base\JsonObject;
use Commercetools\Base\JsonObjectModel;
use Commercetools\Base\MapperFactory;
-use Commercetools\Import\Models\Common\Money;
-use Commercetools\Import\Models\Common\MoneyBuilder;
+use Commercetools\Import\Models\Common\TypedMoney;
+use Commercetools\Import\Models\Common\TypedMoneyBuilder;
use stdClass;
/**
@@ -23,23 +23,23 @@
final class MoneyFieldBuilder implements Builder
{
/**
- * @var null|Money|MoneyBuilder
+ * @var null|TypedMoney|TypedMoneyBuilder
*/
private $value;
/**
- * @return null|Money
+ * @return null|TypedMoney
*/
public function getValue()
{
- return $this->value instanceof MoneyBuilder ? $this->value->build() : $this->value;
+ return $this->value instanceof TypedMoneyBuilder ? $this->value->build() : $this->value;
}
/**
- * @param ?Money $value
+ * @param ?TypedMoney $value
* @return $this
*/
- public function withValue(?Money $value)
+ public function withValue(?TypedMoney $value)
{
$this->value = $value;
@@ -49,7 +49,7 @@ public function withValue(?Money $value)
/**
* @return $this
*/
- public function withValueBuilder(?MoneyBuilder $value)
+ public function withValueBuilder(?TypedMoneyBuilder $value)
{
$this->value = $value;
@@ -59,7 +59,7 @@ public function withValueBuilder(?MoneyBuilder $value)
public function build(): MoneyField
{
return new MoneyFieldModel(
- $this->value instanceof MoneyBuilder ? $this->value->build() : $this->value
+ $this->value instanceof TypedMoneyBuilder ? $this->value->build() : $this->value
);
}
diff --git a/lib/commercetools-import/src/Models/Customfields/MoneyFieldModel.php b/lib/commercetools-import/src/Models/Customfields/MoneyFieldModel.php
index 056b125e320..eaeaabf4a34 100644
--- a/lib/commercetools-import/src/Models/Customfields/MoneyFieldModel.php
+++ b/lib/commercetools-import/src/Models/Customfields/MoneyFieldModel.php
@@ -12,8 +12,8 @@
use Commercetools\Base\JsonObject;
use Commercetools\Base\JsonObjectModel;
use Commercetools\Base\MapperFactory;
-use Commercetools\Import\Models\Common\Money;
-use Commercetools\Import\Models\Common\MoneyModel;
+use Commercetools\Import\Models\Common\TypedMoney;
+use Commercetools\Import\Models\Common\TypedMoneyModel;
use stdClass;
/**
@@ -28,7 +28,7 @@ final class MoneyFieldModel extends JsonObjectModel implements MoneyField
protected $type;
/**
- * @var ?Money
+ * @var ?TypedMoney
*/
protected $value;
@@ -37,7 +37,7 @@ final class MoneyFieldModel extends JsonObjectModel implements MoneyField
* @psalm-suppress MissingParamType
*/
public function __construct(
- ?Money $value = null
+ ?TypedMoney $value = null
) {
$this->value = $value;
$this->type = static::DISCRIMINATOR_VALUE;
@@ -63,7 +63,7 @@ public function getType()
}
/**
- * @return null|Money
+ * @return null|TypedMoney
*/
public function getValue()
{
@@ -73,8 +73,8 @@ public function getValue()
if (is_null($data)) {
return null;
}
-
- $this->value = MoneyModel::of($data);
+ $className = TypedMoneyModel::resolveDiscriminatorClass($data);
+ $this->value = $className::of($data);
}
return $this->value;
@@ -82,9 +82,9 @@ public function getValue()
/**
- * @param ?Money $value
+ * @param ?TypedMoney $value
*/
- public function setValue(?Money $value): void
+ public function setValue(?TypedMoney $value): void
{
$this->value = $value;
}
diff --git a/lib/commercetools-import/src/Models/Prices/PriceImport.php b/lib/commercetools-import/src/Models/Prices/PriceImport.php
index 4b2bb8d3e46..9710bcdd326 100644
--- a/lib/commercetools-import/src/Models/Prices/PriceImport.php
+++ b/lib/commercetools-import/src/Models/Prices/PriceImport.php
@@ -14,10 +14,10 @@
use Commercetools\Import\Models\Common\CustomerGroupKeyReference;
use Commercetools\Import\Models\Common\DiscountedPrice;
use Commercetools\Import\Models\Common\ImportResource;
-use Commercetools\Import\Models\Common\Money;
use Commercetools\Import\Models\Common\PriceTierCollection;
use Commercetools\Import\Models\Common\ProductKeyReference;
use Commercetools\Import\Models\Common\ProductVariantKeyReference;
+use Commercetools\Import\Models\Common\TypedMoney;
use DateTimeImmutable;
interface PriceImport extends ImportResource
@@ -38,7 +38,7 @@ interface PriceImport extends ImportResource
* Maps to Price.value
.
* The Import API only supports centPrecision
prices.
*
- * @return null|Money
+ * @return null|TypedMoney
*/
public function getValue();
@@ -125,9 +125,9 @@ public function getProductVariant();
public function getProduct();
/**
- * @param ?Money $value
+ * @param ?TypedMoney $value
*/
- public function setValue(?Money $value): void;
+ public function setValue(?TypedMoney $value): void;
/**
* @param ?string $country
diff --git a/lib/commercetools-import/src/Models/Prices/PriceImportBuilder.php b/lib/commercetools-import/src/Models/Prices/PriceImportBuilder.php
index 3e22c15029a..2039e797db4 100644
--- a/lib/commercetools-import/src/Models/Prices/PriceImportBuilder.php
+++ b/lib/commercetools-import/src/Models/Prices/PriceImportBuilder.php
@@ -21,13 +21,13 @@
use Commercetools\Import\Models\Common\DiscountedPriceBuilder;
use Commercetools\Import\Models\Common\ImportResource;
use Commercetools\Import\Models\Common\ImportResourceBuilder;
-use Commercetools\Import\Models\Common\Money;
-use Commercetools\Import\Models\Common\MoneyBuilder;
use Commercetools\Import\Models\Common\PriceTierCollection;
use Commercetools\Import\Models\Common\ProductKeyReference;
use Commercetools\Import\Models\Common\ProductKeyReferenceBuilder;
use Commercetools\Import\Models\Common\ProductVariantKeyReference;
use Commercetools\Import\Models\Common\ProductVariantKeyReferenceBuilder;
+use Commercetools\Import\Models\Common\TypedMoney;
+use Commercetools\Import\Models\Common\TypedMoneyBuilder;
use DateTimeImmutable;
use stdClass;
@@ -42,7 +42,7 @@ final class PriceImportBuilder implements Builder
private $key;
/**
- * @var null|Money|MoneyBuilder
+ * @var null|TypedMoney|TypedMoneyBuilder
*/
private $value;
@@ -108,11 +108,11 @@ public function getKey()
* Maps to Price.value
.
* The Import API only supports centPrecision
prices.
*
- * @return null|Money
+ * @return null|TypedMoney
*/
public function getValue()
{
- return $this->value instanceof MoneyBuilder ? $this->value->build() : $this->value;
+ return $this->value instanceof TypedMoneyBuilder ? $this->value->build() : $this->value;
}
/**
@@ -239,10 +239,10 @@ public function withKey(?string $key)
}
/**
- * @param ?Money $value
+ * @param ?TypedMoney $value
* @return $this
*/
- public function withValue(?Money $value)
+ public function withValue(?TypedMoney $value)
{
$this->value = $value;
@@ -362,7 +362,7 @@ public function withProduct(?ProductKeyReference $product)
/**
* @return $this
*/
- public function withValueBuilder(?MoneyBuilder $value)
+ public function withValueBuilder(?TypedMoneyBuilder $value)
{
$this->value = $value;
@@ -423,7 +423,7 @@ public function build(): PriceImport
{
return new PriceImportModel(
$this->key,
- $this->value instanceof MoneyBuilder ? $this->value->build() : $this->value,
+ $this->value instanceof TypedMoneyBuilder ? $this->value->build() : $this->value,
$this->country,
$this->validFrom,
$this->validUntil,
diff --git a/lib/commercetools-import/src/Models/Prices/PriceImportModel.php b/lib/commercetools-import/src/Models/Prices/PriceImportModel.php
index 33f0c0c6db1..17927584e72 100644
--- a/lib/commercetools-import/src/Models/Prices/PriceImportModel.php
+++ b/lib/commercetools-import/src/Models/Prices/PriceImportModel.php
@@ -20,13 +20,13 @@
use Commercetools\Import\Models\Common\DiscountedPriceModel;
use Commercetools\Import\Models\Common\ImportResource;
use Commercetools\Import\Models\Common\ImportResourceModel;
-use Commercetools\Import\Models\Common\Money;
-use Commercetools\Import\Models\Common\MoneyModel;
use Commercetools\Import\Models\Common\PriceTierCollection;
use Commercetools\Import\Models\Common\ProductKeyReference;
use Commercetools\Import\Models\Common\ProductKeyReferenceModel;
use Commercetools\Import\Models\Common\ProductVariantKeyReference;
use Commercetools\Import\Models\Common\ProductVariantKeyReferenceModel;
+use Commercetools\Import\Models\Common\TypedMoney;
+use Commercetools\Import\Models\Common\TypedMoneyModel;
use DateTimeImmutable;
use stdClass;
@@ -41,7 +41,7 @@ final class PriceImportModel extends JsonObjectModel implements PriceImport
protected $key;
/**
- * @var ?Money
+ * @var ?TypedMoney
*/
protected $value;
@@ -101,7 +101,7 @@ final class PriceImportModel extends JsonObjectModel implements PriceImport
*/
public function __construct(
?string $key = null,
- ?Money $value = null,
+ ?TypedMoney $value = null,
?string $country = null,
?DateTimeImmutable $validFrom = null,
?DateTimeImmutable $validUntil = null,
@@ -148,7 +148,7 @@ public function getKey()
* Maps to Price.value
.
* The Import API only supports centPrecision
prices.
*
- * @return null|Money
+ * @return null|TypedMoney
*/
public function getValue()
{
@@ -158,8 +158,8 @@ public function getValue()
if (is_null($data)) {
return null;
}
-
- $this->value = MoneyModel::of($data);
+ $className = TypedMoneyModel::resolveDiscriminatorClass($data);
+ $this->value = $className::of($data);
}
return $this->value;
@@ -390,9 +390,9 @@ public function setKey(?string $key): void
}
/**
- * @param ?Money $value
+ * @param ?TypedMoney $value
*/
- public function setValue(?Money $value): void
+ public function setValue(?TypedMoney $value): void
{
$this->value = $value;
}
diff --git a/lib/commercetools-import/src/Models/Productdrafts/PriceDraftImport.php b/lib/commercetools-import/src/Models/Productdrafts/PriceDraftImport.php
index cfbe22a1166..e1996d085f4 100644
--- a/lib/commercetools-import/src/Models/Productdrafts/PriceDraftImport.php
+++ b/lib/commercetools-import/src/Models/Productdrafts/PriceDraftImport.php
@@ -13,8 +13,8 @@
use Commercetools\Import\Models\Common\ChannelKeyReference;
use Commercetools\Import\Models\Common\CustomerGroupKeyReference;
use Commercetools\Import\Models\Common\DiscountedPrice;
-use Commercetools\Import\Models\Common\Money;
use Commercetools\Import\Models\Common\PriceTierCollection;
+use Commercetools\Import\Models\Common\TypedMoney;
use Commercetools\Import\Models\Customfields\Custom;
use DateTimeImmutable;
@@ -31,7 +31,7 @@ interface PriceDraftImport extends JsonObject
public const FIELD_TIERS = 'tiers';
/**
- * @return null|Money
+ * @return null|TypedMoney
*/
public function getValue();
@@ -88,9 +88,9 @@ public function getDiscounted();
public function getTiers();
/**
- * @param ?Money $value
+ * @param ?TypedMoney $value
*/
- public function setValue(?Money $value): void;
+ public function setValue(?TypedMoney $value): void;
/**
* @param ?string $country
diff --git a/lib/commercetools-import/src/Models/Productdrafts/PriceDraftImportBuilder.php b/lib/commercetools-import/src/Models/Productdrafts/PriceDraftImportBuilder.php
index 82e4d8e894c..1c71840c706 100644
--- a/lib/commercetools-import/src/Models/Productdrafts/PriceDraftImportBuilder.php
+++ b/lib/commercetools-import/src/Models/Productdrafts/PriceDraftImportBuilder.php
@@ -19,9 +19,9 @@
use Commercetools\Import\Models\Common\CustomerGroupKeyReferenceBuilder;
use Commercetools\Import\Models\Common\DiscountedPrice;
use Commercetools\Import\Models\Common\DiscountedPriceBuilder;
-use Commercetools\Import\Models\Common\Money;
-use Commercetools\Import\Models\Common\MoneyBuilder;
use Commercetools\Import\Models\Common\PriceTierCollection;
+use Commercetools\Import\Models\Common\TypedMoney;
+use Commercetools\Import\Models\Common\TypedMoneyBuilder;
use Commercetools\Import\Models\Customfields\Custom;
use Commercetools\Import\Models\Customfields\CustomBuilder;
use DateTimeImmutable;
@@ -33,7 +33,7 @@
final class PriceDraftImportBuilder implements Builder
{
/**
- * @var null|Money|MoneyBuilder
+ * @var null|TypedMoney|TypedMoneyBuilder
*/
private $value;
@@ -78,11 +78,11 @@ final class PriceDraftImportBuilder implements Builder
private $tiers;
/**
- * @return null|Money
+ * @return null|TypedMoney
*/
public function getValue()
{
- return $this->value instanceof MoneyBuilder ? $this->value->build() : $this->value;
+ return $this->value instanceof TypedMoneyBuilder ? $this->value->build() : $this->value;
}
/**
@@ -162,10 +162,10 @@ public function getTiers()
}
/**
- * @param ?Money $value
+ * @param ?TypedMoney $value
* @return $this
*/
- public function withValue(?Money $value)
+ public function withValue(?TypedMoney $value)
{
$this->value = $value;
@@ -263,7 +263,7 @@ public function withTiers(?PriceTierCollection $tiers)
/**
* @return $this
*/
- public function withValueBuilder(?MoneyBuilder $value)
+ public function withValueBuilder(?TypedMoneyBuilder $value)
{
$this->value = $value;
@@ -313,7 +313,7 @@ public function withDiscountedBuilder(?DiscountedPriceBuilder $discounted)
public function build(): PriceDraftImport
{
return new PriceDraftImportModel(
- $this->value instanceof MoneyBuilder ? $this->value->build() : $this->value,
+ $this->value instanceof TypedMoneyBuilder ? $this->value->build() : $this->value,
$this->country,
$this->customerGroup instanceof CustomerGroupKeyReferenceBuilder ? $this->customerGroup->build() : $this->customerGroup,
$this->channel instanceof ChannelKeyReferenceBuilder ? $this->channel->build() : $this->channel,
diff --git a/lib/commercetools-import/src/Models/Productdrafts/PriceDraftImportModel.php b/lib/commercetools-import/src/Models/Productdrafts/PriceDraftImportModel.php
index f1672dd8606..5102b101b04 100644
--- a/lib/commercetools-import/src/Models/Productdrafts/PriceDraftImportModel.php
+++ b/lib/commercetools-import/src/Models/Productdrafts/PriceDraftImportModel.php
@@ -18,9 +18,9 @@
use Commercetools\Import\Models\Common\CustomerGroupKeyReferenceModel;
use Commercetools\Import\Models\Common\DiscountedPrice;
use Commercetools\Import\Models\Common\DiscountedPriceModel;
-use Commercetools\Import\Models\Common\Money;
-use Commercetools\Import\Models\Common\MoneyModel;
use Commercetools\Import\Models\Common\PriceTierCollection;
+use Commercetools\Import\Models\Common\TypedMoney;
+use Commercetools\Import\Models\Common\TypedMoneyModel;
use Commercetools\Import\Models\Customfields\Custom;
use Commercetools\Import\Models\Customfields\CustomModel;
use DateTimeImmutable;
@@ -32,7 +32,7 @@
final class PriceDraftImportModel extends JsonObjectModel implements PriceDraftImport
{
/**
- * @var ?Money
+ * @var ?TypedMoney
*/
protected $value;
@@ -81,7 +81,7 @@ final class PriceDraftImportModel extends JsonObjectModel implements PriceDraftI
* @psalm-suppress MissingParamType
*/
public function __construct(
- ?Money $value = null,
+ ?TypedMoney $value = null,
?string $country = null,
?CustomerGroupKeyReference $customerGroup = null,
?ChannelKeyReference $channel = null,
@@ -103,7 +103,7 @@ public function __construct(
}
/**
- * @return null|Money
+ * @return null|TypedMoney
*/
public function getValue()
{
@@ -113,8 +113,8 @@ public function getValue()
if (is_null($data)) {
return null;
}
-
- $this->value = MoneyModel::of($data);
+ $className = TypedMoneyModel::resolveDiscriminatorClass($data);
+ $this->value = $className::of($data);
}
return $this->value;
@@ -282,9 +282,9 @@ public function getTiers()
/**
- * @param ?Money $value
+ * @param ?TypedMoney $value
*/
- public function setValue(?Money $value): void
+ public function setValue(?TypedMoney $value): void
{
$this->value = $value;
}
diff --git a/lib/commercetools-import/src/Models/Productvariants/MoneyAttribute.php b/lib/commercetools-import/src/Models/Productvariants/MoneyAttribute.php
index f32bac4e6ca..c3c7e2870ef 100644
--- a/lib/commercetools-import/src/Models/Productvariants/MoneyAttribute.php
+++ b/lib/commercetools-import/src/Models/Productvariants/MoneyAttribute.php
@@ -10,19 +10,19 @@
use Commercetools\Base\DateTimeImmutableCollection;
use Commercetools\Base\JsonObject;
-use Commercetools\Import\Models\Common\Money;
+use Commercetools\Import\Models\Common\TypedMoney;
interface MoneyAttribute extends Attribute
{
public const FIELD_VALUE = 'value';
/**
- * @return null|Money
+ * @return null|TypedMoney
*/
public function getValue();
/**
- * @param ?Money $value
+ * @param ?TypedMoney $value
*/
- public function setValue(?Money $value): void;
+ public function setValue(?TypedMoney $value): void;
}
diff --git a/lib/commercetools-import/src/Models/Productvariants/MoneyAttributeBuilder.php b/lib/commercetools-import/src/Models/Productvariants/MoneyAttributeBuilder.php
index c7a6f503e0f..e3dd67d696d 100644
--- a/lib/commercetools-import/src/Models/Productvariants/MoneyAttributeBuilder.php
+++ b/lib/commercetools-import/src/Models/Productvariants/MoneyAttributeBuilder.php
@@ -13,8 +13,8 @@
use Commercetools\Base\JsonObject;
use Commercetools\Base\JsonObjectModel;
use Commercetools\Base\MapperFactory;
-use Commercetools\Import\Models\Common\Money;
-use Commercetools\Import\Models\Common\MoneyBuilder;
+use Commercetools\Import\Models\Common\TypedMoney;
+use Commercetools\Import\Models\Common\TypedMoneyBuilder;
use stdClass;
/**
@@ -28,7 +28,7 @@ final class MoneyAttributeBuilder implements Builder
private $name;
/**
- * @var null|Money|MoneyBuilder
+ * @var null|TypedMoney|TypedMoneyBuilder
*/
private $value;
@@ -45,11 +45,11 @@ public function getName()
}
/**
- * @return null|Money
+ * @return null|TypedMoney
*/
public function getValue()
{
- return $this->value instanceof MoneyBuilder ? $this->value->build() : $this->value;
+ return $this->value instanceof TypedMoneyBuilder ? $this->value->build() : $this->value;
}
/**
@@ -64,10 +64,10 @@ public function withName(?string $name)
}
/**
- * @param ?Money $value
+ * @param ?TypedMoney $value
* @return $this
*/
- public function withValue(?Money $value)
+ public function withValue(?TypedMoney $value)
{
$this->value = $value;
@@ -77,7 +77,7 @@ public function withValue(?Money $value)
/**
* @return $this
*/
- public function withValueBuilder(?MoneyBuilder $value)
+ public function withValueBuilder(?TypedMoneyBuilder $value)
{
$this->value = $value;
@@ -88,7 +88,7 @@ public function build(): MoneyAttribute
{
return new MoneyAttributeModel(
$this->name,
- $this->value instanceof MoneyBuilder ? $this->value->build() : $this->value
+ $this->value instanceof TypedMoneyBuilder ? $this->value->build() : $this->value
);
}
diff --git a/lib/commercetools-import/src/Models/Productvariants/MoneyAttributeModel.php b/lib/commercetools-import/src/Models/Productvariants/MoneyAttributeModel.php
index 7bd495f37e5..d707811b573 100644
--- a/lib/commercetools-import/src/Models/Productvariants/MoneyAttributeModel.php
+++ b/lib/commercetools-import/src/Models/Productvariants/MoneyAttributeModel.php
@@ -12,8 +12,8 @@
use Commercetools\Base\JsonObject;
use Commercetools\Base\JsonObjectModel;
use Commercetools\Base\MapperFactory;
-use Commercetools\Import\Models\Common\Money;
-use Commercetools\Import\Models\Common\MoneyModel;
+use Commercetools\Import\Models\Common\TypedMoney;
+use Commercetools\Import\Models\Common\TypedMoneyModel;
use stdClass;
/**
@@ -33,7 +33,7 @@ final class MoneyAttributeModel extends JsonObjectModel implements MoneyAttribut
protected $type;
/**
- * @var ?Money
+ * @var ?TypedMoney
*/
protected $value;
@@ -43,7 +43,7 @@ final class MoneyAttributeModel extends JsonObjectModel implements MoneyAttribut
*/
public function __construct(
?string $name = null,
- ?Money $value = null
+ ?TypedMoney $value = null
) {
$this->name = $name;
$this->value = $value;
@@ -89,7 +89,7 @@ public function getType()
}
/**
- * @return null|Money
+ * @return null|TypedMoney
*/
public function getValue()
{
@@ -99,8 +99,8 @@ public function getValue()
if (is_null($data)) {
return null;
}
-
- $this->value = MoneyModel::of($data);
+ $className = TypedMoneyModel::resolveDiscriminatorClass($data);
+ $this->value = $className::of($data);
}
return $this->value;
@@ -116,9 +116,9 @@ public function setName(?string $name): void
}
/**
- * @param ?Money $value
+ * @param ?TypedMoney $value
*/
- public function setValue(?Money $value): void
+ public function setValue(?TypedMoney $value): void
{
$this->value = $value;
}
diff --git a/lib/commercetools-import/src/Models/Productvariants/MoneySetAttribute.php b/lib/commercetools-import/src/Models/Productvariants/MoneySetAttribute.php
index 93d793eb63f..3526bf466e5 100644
--- a/lib/commercetools-import/src/Models/Productvariants/MoneySetAttribute.php
+++ b/lib/commercetools-import/src/Models/Productvariants/MoneySetAttribute.php
@@ -10,19 +10,19 @@
use Commercetools\Base\DateTimeImmutableCollection;
use Commercetools\Base\JsonObject;
-use Commercetools\Import\Models\Common\MoneyCollection;
+use Commercetools\Import\Models\Common\TypedMoneyCollection;
interface MoneySetAttribute extends Attribute
{
public const FIELD_VALUE = 'value';
/**
- * @return null|MoneyCollection
+ * @return null|TypedMoneyCollection
*/
public function getValue();
/**
- * @param ?MoneyCollection $value
+ * @param ?TypedMoneyCollection $value
*/
- public function setValue(?MoneyCollection $value): void;
+ public function setValue(?TypedMoneyCollection $value): void;
}
diff --git a/lib/commercetools-import/src/Models/Productvariants/MoneySetAttributeBuilder.php b/lib/commercetools-import/src/Models/Productvariants/MoneySetAttributeBuilder.php
index cb8e16d2889..0f64e4b2a79 100644
--- a/lib/commercetools-import/src/Models/Productvariants/MoneySetAttributeBuilder.php
+++ b/lib/commercetools-import/src/Models/Productvariants/MoneySetAttributeBuilder.php
@@ -13,7 +13,7 @@
use Commercetools\Base\JsonObject;
use Commercetools\Base\JsonObjectModel;
use Commercetools\Base\MapperFactory;
-use Commercetools\Import\Models\Common\MoneyCollection;
+use Commercetools\Import\Models\Common\TypedMoneyCollection;
use stdClass;
/**
@@ -27,7 +27,7 @@ final class MoneySetAttributeBuilder implements Builder
private $name;
/**
- * @var ?MoneyCollection
+ * @var ?TypedMoneyCollection
*/
private $value;
@@ -44,7 +44,7 @@ public function getName()
}
/**
- * @return null|MoneyCollection
+ * @return null|TypedMoneyCollection
*/
public function getValue()
{
@@ -63,10 +63,10 @@ public function withName(?string $name)
}
/**
- * @param ?MoneyCollection $value
+ * @param ?TypedMoneyCollection $value
* @return $this
*/
- public function withValue(?MoneyCollection $value)
+ public function withValue(?TypedMoneyCollection $value)
{
$this->value = $value;
diff --git a/lib/commercetools-import/src/Models/Productvariants/MoneySetAttributeModel.php b/lib/commercetools-import/src/Models/Productvariants/MoneySetAttributeModel.php
index c61808401af..14ce11603d1 100644
--- a/lib/commercetools-import/src/Models/Productvariants/MoneySetAttributeModel.php
+++ b/lib/commercetools-import/src/Models/Productvariants/MoneySetAttributeModel.php
@@ -12,7 +12,7 @@
use Commercetools\Base\JsonObject;
use Commercetools\Base\JsonObjectModel;
use Commercetools\Base\MapperFactory;
-use Commercetools\Import\Models\Common\MoneyCollection;
+use Commercetools\Import\Models\Common\TypedMoneyCollection;
use stdClass;
/**
@@ -32,7 +32,7 @@ final class MoneySetAttributeModel extends JsonObjectModel implements MoneySetAt
protected $type;
/**
- * @var ?MoneyCollection
+ * @var ?TypedMoneyCollection
*/
protected $value;
@@ -42,7 +42,7 @@ final class MoneySetAttributeModel extends JsonObjectModel implements MoneySetAt
*/
public function __construct(
?string $name = null,
- ?MoneyCollection $value = null
+ ?TypedMoneyCollection $value = null
) {
$this->name = $name;
$this->value = $value;
@@ -88,7 +88,7 @@ public function getType()
}
/**
- * @return null|MoneyCollection
+ * @return null|TypedMoneyCollection
*/
public function getValue()
{
@@ -98,7 +98,7 @@ public function getValue()
if (is_null($data)) {
return null;
}
- $this->value = MoneyCollection::fromArray($data);
+ $this->value = TypedMoneyCollection::fromArray($data);
}
return $this->value;
@@ -114,9 +114,9 @@ public function setName(?string $name): void
}
/**
- * @param ?MoneyCollection $value
+ * @param ?TypedMoneyCollection $value
*/
- public function setValue(?MoneyCollection $value): void
+ public function setValue(?TypedMoneyCollection $value): void
{
$this->value = $value;
}