| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
use MyParcelNL\Sdk\src\Adapter\DeliveryOptions\AbstractDeliveryOptionsAdapter; |
| 6 |
use MyParcelNL\Sdk\src\Model\Consignment\AbstractConsignment; |
| 7 |
|
| 8 |
class WCPN_DeliveryOptionsFromOrderAdapter extends AbstractDeliveryOptionsAdapter |
| 9 |
{ |
| 10 |
/** |
| 11 |
* Creates delivery options but sets most missing data to null instead of default values. |
| 12 |
* |
| 13 |
* @param AbstractDeliveryOptionsAdapter|null $originAdapter |
| 14 |
* @param array $inputData |
| 15 |
*/ |
| 16 |
public function __construct(?AbstractDeliveryOptionsAdapter $originAdapter, array $inputData = []) |
| 17 |
{ |
| 18 |
$adapterCarrier = $originAdapter ? $originAdapter->getCarrier() : null; |
| 19 |
$adapterDate = $originAdapter ? $originAdapter->getDate() : null; |
| 20 |
$adapterDeliveryType = $originAdapter ? $originAdapter->getDeliveryType() : AbstractConsignment::DEFAULT_DELIVERY_TYPE_NAME; |
| 21 |
$adapterPackageType = $originAdapter ? $originAdapter->getPackageType() : null; |
| 22 |
$adapterPickupLocation = $originAdapter ? $originAdapter->getPickupLocation() : null; |
| 23 |
|
| 24 |
$this->carrier = $inputData['carrier'] ?? $adapterCarrier; |
| 25 |
$this->date = $inputData['date'] ?? $adapterDate; |
| 26 |
$this->deliveryType = $inputData['delivery_type'] ?? $adapterDeliveryType; |
| 27 |
$this->packageType = $inputData['package_type'] ?? $adapterPackageType; |
| 28 |
$this->shipmentOptions = new WCPN_ShipmentOptionsFromOrderAdapter($originAdapter, $inputData); |
| 29 |
|
| 30 |
$hasInputPickupLocation = isset($inputData['pickup_location']) && ! empty($inputData['pickup_location']); |
| 31 |
$this->pickupLocation = $hasInputPickupLocation |
| 32 |
? new WCPN_PickupLocationFromOrderAdapter($originAdapter, $inputData) |
| 33 |
: $adapterPickupLocation; |
| 34 |
} |
| 35 |
} |
| 36 |
|