Skip to content

Commit

Permalink
Added support for consignment_status_history in Orders
Browse files Browse the repository at this point in the history
  • Loading branch information
michalsalon-mall committed Dec 16, 2021
1 parent 36a90f2 commit bd5c906
Show file tree
Hide file tree
Showing 10 changed files with 311 additions and 106 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 4.1.0 - 2021-12-16

### Added

- `consignmentStatusHistory` attribute to `Order` entity used for MDP Spectrum orders

## 4.0.0 - 2021-11-26

### Added
Expand Down
3 changes: 2 additions & 1 deletion doc/Order.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ Example above prints out
"cancelled": null,
"delivered": null,
"shipping": null,
"ulozenkaStatusHistory": []
"ulozenkaStatusHistory": [],
"consignmentStatusHistory": []
}
```

Expand Down
2 changes: 1 addition & 1 deletion src/MpApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class MpApiClient implements ClientInterface, MpApiClientInterface
{

const APP_NAME = 'mp-api-client';
const APP_VERSION = '4.0.1-beta';
const APP_VERSION = '4.1.0';

private BrandClientInterface $brandClient;
private CategoryClientInterface $categoryClient;
Expand Down
48 changes: 48 additions & 0 deletions src/Order/Entity/ConsignmentStatusEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php declare(strict_types=1);

namespace MpApiClient\Order\Entity;

use MpApiClient\Common\Util\AbstractStringEnum;

/**
* @method static self CREATED()
* @method static self RECEIVED()
* @method static self CANCELLED()
* @method static self DELIVERING()
* @method static self DAMAGED()
* @method static self RETURNING()
* @method static self RETURNED()
* @method static self READY_FOR_PICKUP()
* @method static self DELIVERED()
* @method static self LOST()
*/
final class ConsignmentStatusEnum extends AbstractStringEnum
{

public const CREATED = 'CREATED';
public const RECEIVED = 'RECEIVED';
public const CANCELLED = 'CANCELLED';
public const DELIVERING = 'DELIVERING';
public const DAMAGED = 'DAMAGED';
public const RETURNING = 'RETURNING';
public const RETURNED = 'RETURNED';
public const READY_FOR_PICKUP = 'READY_FOR_PICKUP';
public const DELIVERED = 'DELIVERED';
public const LOST = 'LOST';

public const TYPES = [
self::CREATED,
self::RECEIVED,
self::CANCELLED,
self::DELIVERING,
self::DAMAGED,
self::RETURNING,
self::RETURNED,
self::READY_FOR_PICKUP,
self::DELIVERED,
self::LOST,
];

public const KEY_NAME = 'status';

}
24 changes: 24 additions & 0 deletions src/Order/Entity/ConsignmentStatusFlagEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php declare(strict_types=1);

namespace MpApiClient\Order\Entity;

use MpApiClient\Common\Util\AbstractStringEnum;

/**
* @method static self DAMAGED()
* @method static self LOST()
*/
final class ConsignmentStatusFlagEnum extends AbstractStringEnum
{

public const DAMAGED = 'damaged';
public const LOST = 'lost';

public const TYPES = [
self::DAMAGED,
self::LOST,
];

public const KEY_NAME = 'flags';

}
68 changes: 68 additions & 0 deletions src/Order/Entity/ConsignmentStatusHistoryItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php declare(strict_types=1);

namespace MpApiClient\Order\Entity;

use DateTime;
use DateTimeInterface;
use Exception;
use JsonSerializable;
use MpApiClient\Common\Util\JsonSerializeEntityTrait;

final class ConsignmentStatusHistoryItem implements JsonSerializable
{

use JsonSerializeEntityTrait;

private DateTimeInterface $date;
private ConsignmentStatusEnum $code;
/**
* @var ConsignmentStatusFlagEnum[]
*/
private array $flags;

/**
* @param DateTimeInterface $date
* @param ConsignmentStatusEnum $code
* @param ConsignmentStatusFlagEnum[] $flags
*/
private function __construct(ConsignmentStatusEnum $code, DateTimeInterface $date, array $flags)
{
$this->code = $code;
$this->date = $date;
$this->flags = $flags;
}

/**
* @param array<string, mixed> $data
*
* @throws Exception
* @internal
*/
public static function createFromApi(array $data): self
{
return new self(
new ConsignmentStatusEnum($data[ConsignmentStatusEnum::KEY_NAME]),
new DateTime($data['date']),
array_map(fn(string $flag): ConsignmentStatusFlagEnum => new ConsignmentStatusFlagEnum($flag), $data[ConsignmentStatusFlagEnum::KEY_NAME]),
);
}

public function getCode(): ConsignmentStatusEnum
{
return $this->code;
}

public function getDate(): DateTimeInterface
{
return $this->date;
}

/**
* @return ConsignmentStatusFlagEnum[]
*/
public function getFlags(): array
{
return $this->flags;
}

}
46 changes: 46 additions & 0 deletions src/Order/Entity/ConsignmentStatusHistoryIterator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php declare(strict_types=1);

namespace MpApiClient\Order\Entity;

use Exception;
use MpApiClient\Common\Util\AbstractIntKeyIterator;

/**
* @extends AbstractIntKeyIterator<ConsignmentStatusHistoryItem>
* @property ConsignmentStatusHistoryItem[] $data
*/
final class ConsignmentStatusHistoryIterator extends AbstractIntKeyIterator
{

private function __construct(ConsignmentStatusHistoryItem ...$data)
{
$this->data = $data;
}

/**
* @param array<int, array<string, mixed>> $data
*
* @throws Exception
* @internal
*/
public static function createFromApi(array $data): self
{
return new self(
...array_map(fn(array $item): ConsignmentStatusHistoryItem => ConsignmentStatusHistoryItem::createFromApi($item), $data)
);
}

/**
* @return false|ConsignmentStatusHistoryItem
*/
public function current()
{
return current($this->data);
}

public function get(int $key): ?ConsignmentStatusHistoryItem
{
return $this->data[$key] ?? null;
}

}
Loading

0 comments on commit bd5c906

Please sign in to comment.