Skip to content

Commit

Permalink
fix(#41): dates in Order\OrderItem are optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeroen van Leusden committed Aug 6, 2021
1 parent 7f2dfcf commit 1393c78
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 21 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bol-com/retailer-api",
"type": "library",
"version": "1.1.1",
"version": "1.1.2",
"authors": [
{
"name": "Reach Digital",
Expand Down
88 changes: 69 additions & 19 deletions src/Model/Order/OrderItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ final class OrderItem
private $offerId;
private $transactionFee;
private $latestDeliveryDate;
private $expiryDate;
private $exactDeliveryDate;
private $offerCondition;
private $cancelRequest;
private $fulfilmentMethod;
private $selectedDeliveryWindow;

public function __construct(OrderItemId $orderItemId, string $offerReference = null, \BolCom\RetailerApi\Model\Offer\Ean $ean, string $title, Quantity $quantity, \BolCom\RetailerApi\Model\CurrencyAmount $offerPrice, \BolCom\RetailerApi\Model\Offer\OfferId $offerId, \BolCom\RetailerApi\Model\CurrencyAmount $transactionFee, \BolCom\RetailerApi\Model\Date $latestDeliveryDate, \BolCom\RetailerApi\Model\Offer\Condition $offerCondition, bool $cancelRequest, \BolCom\RetailerApi\Model\Offer\FulfilmentMethod $fulfilmentMethod, SelectedDeliveryWindow $selectedDeliveryWindow = null)
public function __construct(OrderItemId $orderItemId, string $offerReference = null, \BolCom\RetailerApi\Model\Offer\Ean $ean, string $title, Quantity $quantity, \BolCom\RetailerApi\Model\CurrencyAmount $offerPrice, \BolCom\RetailerApi\Model\Offer\OfferId $offerId, \BolCom\RetailerApi\Model\CurrencyAmount $transactionFee, \BolCom\RetailerApi\Model\Date $latestDeliveryDate = null, \BolCom\RetailerApi\Model\Date $expiryDate = null, \BolCom\RetailerApi\Model\Date $exactDeliveryDate = null, \BolCom\RetailerApi\Model\Offer\Condition $offerCondition, bool $cancelRequest, \BolCom\RetailerApi\Model\Offer\FulfilmentMethod $fulfilmentMethod, SelectedDeliveryWindow $selectedDeliveryWindow = null)
{
$this->orderItemId = $orderItemId;
$this->offerReference = $offerReference;
Expand All @@ -35,6 +37,8 @@ public function __construct(OrderItemId $orderItemId, string $offerReference = n
$this->offerId = $offerId;
$this->transactionFee = $transactionFee;
$this->latestDeliveryDate = $latestDeliveryDate;
$this->expiryDate = $expiryDate;
$this->exactDeliveryDate = $exactDeliveryDate;
$this->offerCondition = $offerCondition;
$this->cancelRequest = $cancelRequest;
$this->fulfilmentMethod = $fulfilmentMethod;
Expand Down Expand Up @@ -81,11 +85,21 @@ public function transactionFee(): \BolCom\RetailerApi\Model\CurrencyAmount
return $this->transactionFee;
}

public function latestDeliveryDate(): \BolCom\RetailerApi\Model\Date
public function latestDeliveryDate()
{
return $this->latestDeliveryDate;
}

public function expiryDate()
{
return $this->expiryDate;
}

public function exactDeliveryDate()
{
return $this->exactDeliveryDate;
}

public function offerCondition(): \BolCom\RetailerApi\Model\Offer\Condition
{
return $this->offerCondition;
Expand All @@ -108,67 +122,77 @@ public function selectedDeliveryWindow()

public function withOrderItemId(OrderItemId $orderItemId): OrderItem
{
return new self($orderItemId, $this->offerReference, $this->ean, $this->title, $this->quantity, $this->offerPrice, $this->offerId, $this->transactionFee, $this->latestDeliveryDate, $this->offerCondition, $this->cancelRequest, $this->fulfilmentMethod, $this->selectedDeliveryWindow);
return new self($orderItemId, $this->offerReference, $this->ean, $this->title, $this->quantity, $this->offerPrice, $this->offerId, $this->transactionFee, $this->latestDeliveryDate, $this->expiryDate, $this->exactDeliveryDate, $this->offerCondition, $this->cancelRequest, $this->fulfilmentMethod, $this->selectedDeliveryWindow);
}

public function withOfferReference(string $offerReference = null): OrderItem
{
return new self($this->orderItemId, $offerReference, $this->ean, $this->title, $this->quantity, $this->offerPrice, $this->offerId, $this->transactionFee, $this->latestDeliveryDate, $this->offerCondition, $this->cancelRequest, $this->fulfilmentMethod, $this->selectedDeliveryWindow);
return new self($this->orderItemId, $offerReference, $this->ean, $this->title, $this->quantity, $this->offerPrice, $this->offerId, $this->transactionFee, $this->latestDeliveryDate, $this->expiryDate, $this->exactDeliveryDate, $this->offerCondition, $this->cancelRequest, $this->fulfilmentMethod, $this->selectedDeliveryWindow);
}

public function withEan(\BolCom\RetailerApi\Model\Offer\Ean $ean): OrderItem
{
return new self($this->orderItemId, $this->offerReference, $ean, $this->title, $this->quantity, $this->offerPrice, $this->offerId, $this->transactionFee, $this->latestDeliveryDate, $this->offerCondition, $this->cancelRequest, $this->fulfilmentMethod, $this->selectedDeliveryWindow);
return new self($this->orderItemId, $this->offerReference, $ean, $this->title, $this->quantity, $this->offerPrice, $this->offerId, $this->transactionFee, $this->latestDeliveryDate, $this->expiryDate, $this->exactDeliveryDate, $this->offerCondition, $this->cancelRequest, $this->fulfilmentMethod, $this->selectedDeliveryWindow);
}

public function withTitle(string $title): OrderItem
{
return new self($this->orderItemId, $this->offerReference, $this->ean, $title, $this->quantity, $this->offerPrice, $this->offerId, $this->transactionFee, $this->latestDeliveryDate, $this->offerCondition, $this->cancelRequest, $this->fulfilmentMethod, $this->selectedDeliveryWindow);
return new self($this->orderItemId, $this->offerReference, $this->ean, $title, $this->quantity, $this->offerPrice, $this->offerId, $this->transactionFee, $this->latestDeliveryDate, $this->expiryDate, $this->exactDeliveryDate, $this->offerCondition, $this->cancelRequest, $this->fulfilmentMethod, $this->selectedDeliveryWindow);
}

public function withQuantity(Quantity $quantity): OrderItem
{
return new self($this->orderItemId, $this->offerReference, $this->ean, $this->title, $quantity, $this->offerPrice, $this->offerId, $this->transactionFee, $this->latestDeliveryDate, $this->offerCondition, $this->cancelRequest, $this->fulfilmentMethod, $this->selectedDeliveryWindow);
return new self($this->orderItemId, $this->offerReference, $this->ean, $this->title, $quantity, $this->offerPrice, $this->offerId, $this->transactionFee, $this->latestDeliveryDate, $this->expiryDate, $this->exactDeliveryDate, $this->offerCondition, $this->cancelRequest, $this->fulfilmentMethod, $this->selectedDeliveryWindow);
}

public function withOfferPrice(\BolCom\RetailerApi\Model\CurrencyAmount $offerPrice): OrderItem
{
return new self($this->orderItemId, $this->offerReference, $this->ean, $this->title, $this->quantity, $offerPrice, $this->offerId, $this->transactionFee, $this->latestDeliveryDate, $this->offerCondition, $this->cancelRequest, $this->fulfilmentMethod, $this->selectedDeliveryWindow);
return new self($this->orderItemId, $this->offerReference, $this->ean, $this->title, $this->quantity, $offerPrice, $this->offerId, $this->transactionFee, $this->latestDeliveryDate, $this->expiryDate, $this->exactDeliveryDate, $this->offerCondition, $this->cancelRequest, $this->fulfilmentMethod, $this->selectedDeliveryWindow);
}

public function withOfferId(\BolCom\RetailerApi\Model\Offer\OfferId $offerId): OrderItem
{
return new self($this->orderItemId, $this->offerReference, $this->ean, $this->title, $this->quantity, $this->offerPrice, $offerId, $this->transactionFee, $this->latestDeliveryDate, $this->offerCondition, $this->cancelRequest, $this->fulfilmentMethod, $this->selectedDeliveryWindow);
return new self($this->orderItemId, $this->offerReference, $this->ean, $this->title, $this->quantity, $this->offerPrice, $offerId, $this->transactionFee, $this->latestDeliveryDate, $this->expiryDate, $this->exactDeliveryDate, $this->offerCondition, $this->cancelRequest, $this->fulfilmentMethod, $this->selectedDeliveryWindow);
}

public function withTransactionFee(\BolCom\RetailerApi\Model\CurrencyAmount $transactionFee): OrderItem
{
return new self($this->orderItemId, $this->offerReference, $this->ean, $this->title, $this->quantity, $this->offerPrice, $this->offerId, $transactionFee, $this->latestDeliveryDate, $this->offerCondition, $this->cancelRequest, $this->fulfilmentMethod, $this->selectedDeliveryWindow);
return new self($this->orderItemId, $this->offerReference, $this->ean, $this->title, $this->quantity, $this->offerPrice, $this->offerId, $transactionFee, $this->latestDeliveryDate, $this->expiryDate, $this->exactDeliveryDate, $this->offerCondition, $this->cancelRequest, $this->fulfilmentMethod, $this->selectedDeliveryWindow);
}

public function withLatestDeliveryDate(\BolCom\RetailerApi\Model\Date $latestDeliveryDate = null): OrderItem
{
return new self($this->orderItemId, $this->offerReference, $this->ean, $this->title, $this->quantity, $this->offerPrice, $this->offerId, $this->transactionFee, $latestDeliveryDate, $this->expiryDate, $this->exactDeliveryDate, $this->offerCondition, $this->cancelRequest, $this->fulfilmentMethod, $this->selectedDeliveryWindow);
}

public function withExpiryDate(\BolCom\RetailerApi\Model\Date $expiryDate = null): OrderItem
{
return new self($this->orderItemId, $this->offerReference, $this->ean, $this->title, $this->quantity, $this->offerPrice, $this->offerId, $this->transactionFee, $this->latestDeliveryDate, $expiryDate, $this->exactDeliveryDate, $this->offerCondition, $this->cancelRequest, $this->fulfilmentMethod, $this->selectedDeliveryWindow);
}

public function withLatestDeliveryDate(\BolCom\RetailerApi\Model\Date $latestDeliveryDate): OrderItem
public function withExactDeliveryDate(\BolCom\RetailerApi\Model\Date $exactDeliveryDate = null): OrderItem
{
return new self($this->orderItemId, $this->offerReference, $this->ean, $this->title, $this->quantity, $this->offerPrice, $this->offerId, $this->transactionFee, $latestDeliveryDate, $this->offerCondition, $this->cancelRequest, $this->fulfilmentMethod, $this->selectedDeliveryWindow);
return new self($this->orderItemId, $this->offerReference, $this->ean, $this->title, $this->quantity, $this->offerPrice, $this->offerId, $this->transactionFee, $this->latestDeliveryDate, $this->expiryDate, $exactDeliveryDate, $this->offerCondition, $this->cancelRequest, $this->fulfilmentMethod, $this->selectedDeliveryWindow);
}

public function withOfferCondition(\BolCom\RetailerApi\Model\Offer\Condition $offerCondition): OrderItem
{
return new self($this->orderItemId, $this->offerReference, $this->ean, $this->title, $this->quantity, $this->offerPrice, $this->offerId, $this->transactionFee, $this->latestDeliveryDate, $offerCondition, $this->cancelRequest, $this->fulfilmentMethod, $this->selectedDeliveryWindow);
return new self($this->orderItemId, $this->offerReference, $this->ean, $this->title, $this->quantity, $this->offerPrice, $this->offerId, $this->transactionFee, $this->latestDeliveryDate, $this->expiryDate, $this->exactDeliveryDate, $offerCondition, $this->cancelRequest, $this->fulfilmentMethod, $this->selectedDeliveryWindow);
}

public function withCancelRequest(bool $cancelRequest): OrderItem
{
return new self($this->orderItemId, $this->offerReference, $this->ean, $this->title, $this->quantity, $this->offerPrice, $this->offerId, $this->transactionFee, $this->latestDeliveryDate, $this->offerCondition, $cancelRequest, $this->fulfilmentMethod, $this->selectedDeliveryWindow);
return new self($this->orderItemId, $this->offerReference, $this->ean, $this->title, $this->quantity, $this->offerPrice, $this->offerId, $this->transactionFee, $this->latestDeliveryDate, $this->expiryDate, $this->exactDeliveryDate, $this->offerCondition, $cancelRequest, $this->fulfilmentMethod, $this->selectedDeliveryWindow);
}

public function withFulfilmentMethod(\BolCom\RetailerApi\Model\Offer\FulfilmentMethod $fulfilmentMethod): OrderItem
{
return new self($this->orderItemId, $this->offerReference, $this->ean, $this->title, $this->quantity, $this->offerPrice, $this->offerId, $this->transactionFee, $this->latestDeliveryDate, $this->offerCondition, $this->cancelRequest, $fulfilmentMethod, $this->selectedDeliveryWindow);
return new self($this->orderItemId, $this->offerReference, $this->ean, $this->title, $this->quantity, $this->offerPrice, $this->offerId, $this->transactionFee, $this->latestDeliveryDate, $this->expiryDate, $this->exactDeliveryDate, $this->offerCondition, $this->cancelRequest, $fulfilmentMethod, $this->selectedDeliveryWindow);
}

public function withSelectedDeliveryWindow(SelectedDeliveryWindow $selectedDeliveryWindow = null): OrderItem
{
return new self($this->orderItemId, $this->offerReference, $this->ean, $this->title, $this->quantity, $this->offerPrice, $this->offerId, $this->transactionFee, $this->latestDeliveryDate, $this->offerCondition, $this->cancelRequest, $this->fulfilmentMethod, $selectedDeliveryWindow);
return new self($this->orderItemId, $this->offerReference, $this->ean, $this->title, $this->quantity, $this->offerPrice, $this->offerId, $this->transactionFee, $this->latestDeliveryDate, $this->expiryDate, $this->exactDeliveryDate, $this->offerCondition, $this->cancelRequest, $this->fulfilmentMethod, $selectedDeliveryWindow);
}

public static function fromArray(array $data): OrderItem
Expand Down Expand Up @@ -225,11 +249,35 @@ public static function fromArray(array $data): OrderItem

$transactionFee = \BolCom\RetailerApi\Model\CurrencyAmount::fromScalar($data['transactionFee']);

if (! isset($data['latestDeliveryDate']) || ! \is_string($data['latestDeliveryDate'])) {
throw new \InvalidArgumentException("Key 'latestDeliveryDate' is missing in data array or is not a string");
if (isset($data['latestDeliveryDate'])) {
if (! \is_string($data['latestDeliveryDate'])) {
throw new \InvalidArgumentException("Value for 'latestDeliveryDate' is not a string in data array");
}

$latestDeliveryDate = \BolCom\RetailerApi\Model\Date::fromString($data['latestDeliveryDate']);
} else {
$latestDeliveryDate = null;
}

if (isset($data['expiryDate'])) {
if (! \is_string($data['expiryDate'])) {
throw new \InvalidArgumentException("Value for 'expiryDate' is not a string in data array");
}

$expiryDate = \BolCom\RetailerApi\Model\Date::fromString($data['expiryDate']);
} else {
$expiryDate = null;
}

$latestDeliveryDate = \BolCom\RetailerApi\Model\Date::fromString($data['latestDeliveryDate']);
if (isset($data['exactDeliveryDate'])) {
if (! \is_string($data['exactDeliveryDate'])) {
throw new \InvalidArgumentException("Value for 'exactDeliveryDate' is not a string in data array");
}

$exactDeliveryDate = \BolCom\RetailerApi\Model\Date::fromString($data['exactDeliveryDate']);
} else {
$exactDeliveryDate = null;
}

if (! isset($data['offerCondition']) || ! \is_string($data['offerCondition'])) {
throw new \InvalidArgumentException("Key 'offerCondition' is missing in data array or is not a string");
Expand Down Expand Up @@ -269,6 +317,8 @@ public static function fromArray(array $data): OrderItem
$offerId,
$transactionFee,
$latestDeliveryDate,
$expiryDate,
$exactDeliveryDate,
$offerCondition,
$cancelRequest,
$fulfilmentMethod,
Expand Down
4 changes: 3 additions & 1 deletion src/Model/Order/domain.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ namespace BolCom\RetailerApi\Model\Order {
\BolCom\RetailerApi\Model\CurrencyAmount $offerPrice,
\BolCom\RetailerApi\Model\Offer\OfferId $offerId,
\BolCom\RetailerApi\Model\CurrencyAmount $transactionFee,
\BolCom\RetailerApi\Model\Date $latestDeliveryDate,
?\BolCom\RetailerApi\Model\Date $latestDeliveryDate,
?\BolCom\RetailerApi\Model\Date $expiryDate,
?\BolCom\RetailerApi\Model\Date $exactDeliveryDate,
\BolCom\RetailerApi\Model\Offer\Condition $offerCondition,
bool $cancelRequest,
\BolCom\RetailerApi\Model\Offer\FulfilmentMethod $fulfilmentMethod,
Expand Down

0 comments on commit 1393c78

Please sign in to comment.