Skip to content

Commit

Permalink
feat: add ups to nl, be and lu (#324)
Browse files Browse the repository at this point in the history
INT-658

---------

Co-authored-by: jochemgravendeel <[email protected]>
  • Loading branch information
FlorianSDV and GravendeelJochem authored Dec 18, 2024
1 parent 0cdbf7d commit 065e50f
Show file tree
Hide file tree
Showing 131 changed files with 2,540 additions and 173 deletions.
2 changes: 2 additions & 0 deletions config/pdk-business-logic.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
declare(strict_types=1);

use MyParcelNL\Pdk\App\Options\Definition\AgeCheckDefinition;
use MyParcelNL\Pdk\App\Options\Definition\CollectDefinition;
use MyParcelNL\Pdk\App\Options\Definition\DirectReturnDefinition;
use MyParcelNL\Pdk\App\Options\Definition\HideSenderDefinition;
use MyParcelNL\Pdk\App\Options\Definition\InsuranceDefinition;
Expand Down Expand Up @@ -76,6 +77,7 @@
new SignatureDefinition(),
new TrackedDefinition(),
new ReceiptCodeDefinition(),
new CollectDefinition(),
];
}),

Expand Down
18 changes: 14 additions & 4 deletions config/platform/myparcel.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
'sameDayDelivery' => false,
'signature' => true,
'receiptCode' => true,
'collect' => false,
'insurance' => [
0,
10000,
Expand Down Expand Up @@ -99,6 +100,7 @@
'onlyRecipient' => true,
'sameDayDelivery' => false,
'largeFormat' => true,
'collect' => false,
],
'features' => [
'labelDescriptionLength' => 45,
Expand All @@ -112,7 +114,7 @@
'packageTypes' => [
DeliveryOptions::PACKAGE_TYPE_PACKAGE_NAME,
DeliveryOptions::PACKAGE_TYPE_MAILBOX_NAME,
DeliveryOptions::PACKAGE_TYPE_PACKAGE_SMALL_NAME
DeliveryOptions::PACKAGE_TYPE_PACKAGE_SMALL_NAME,
],
'deliveryTypes' => [
DeliveryOptions::DELIVERY_TYPE_STANDARD_NAME,
Expand All @@ -127,6 +129,7 @@
'signature' => true,
'saturdayDelivery' => true,
'hideSender' => true,
'collect' => false,
'insurance' => [
0,
50000,
Expand Down Expand Up @@ -162,6 +165,7 @@
'onlyRecipient' => true,
'sameDayDelivery' => true,
'largeFormat' => true,
'collect' => false,
],
'features' => [
'labelDescriptionLength' => 45,
Expand All @@ -187,6 +191,7 @@
'signature' => true,
'saturdayDelivery' => false,
'hideSender' => false,
'collect' => false,
'insurance' => [
0,
50000,
Expand Down Expand Up @@ -222,6 +227,7 @@
'onlyRecipient' => false,
'sameDayDelivery' => false,
'largeFormat' => false,
'collect' => false,
],
'features' => [
'labelDescriptionLength' => 45,
Expand Down Expand Up @@ -273,11 +279,14 @@
],
'deliveryTypes' => [
DeliveryOptions::DELIVERY_TYPE_STANDARD_NAME,
DeliveryOptions::DELIVERY_TYPE_EXPRESS_NAME,
],
'shipmentOptions' => [
'ageCheck' => false,
'onlyRecipient' => false,
'return' => false,
'ageCheck' => true,
'onlyRecipient' => true,
'return' => true,
'signature' => true,
'collect' => true,
],
'features' => [
'labelDescriptionLength' => 45,
Expand All @@ -299,6 +308,7 @@
'ageCheck' => false,
'onlyRecipient' => false,
'return' => false,
'collect' => false,
],
'features' => [
'labelDescriptionLength' => 45,
Expand Down
4 changes: 2 additions & 2 deletions config/schema/myparcel/order/ups/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"required": ["deliveryType"],
"properties": {
"deliveryType": {
"enum": ["standard", null]
"enum": ["standard", null, "express"]
}
}
}
Expand Down Expand Up @@ -43,7 +43,7 @@
"deliveryOptions": {
"properties": {
"deliveryType": {
"enum": ["standard", null]
"enum": ["standard", null, "express"]
},
"packageType": {
"enum": ["package", null]
Expand Down
5 changes: 4 additions & 1 deletion config/schema/order.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"pattern": "^(20\\d\\d)-(0[1-9]|1[012])-(0[1-9]|[12]\\d|3[01]) ([01]\\d|2[0123]):([012345]\\d):([012345]\\d)$"
},
"deliveryType": {
"enum": ["morning", "standard", "evening", "pickup"]
"enum": ["morning", "standard", "evening", "pickup", "express"]
},
"labelAmount": {
"type": ["integer", "null"],
Expand Down Expand Up @@ -146,6 +146,9 @@
},
"receiptCode": {
"enum": [0, 1]
},
"collect": {
"enum": [-1, 0, 1]
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/App/DeliveryOptions/Service/DeliveryOptionsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class DeliveryOptionsService implements DeliveryOptionsServiceInterface
'allowSameDayDelivery' => CarrierSettings::ALLOW_SAME_DAY_DELIVERY,
'allowSaturdayDelivery' => CarrierSettings::ALLOW_SATURDAY_DELIVERY,
'allowSignature' => CarrierSettings::ALLOW_SIGNATURE,
'allowExpressDelivery' => CarrierSettings::ALLOW_DELIVERY_TYPE_EXPRESS,
'priceEveningDelivery' => CarrierSettings::PRICE_DELIVERY_TYPE_EVENING,
'priceMorningDelivery' => CarrierSettings::PRICE_DELIVERY_TYPE_MORNING,
'priceOnlyRecipient' => CarrierSettings::PRICE_ONLY_RECIPIENT,
Expand All @@ -46,6 +47,7 @@ class DeliveryOptionsService implements DeliveryOptionsServiceInterface
'priceSameDayDelivery' => CarrierSettings::PRICE_DELIVERY_TYPE_SAME_DAY,
'priceSignature' => CarrierSettings::PRICE_SIGNATURE,
'priceStandardDelivery' => CarrierSettings::PRICE_DELIVERY_TYPE_STANDARD,
'priceCollect' => CarrierSettings::PRICE_COLLECT,
];

/**
Expand Down
45 changes: 45 additions & 0 deletions src/App/Options/Definition/CollectDefinition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace MyParcelNL\Pdk\App\Options\Definition;

use MyParcelNL\Pdk\App\Options\Contract\OrderOptionDefinitionInterface;
use MyParcelNL\Pdk\Settings\Model\CarrierSettings;
use MyParcelNL\Pdk\Shipment\Model\ShipmentOptions;
use MyParcelNL\Pdk\Validation\Validator\CarrierSchema;

class CollectDefinition implements OrderOptionDefinitionInterface
{
/**
* @inheritDoc
*/
public function getCarrierSettingsKey(): ?string
{
return CarrierSettings::EXPORT_COLLECT;
}

/**
* @inheritDoc
*/
public function getProductSettingsKey(): ?string
{
return null;
}

/**
* @inheritDoc
*/
public function getShipmentOptionsKey(): ?string
{
return ShipmentOptions::COLLECT;
}

/**
* @inheritDoc
*/
public function validate(CarrierSchema $carrierSchema): bool
{
return $carrierSchema->canHaveCollect();
}
}
25 changes: 25 additions & 0 deletions src/App/Order/Calculator/UPS/UPSAgeCheckCalculator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace MyParcelNL\Pdk\App\Order\Calculator\UPS;

use MyParcelNL\Pdk\App\Order\Calculator\AbstractPdkOrderOptionCalculator;
use MyParcelNL\Pdk\Types\Service\TriStateService;

/**
* When age check is enabled, signature is required.
*/
final class UPSAgeCheckCalculator extends AbstractPdkOrderOptionCalculator
{
public function calculate(): void
{
$shipmentOptions = $this->order->deliveryOptions->shipmentOptions;

if (TriStateService::ENABLED !== $shipmentOptions->ageCheck) {
return;
}

$shipmentOptions->signature = TriStateService::ENABLED;
}
}
2 changes: 2 additions & 0 deletions src/App/Order/Calculator/UPS/UPSCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ protected function getCalculators(): array
{
return [
UPSCountryShipmentOptionsCalculator::class,
UPSAgeCheckCalculator::class,
UPSDeliveryTypeCalculator::class,
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,12 @@
namespace MyParcelNL\Pdk\App\Order\Calculator\UPS;

use MyParcelNL\Pdk\App\Order\Calculator\AbstractPdkOrderOptionCalculator;
use MyParcelNL\Pdk\App\Order\Model\PdkOrder;
use MyParcelNL\Pdk\Base\Contract\CountryServiceInterface;
use MyParcelNL\Pdk\Facade\Pdk;

class UPSCountryShipmentOptionsCalculator extends AbstractPdkOrderOptionCalculator
{
private $countryService;

public function __construct(PdkOrder $order)
{
parent::__construct($order);

$this->countryService = Pdk::get(CountryServiceInterface::class);
}

// Comment: Always set delivery date to null for UPS shipments regardless of country
public function calculate(): void
{
$cc = $this->order->shippingAddress->cc;
if ($this->countryService->isRow($cc) || $this->countryService->isEu($cc)) {
$this->order->deliveryOptions->date = null;
}
$this->order->deliveryOptions->date = null;
}
}
28 changes: 28 additions & 0 deletions src/App/Order/Calculator/UPS/UPSDeliveryTypeCalculator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace MyParcelNL\Pdk\App\Order\Calculator\UPS;

use MyParcelNL\Pdk\App\Order\Calculator\AbstractPdkOrderOptionCalculator;
use MyParcelNL\Pdk\Base\Service\CountryCodes;
use MyParcelNL\Pdk\Shipment\Model\DeliveryOptions;

class UPSDeliveryTypeCalculator extends AbstractPdkOrderOptionCalculator
{
/**
* @inheritDoc
*/
public function calculate(): void
{
$deliveryOptions = $this->order->deliveryOptions;

$isExpress = $deliveryOptions->deliveryType === DeliveryOptions::DELIVERY_TYPE_EXPRESS_NAME;
if (
$isExpress
&& $this->order->shippingAddress->cc !== CountryCodes::CC_NL
) {
$deliveryOptions->deliveryType = DeliveryOptions::DELIVERY_TYPE_STANDARD_NAME;
}
}
}
12 changes: 11 additions & 1 deletion src/Frontend/View/CarrierSettingsItemView.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ function (FormOperationBuilder $builder) {
: [],

$this->carrierSchema->canHaveInsurance() ? $this->getExportInsuranceFields() : [],

$this->carrierSchema->canHaveCollect()
? [new interactiveElement(CarrierSettings::EXPORT_COLLECT, Components::INPUT_TOGGLE)]
: [],
];
}

Expand Down Expand Up @@ -393,7 +397,13 @@ function (FormOperationBuilder $builder) {
$this->carrierSchema->canHaveOnlyRecipient() ? $this->createSettingWithPriceFields(
CarrierSettings::ALLOW_ONLY_RECIPIENT,
CarrierSettings::PRICE_ONLY_RECIPIENT
) : []
) : [],

$this->carrierSchema->canHaveExpressDelivery() ?
$this->createSettingWithPriceFields(
CarrierSettings::ALLOW_DELIVERY_TYPE_EXPRESS,
CarrierSettings::PRICE_DELIVERY_TYPE_EXPRESS
) : []
),

/**
Expand Down
Loading

0 comments on commit 065e50f

Please sign in to comment.