Skip to content

Commit

Permalink
feat(checkout): show carriers only for countries they ship to
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Sep 26, 2024
1 parent eebdfd5 commit f06a031
Show file tree
Hide file tree
Showing 32 changed files with 1,119 additions and 101 deletions.
279 changes: 276 additions & 3 deletions config/pdk.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types=1);

use MyParcelNL\Pdk\Account\Platform;
use MyParcelNL\Pdk\Api\Contract\ClientAdapterInterface;
use MyParcelNL\Pdk\App\Account\Contract\PdkAccountRepositoryInterface;
use MyParcelNL\Pdk\App\Action\Backend\Account\UpdateAccountAction;
Expand All @@ -23,6 +24,8 @@
use MyParcelNL\Pdk\Audit\Service\AuditService;
use MyParcelNL\Pdk\Base\Contract\CronServiceInterface;
use MyParcelNL\Pdk\Base\Contract\WeightServiceInterface;
use MyParcelNL\Pdk\Base\Service\CountryCodes;
use MyParcelNL\Pdk\Carrier\Model\Carrier;
use MyParcelNL\Pdk\Facade\Pdk;
use MyParcelNL\Pdk\Frontend\Contract\FrontendRenderServiceInterface;
use MyParcelNL\Pdk\Frontend\Contract\ScriptServiceInterface;
Expand All @@ -32,6 +35,7 @@
use MyParcelNL\PrestaShop\Configuration\Contract\PsConfigurationServiceInterface;
use MyParcelNL\PrestaShop\Configuration\Service\Ps17PsConfigurationService;
use MyParcelNL\PrestaShop\Contract\PsCarrierServiceInterface;
use MyParcelNL\PrestaShop\Contract\PsCountryServiceInterface;
use MyParcelNL\PrestaShop\Contract\PsObjectModelServiceInterface;
use MyParcelNL\PrestaShop\Contract\PsOrderServiceInterface;
use MyParcelNL\PrestaShop\Database\CreateAuditTableDatabaseMigration;
Expand Down Expand Up @@ -76,6 +80,7 @@
use MyParcelNL\PrestaShop\Router\Service\Ps8RouterService;
use MyParcelNL\PrestaShop\Script\Service\PsScriptService;
use MyParcelNL\PrestaShop\Service\PsCarrierService;
use MyParcelNL\PrestaShop\Service\PsCountryService;
use MyParcelNL\PrestaShop\Service\PsObjectModelService;
use MyParcelNL\PrestaShop\Service\PsOrderService;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -176,12 +181,280 @@
/**
* Custom services
*/
PsCarrierServiceInterface::class => get(PsCarrierService::class),
PsConfigurationServiceInterface::class => get(Ps17PsConfigurationService::class),
PsObjectModelServiceInterface::class => get(PsObjectModelService::class),
PsOrderServiceInterface::class => get(PsOrderService::class),
PsRouterServiceInterface::class => psVersionFactory([
['class' => Ps8RouterService::class, 'version' => 8],
['class' => Ps17RouterService::class],
]),

/**
* Object model services
*/
PsObjectModelServiceInterface::class => get(PsObjectModelService::class),

PsCarrierServiceInterface::class => get(PsCarrierService::class),
PsCountryServiceInterface::class => get(PsCountryService::class),
PsOrderServiceInterface::class => get(PsOrderService::class),

/**
* Countries per platform and carrier.
* This is intended as a temporary solution until we can use the Carrier Capabilities service. This is copied from the Delivery Options.
*
* @TODO Replace when Carrier Capabilities is available.
*/
'countriesPerPlatformAndCarrier' => value([
Platform::MYPARCEL_NAME => [
Carrier::CARRIER_POSTNL_NAME => [
'deliveryCountries' => [
CountryCodes::CC_NL, // Netherlands
CountryCodes::CC_BE, // Belgium
],
'pickupCountries' => [
CountryCodes::CC_NL, // Netherlands
CountryCodes::CC_BE, // Belgium
CountryCodes::CC_DK, // Denmark
CountryCodes::CC_SE, // Sweden
CountryCodes::CC_DE, // Germany
],
'fakeDelivery' => true,
],
Carrier::CARRIER_DHL_FOR_YOU_NAME => [
'deliveryCountries' => [
CountryCodes::CC_NL, // Netherlands
CountryCodes::CC_BE, // Belgium
],
'pickupCountries' => [
CountryCodes::CC_NL, // Netherlands
],
],
Carrier::CARRIER_DHL_PARCEL_CONNECT_NAME => [
'deliveryCountries' => [
CountryCodes::CC_AT, // Austria
CountryCodes::CC_BG, // Bulgaria
CountryCodes::CC_HR, // Croatia
CountryCodes::CC_CZ, // Czech Republic
CountryCodes::CC_EE, // Estonia
CountryCodes::CC_FI, // Finland
CountryCodes::CC_DE, // Germany
CountryCodes::CC_GR, // Greece
CountryCodes::CC_HU, // Hungary
CountryCodes::CC_IE, // Ireland
CountryCodes::CC_IT, // Italy
CountryCodes::CC_LV, // Latvia
CountryCodes::CC_LT, // Lithuania
CountryCodes::CC_LU, // Luxembourg
CountryCodes::CC_PL, // Poland
CountryCodes::CC_PT, // Portugal
CountryCodes::CC_RO, // Romania
CountryCodes::CC_SK, // Slovakia
CountryCodes::CC_SI, // Slovenia
CountryCodes::CC_ES, // Spain
],
'pickupCountries' => [
CountryCodes::CC_AT, // Austria
CountryCodes::CC_BG, // Bulgaria
CountryCodes::CC_HR, // Croatia
CountryCodes::CC_CZ, // Czech Republic
CountryCodes::CC_DK, // Denmark
CountryCodes::CC_FR, // France
CountryCodes::CC_DE, // Germany
CountryCodes::CC_GR, // Greece
CountryCodes::CC_HU, // Hungary
CountryCodes::CC_IT, // Italy
CountryCodes::CC_LU, // Luxembourg
CountryCodes::CC_PL, // Poland
CountryCodes::CC_PT, // Portugal
CountryCodes::CC_RO, // Romania
CountryCodes::CC_SK, // Slovakia
CountryCodes::CC_SI, // Slovenia
CountryCodes::CC_ES, // Spain
CountryCodes::CC_SE, // Sweden
],
],
Carrier::CARRIER_DHL_EUROPLUS_NAME => [
'deliveryCountries' => [
CountryCodes::CC_BE, // Belgium
CountryCodes::CC_BG, // Bulgaria
CountryCodes::CC_DK, // Denmark
CountryCodes::CC_DE, // Germany
CountryCodes::CC_EE, // Estonia
CountryCodes::CC_FI, // Finland
CountryCodes::CC_FR, // France
CountryCodes::CC_GR, // Greece
CountryCodes::CC_HU, // Hungary
CountryCodes::CC_IE, // Ireland
CountryCodes::CC_IT, // Italy
CountryCodes::CC_HR, // Croatia
CountryCodes::CC_LV, // Latvia
CountryCodes::CC_LT, // Lithuania
CountryCodes::CC_LU, // Luxembourg
CountryCodes::CC_NL, // Netherlands
CountryCodes::CC_AT, // Austria
CountryCodes::CC_PL, // Poland
CountryCodes::CC_PT, // Portugal
CountryCodes::CC_RO, // Romania
CountryCodes::CC_SI, // Slovenia
CountryCodes::CC_SK, // Slovakia
CountryCodes::CC_ES, // Spain
CountryCodes::CC_CZ, // Czech Republic
CountryCodes::CC_SE, // Sweden
CountryCodes::CC_GB, // United Kingdom
],
'pickupCountries' => [],
],
Carrier::CARRIER_UPS_NAME => [
'deliveryCountries' => [
CountryCodes::CC_BG, // Bulgaria
CountryCodes::CC_DE, // Germany
CountryCodes::CC_EE, // Estonia
CountryCodes::CC_FI, // Finland
CountryCodes::CC_GR, // Greece
CountryCodes::CC_HU, // Hungary
CountryCodes::CC_IE, // Ireland
CountryCodes::CC_IT, // Italy
CountryCodes::CC_HR, // Croatia
CountryCodes::CC_LV, // Latvia
CountryCodes::CC_LT, // Lithuania
CountryCodes::CC_LU, // Luxembourg
CountryCodes::CC_AT, // Austria
CountryCodes::CC_PL, // Poland
CountryCodes::CC_PT, // Portugal
CountryCodes::CC_RO, // Romania
CountryCodes::CC_SI, // Slovenia
CountryCodes::CC_SK, // Slovakia
CountryCodes::CC_ES, // Spain
CountryCodes::CC_CZ, // Czech Republic
],
'pickupCountries' => [
CountryCodes::CC_DE, // Germany
],
'fakeDelivery' => true,
],
Carrier::CARRIER_DPD_NAME => [
'deliveryCountries' => [
CountryCodes::CC_AT, // Austria
CountryCodes::CC_BE, // Belgium
CountryCodes::CC_BG, // Bulgaria
CountryCodes::CC_CZ, // Czech Republic
CountryCodes::CC_DK, // Denmark
CountryCodes::CC_EE, // Estonia
CountryCodes::CC_FI, // Finland
CountryCodes::CC_FR, // France
CountryCodes::CC_DE, // Germany
CountryCodes::CC_GR, // Greece
CountryCodes::CC_HU, // Hungary
CountryCodes::CC_IE, // Ireland
CountryCodes::CC_IT, // Italy
CountryCodes::CC_LV, // Latvia
CountryCodes::CC_LI, // Liechtenstein
CountryCodes::CC_LT, // Lithuania
CountryCodes::CC_LU, // Luxembourg
CountryCodes::CC_NL, // Netherlands
CountryCodes::CC_PL, // Poland
CountryCodes::CC_PT, // Portugal
CountryCodes::CC_RO, // Romania
CountryCodes::CC_SK, // Slovakia
CountryCodes::CC_SI, // Slovenia
CountryCodes::CC_ES, // Spain
CountryCodes::CC_SE, // Sweden
],
'pickupCountries' => [
CountryCodes::CC_AT, // Austria
CountryCodes::CC_BE, // Belgium
CountryCodes::CC_CZ, // Czech Republic
CountryCodes::CC_DK, // Denmark
CountryCodes::CC_EE, // Estonia
CountryCodes::CC_FI, // Finland
CountryCodes::CC_FR, // France
CountryCodes::CC_DE, // Germany
CountryCodes::CC_HU, // Hungary
CountryCodes::CC_LV, // Latvia
CountryCodes::CC_LT, // Lithuania
CountryCodes::CC_LU, // Luxembourg
CountryCodes::CC_NL, // Netherlands
CountryCodes::CC_PL, // Poland
CountryCodes::CC_PT, // Portugal
CountryCodes::CC_SK, // Slovakia
CountryCodes::CC_SI, // Slovenia
CountryCodes::CC_ES, // Spain
CountryCodes::CC_GB, // United Kingdom
],
],
],

Platform::SENDMYPARCEL_NAME => [
Carrier::CARRIER_BPOST_NAME => [
'deliveryCountries' => [
CountryCodes::CC_BE, // Belgium
CountryCodes::CC_NL, // Netherlands
],
'pickupCountries' => [
CountryCodes::CC_BE, // Belgium
CountryCodes::CC_NL, // Netherlands
],
'fakeDelivery' => true,
],
Carrier::CARRIER_POSTNL_NAME => [
'deliveryCountries' => [
CountryCodes::CC_BE, // Belgium
CountryCodes::CC_NL, // Netherlands
],
'pickupCountries' => [
CountryCodes::CC_BE, // Belgium
CountryCodes::CC_NL, // Netherlands
],
'fakeDelivery' => true,
],
Carrier::CARRIER_DPD_NAME => [
'deliveryCountries' => [
CountryCodes::CC_AT, // Austria
CountryCodes::CC_BE, // Belgium
CountryCodes::CC_BG, // Bulgaria
CountryCodes::CC_CZ, // Czech Republic
CountryCodes::CC_DK, // Denmark
CountryCodes::CC_EE, // Estonia
CountryCodes::CC_FI, // Finland
CountryCodes::CC_FR, // France
CountryCodes::CC_DE, // Germany
CountryCodes::CC_GR, // Greece
CountryCodes::CC_HU, // Hungary
CountryCodes::CC_IE, // Ireland
CountryCodes::CC_IT, // Italy
CountryCodes::CC_LV, // Latvia
CountryCodes::CC_LI, // Liechtenstein
CountryCodes::CC_LT, // Lithuania
CountryCodes::CC_LU, // Luxembourg
CountryCodes::CC_NL, // Netherlands
CountryCodes::CC_PL, // Poland
CountryCodes::CC_PT, // Portugal
CountryCodes::CC_RO, // Romania
CountryCodes::CC_SK, // Slovakia
CountryCodes::CC_SI, // Slovenia
CountryCodes::CC_ES, // Spain
CountryCodes::CC_SE, // Sweden
],
'pickupCountries' => [
CountryCodes::CC_AT, // Austria
CountryCodes::CC_BE, // Belgium
CountryCodes::CC_CZ, // Czech Republic
CountryCodes::CC_DK, // Denmark
CountryCodes::CC_EE, // Estonia
CountryCodes::CC_FI, // Finland
CountryCodes::CC_FR, // France
CountryCodes::CC_DE, // Germany
CountryCodes::CC_HU, // Hungary
CountryCodes::CC_LV, // Latvia
CountryCodes::CC_LT, // Lithuania
CountryCodes::CC_LU, // Luxembourg
CountryCodes::CC_NL, // Netherlands
CountryCodes::CC_PL, // Poland
CountryCodes::CC_PT, // Portugal
CountryCodes::CC_SK, // Slovakia
CountryCodes::CC_SI, // Slovenia
CountryCodes::CC_ES, // Spain
CountryCodes::CC_GB, // United Kingdom
],
],
],
]),
];
6 changes: 4 additions & 2 deletions myparcelnl.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
use MyParcelNL\PrestaShop\Hooks\HasPdkProductHooks;
use MyParcelNL\PrestaShop\Hooks\HasPdkRenderHooks;
use MyParcelNL\PrestaShop\Hooks\HasPdkScriptHooks;
use MyParcelNL\PrestaShop\Hooks\HasPsCarrierHooks;
use MyParcelNL\PrestaShop\Hooks\HasPsCarrierListHooks;
use MyParcelNL\PrestaShop\Hooks\HasPsCarrierUpdateHooks;
use MyParcelNL\PrestaShop\Hooks\HasPsShippingCostHooks;
use function MyParcelNL\PrestaShop\bootPdk;

Expand All @@ -35,7 +36,8 @@ class MyParcelNL extends CarrierModule
use HasPdkProductHooks;
use HasPdkRenderHooks;
use HasPdkScriptHooks;
use HasPsCarrierHooks;
use HasPsCarrierListHooks;
use HasPsCarrierUpdateHooks;
use HasPsShippingCostHooks;

/**
Expand Down
Loading

0 comments on commit f06a031

Please sign in to comment.