woo-postnl
/
includes
/
vendor
/
myparcelnl
/
sdk
/
src
/
Adapter
/
DeliveryOptions
/
DeliveryOptionsV3Adapter.php
DeliveryOptionsV3Adapter.php in PostNL for WooCommerce 4.0.0, at includes/vendor/myparcelnl/sdk/src/Adapter/DeliveryOptions/DeliveryOptionsV3Adapter.php
| 1 | <?php declare(strict_types=1); |
| 2 | |
| 3 | namespace MyParcelNL\Sdk\src\Adapter\DeliveryOptions; |
| 4 | |
| 5 | use Exception; |
| 6 | |
| 7 | /** |
| 8 | * Class DeliveryOptionsV3Adapter |
| 9 | */ |
| 10 | class DeliveryOptionsV3Adapter extends AbstractDeliveryOptionsAdapter |
| 11 | { |
| 12 | /** |
| 13 | * Default values to use if there is no input. |
| 14 | */ |
| 15 | public const DEFAULTS = [ |
| 16 | "deliveryType" => "standard", |
| 17 | "date" => "", |
| 18 | "shipmentOptions" => [], |
| 19 | "isPickup" => false, |
| 20 | ]; |
| 21 | |
| 22 | /** |
| 23 | * DeliveryOptions constructor. |
| 24 | * |
| 25 | * @param array $deliveryOptions |
| 26 | */ |
| 27 | public function __construct(array $deliveryOptions = []) |
| 28 | { |
| 29 | if (! count($deliveryOptions)) { |
| 30 | $deliveryOptions = self::DEFAULTS; |
| 31 | } |
| 32 | |
| 33 | $this->carrier = $deliveryOptions["carrier"] ?? null; |
| 34 | $this->date = $deliveryOptions["date"] ?? null; |
| 35 | $this->deliveryType = $deliveryOptions["deliveryType"] ?? null; |
| 36 | $this->packageType = $deliveryOptions["packageType"] ?? null; |
| 37 | $this->shipmentOptions = new ShipmentOptionsV3Adapter($deliveryOptions["shipmentOptions"] ?? []); |
| 38 | |
| 39 | if ($this->isPickup()) { |
| 40 | $this->pickupLocation = new PickupLocationV3Adapter($deliveryOptions["pickupLocation"]); |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 |