Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(checkout): show carriers only for countries they ship to #273

Merged
merged 6 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -16,7 +16,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 @@ -41,7 +42,8 @@ class MyParcelNL extends CarrierModule
use HasPdkProductHooks;
use HasPdkRenderHooks;
use HasPdkScriptHooks;
use HasPsCarrierHooks;
use HasPsCarrierListHooks;
use HasPsCarrierUpdateHooks;
use HasPsShippingCostHooks;

private static ?string $versionFromComposer = null;
Expand Down
Loading