From 5605275032bc35e23c0024ac2c25209d322d2942 Mon Sep 17 00:00:00 2001 From: marija Date: Wed, 24 Feb 2021 16:43:22 +0100 Subject: [PATCH 01/37] Define brand configuration service and implement it for Packlink PLCR24-7 --- composer.json | 6 +- .../Packlink/PacklinkConfigurationService.php | 149 ++++++++++++++++++ .../Brand/BrandConfigurationService.php | 26 +++ .../Brand/DTO/BrandConfiguration.php | 99 ++++++++++++ .../Brands/Packlink/BaseTestWithServices.php | 23 +++ .../PacklinkConfigurationServiceTest.php | 26 +++ 6 files changed, 327 insertions(+), 2 deletions(-) create mode 100644 src/Brands/Packlink/PacklinkConfigurationService.php create mode 100644 src/BusinessLogic/Brand/BrandConfigurationService.php create mode 100644 src/BusinessLogic/Brand/DTO/BrandConfiguration.php create mode 100644 tests/Brands/Packlink/BaseTestWithServices.php create mode 100644 tests/Brands/Packlink/PacklinkConfigurationServiceTest.php diff --git a/composer.json b/composer.json index 6142cf94..b7c42ab4 100755 --- a/composer.json +++ b/composer.json @@ -10,13 +10,15 @@ "autoload": { "psr-4": { "Logeecom\\Infrastructure\\": "src/Infrastructure", - "Packlink\\BusinessLogic\\": "src/BusinessLogic" + "Packlink\\BusinessLogic\\": "src/BusinessLogic", + "Packlink\\Brands\\": "src/Brands" } }, "autoload-dev": { "psr-4": { "Logeecom\\Tests\\Infrastructure\\": "tests/Infrastructure", - "Logeecom\\Tests\\BusinessLogic\\": "tests/BusinessLogic" + "Logeecom\\Tests\\BusinessLogic\\": "tests/BusinessLogic", + "Logeecom\\Tests\\Brands\\": "tests/Brands" } }, "require-dev": { diff --git a/src/Brands/Packlink/PacklinkConfigurationService.php b/src/Brands/Packlink/PacklinkConfigurationService.php new file mode 100644 index 00000000..4b6f390a --- /dev/null +++ b/src/Brands/Packlink/PacklinkConfigurationService.php @@ -0,0 +1,149 @@ + array( + 'code' => 'ES', + 'postal_code' => '28001', + ), + 'DE' => array( + 'code' => 'DE', + 'postal_code' => '10115', + ), + 'FR' => array( + 'code' => 'FR', + 'postal_code' => '75001', + ), + 'IT' => array( + 'code' => 'IT', + 'postal_code' => '00118', + ), + 'AT' => array( + 'code' => 'AT', + 'postal_code' => '1010', + ), + 'NL' => array( + 'code' => 'NL', + 'postal_code' => '1011', + ), + 'BE' => array( + 'code' => 'BE', + 'postal_code' => '1000', + ), + 'PT' => array( + 'code' => 'PT', + 'postal_code' => '1000-017', + ), + 'TR' => array( + 'code' => 'TR', + 'postal_code' => '06010', + ), + 'IE' => array( + 'code' => 'IE', + 'postal_code' => 'D1', + ), + 'GB' => array( + 'code' => 'GB', + 'postal_code' => 'E1 6AN', + ), + 'HU' => array( + 'code' => 'HU', + 'postal_code' => '1014', + ), + ); + /** + * List of countries available only for warehouse selection. + * + * @var array + */ + protected static $additionalWarehouseCountries = array( + 'PL' => array( + 'code' => 'PL', + 'postal_code' => '00-694', + ), + 'CH' => array( + 'code' => 'CH', + 'postal_code' => '3000', + ), + 'LU' => array( + 'code' => 'LU', + 'postal_code' => '1009', + ), + 'AR' => array( + 'code' => 'AR', + 'postal_code' => 'C1258 AAA', + ), + 'US' => array( + 'code' => 'US', + 'postal_code' => '01223', + ), + 'BO' => array( + 'code' => 'BO', + 'postal_code' => 'La Paz', + ), + 'MX' => array( + 'code' => 'MX', + 'postal_code' => '21900', + ), + 'CL' => array( + 'code' => 'CL', + 'postal_code' => '7500599', + ), + 'CZ' => array( + 'code' => 'CZ', + 'postal_code' => '186 00', + ), + 'SE' => array( + 'code' => 'SE', + 'postal_code' => '103 16', + ), + ); + + /** + * @inheritDoc + */ + public function get() + { + $brandConfiguration = new BrandConfiguration(); + + $brandConfiguration->platformCode = 'PRO'; + $brandConfiguration->shippingServiceSource = 'PRO'; + $brandConfiguration->platformCountries = static::$supportedPlatformCountries; + $brandConfiguration->registrationCountries = static::$supportedRegistrationCountries; + $brandConfiguration->warehouseCountries = array_merge( + static::$supportedRegistrationCountries, + static::$additionalWarehouseCountries + ); + + return $brandConfiguration; + } +} diff --git a/src/BusinessLogic/Brand/BrandConfigurationService.php b/src/BusinessLogic/Brand/BrandConfigurationService.php new file mode 100644 index 00000000..a5f4b049 --- /dev/null +++ b/src/BusinessLogic/Brand/BrandConfigurationService.php @@ -0,0 +1,26 @@ + $this->platformCode, + 'shipping_service_source' => $this->shippingServiceSource, + 'platform_countries' => $this->platformCountries, + 'registration_countries' => $this->registrationCountries, + 'warehouse_countries' => $this->warehouseCountries, + ); + } + + /** + * Creates BrandConfiguration object from array. + * + * @param array $data + * + * @return BrandConfiguration + */ + public static function fromArray(array $data) + { + $result = new static(); + + $result->platformCode = $data['platform_code']; + $result->shippingServiceSource = $data['shipping_service_source']; + + if (isset($data['platform_countries']) && is_array($data['platform_countries'])) { + $result->platformCountries = $data['platform_countries']; + } else { + $result->platformCountries = array(); + } + + if (isset($data['registration_countries']) && is_array($data['registration_countries'])) { + $result->registrationCountries = $data['registration_countries']; + } else { + $result->registrationCountries = array(); + } + + if (isset($data['warehouse_countries']) && is_array($data['warehouse_countries'])) { + $result->warehouseCountries = $data['warehouse_countries']; + } else { + $result->warehouseCountries = array(); + } + + return $result; + } +} diff --git a/tests/Brands/Packlink/BaseTestWithServices.php b/tests/Brands/Packlink/BaseTestWithServices.php new file mode 100644 index 00000000..2baff49b --- /dev/null +++ b/tests/Brands/Packlink/BaseTestWithServices.php @@ -0,0 +1,23 @@ +get(); + $this->assertEquals('PRO', $brandConfiguration->platformCode); + $this->assertEquals('PRO', $brandConfiguration->shippingServiceSource); + $this->assertCount(5, $brandConfiguration->platformCountries); + $this->assertEquals('ES', $brandConfiguration->registrationCountries['ES']['code']); + $this->assertEquals('28001', $brandConfiguration->warehouseCountries['ES']['postal_code']); + } +} \ No newline at end of file From 586662fe39eba1f0b3c1030f62ff6ad23587c1c3 Mon Sep 17 00:00:00 2001 From: marija Date: Fri, 26 Feb 2021 09:41:14 +0100 Subject: [PATCH 02/37] Refactor ShippingServiceSearch to eliminate a hardcoded source PLCR24-8 --- src/BusinessLogic/Http/DTO/ShippingServiceSearch.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/BusinessLogic/Http/DTO/ShippingServiceSearch.php b/src/BusinessLogic/Http/DTO/ShippingServiceSearch.php index af9fc645..a3fd16f4 100644 --- a/src/BusinessLogic/Http/DTO/ShippingServiceSearch.php +++ b/src/BusinessLogic/Http/DTO/ShippingServiceSearch.php @@ -3,6 +3,8 @@ namespace Packlink\BusinessLogic\Http\DTO; use Logeecom\Infrastructure\Data\DataTransferObject; +use Logeecom\Infrastructure\ServiceRegister; +use Packlink\BusinessLogic\Brand\BrandConfigurationService; /** * This class holds search parameters that are used when searching for services @@ -82,12 +84,16 @@ public function __construct( */ public function toArray() { + /** @var BrandConfigurationService $brandConfigurationService */ + $brandConfigurationService = ServiceRegister::getService(BrandConfigurationService::CLASS_NAME); + $brand = $brandConfigurationService->get(); + $data = array( 'from[country]' => $this->fromCountry, 'from[zip]' => $this->fromZip, 'to[country]' => $this->toCountry, 'to[zip]' => $this->toZip, - 'source' => 'PRO', + 'source' => $brand->shippingServiceSource, ); if ($this->serviceId) { From 398045931b61a5e623e4fb235bd4d0c0475ee363 Mon Sep 17 00:00:00 2001 From: marija Date: Fri, 26 Feb 2021 11:12:32 +0100 Subject: [PATCH 03/37] Refactor code to eliminate hardcoded platform code PLCR24-9 --- src/BusinessLogic/Http/DTO/Draft.php | 15 ++++++++++++++- src/BusinessLogic/Http/Proxy.php | 19 +++++++++++++++++-- .../Registration/RegistrationRequest.php | 19 ++++++++++++++++--- .../Common/BaseTestWithServices.php | 9 +++++++++ .../RegistrationRequestDtoTest.php | 13 +++++++++++-- .../Registration/RegistrationServiceTest.php | 7 ++++++- 6 files changed, 73 insertions(+), 9 deletions(-) diff --git a/src/BusinessLogic/Http/DTO/Draft.php b/src/BusinessLogic/Http/DTO/Draft.php index c2593af7..30988f96 100644 --- a/src/BusinessLogic/Http/DTO/Draft.php +++ b/src/BusinessLogic/Http/DTO/Draft.php @@ -3,6 +3,8 @@ namespace Packlink\BusinessLogic\Http\DTO; use Logeecom\Infrastructure\Data\DataTransferObject; +use Logeecom\Infrastructure\ServiceRegister; +use Packlink\BusinessLogic\Brand\BrandConfigurationService; use Packlink\BusinessLogic\Http\DTO\Draft\AdditionalData; use Packlink\BusinessLogic\Http\DTO\Draft\Address; use Packlink\BusinessLogic\Http\DTO\Draft\DraftPrice; @@ -31,7 +33,7 @@ class Draft extends DataTransferObject * * @var string */ - public $platform = 'PRO'; + public $platform; /** * Unique platform country identifier. * @@ -148,6 +150,17 @@ class Draft extends DataTransferObject */ public $price; + /** + * Draft constructor. + */ + public function __construct() + { + /** @var BrandConfigurationService $service */ + $service = ServiceRegister::getService(BrandConfigurationService::CLASS_NAME); + + $this->platform = $service->get()->platformCode; + } + /** * Transforms DTO to its array format suitable for http client. * diff --git a/src/BusinessLogic/Http/Proxy.php b/src/BusinessLogic/Http/Proxy.php index c59904a5..77188b6c 100644 --- a/src/BusinessLogic/Http/Proxy.php +++ b/src/BusinessLogic/Http/Proxy.php @@ -8,6 +8,8 @@ use Logeecom\Infrastructure\Http\HttpClient; use Logeecom\Infrastructure\Http\HttpResponse; use Logeecom\Infrastructure\Logger\Logger; +use Logeecom\Infrastructure\ServiceRegister; +use Packlink\BusinessLogic\Brand\BrandConfigurationService; use Packlink\BusinessLogic\Configuration; use Packlink\BusinessLogic\DTO\FrontDtoFactory; use Packlink\BusinessLogic\Http\DTO\Analytics; @@ -199,9 +201,11 @@ public function getLocations($serviceId, $countryCode, $postalCode) */ public function searchLocations($platformCountry, $postalZone, $query) { + $brand = $this->getBrandConfigurationService()->get(); + $url = 'locations/postalcodes?' . http_build_query( array( - 'platform' => 'PRO', + 'platform' => $brand->platformCode, 'platform_country' => $platformCountry, 'postalzone' => $postalZone, 'q' => $query, @@ -245,9 +249,11 @@ public function getPostalCodes($countryCode, $zipCode) */ public function getPostalZones($countryCode, $lang = 'en') { + $brand = $this->getBrandConfigurationService()->get(); + $url = 'locations/postalzones/destinations?' . http_build_query( array( - 'platform' => 'PRO', + 'platform' => $brand->platformCode, 'platform_country' => $countryCode, 'language' => $lang, ) @@ -552,4 +558,13 @@ private function getRequestHeaders() 'Ecommerce-Version' => 'X-Ecommerce-Version: ' . $this->configService->getECommerceVersion(), ); } + + /** + * @return BrandConfigurationService + */ + private function getBrandConfigurationService() + { + /** @noinspection PhpIncompatibleReturnTypeInspection */ + return ServiceRegister::getService(BrandConfigurationService::CLASS_NAME); + } } diff --git a/src/BusinessLogic/Registration/RegistrationRequest.php b/src/BusinessLogic/Registration/RegistrationRequest.php index 779ace9f..d0cc5a0f 100644 --- a/src/BusinessLogic/Registration/RegistrationRequest.php +++ b/src/BusinessLogic/Registration/RegistrationRequest.php @@ -2,6 +2,8 @@ namespace Packlink\BusinessLogic\Registration; +use Logeecom\Infrastructure\ServiceRegister; +use Packlink\BusinessLogic\Brand\BrandConfigurationService; use Packlink\BusinessLogic\DTO\FrontDto; use Packlink\BusinessLogic\DTO\ValidationError; use Packlink\BusinessLogic\Language\Translator; @@ -54,7 +56,7 @@ class RegistrationRequest extends FrontDto */ public $language; /** - * Platform (only supported platform is "PRO"). + * Platform. * * @var string */ @@ -257,12 +259,23 @@ protected static function doValidate(array $payload, array &$validationErrors) static::setInvalidFieldError('source', $validationErrors, Translator::translate('validation.invalidUrl')); } - if (!empty($payload['platform']) && $payload['platform'] !== 'PRO') { + $brand = static::getBrandConfigurationService()->get(); + + if (!empty($payload['platform']) && $payload['platform'] !== $brand->platformCode) { static::setInvalidFieldError( 'platform', $validationErrors, - Translator::translate('validation.invalidFieldValue', array('PRO')) + Translator::translate('validation.invalidFieldValue', array($brand->platformCode)) ); } } + + /** + * @return BrandConfigurationService + */ + private static function getBrandConfigurationService() + { + /** @noinspection PhpIncompatibleReturnTypeInspection */ + return ServiceRegister::getService(BrandConfigurationService::CLASS_NAME); + } } diff --git a/tests/BusinessLogic/Common/BaseTestWithServices.php b/tests/BusinessLogic/Common/BaseTestWithServices.php index e469e3da..a609e93e 100644 --- a/tests/BusinessLogic/Common/BaseTestWithServices.php +++ b/tests/BusinessLogic/Common/BaseTestWithServices.php @@ -17,6 +17,8 @@ use Logeecom\Tests\Infrastructure\Common\TestComponents\TaskExecution\TestTaskRunnerWakeupService; use Logeecom\Tests\Infrastructure\Common\TestComponents\TestHttpClient; use Logeecom\Tests\Infrastructure\Common\TestServiceRegister; +use Packlink\Brands\Packlink\PacklinkConfigurationService; +use Packlink\BusinessLogic\Brand\BrandConfigurationService; use Packlink\BusinessLogic\Country\Country; use Packlink\BusinessLogic\Country\CountryService; use Packlink\BusinessLogic\Country\RegistrationCountry; @@ -121,6 +123,13 @@ function () { } ); + TestServiceRegister::registerService( + BrandConfigurationService::CLASS_NAME, + function () { + return new PacklinkConfigurationService(); + } + ); + TestRepositoryRegistry::registerRepository(QueueItem::CLASS_NAME, MemoryQueueItemRepository::THIS_CLASS_NAME); TestFrontDtoFactory::register(Warehouse::CLASS_KEY, TestWarehouse::CLASS_NAME); diff --git a/tests/BusinessLogic/Registration/RegistrationRequestDtoTest.php b/tests/BusinessLogic/Registration/RegistrationRequestDtoTest.php index 2f17f4ce..417159df 100644 --- a/tests/BusinessLogic/Registration/RegistrationRequestDtoTest.php +++ b/tests/BusinessLogic/Registration/RegistrationRequestDtoTest.php @@ -3,6 +3,8 @@ namespace BusinessLogic\Registration; use Logeecom\Tests\BusinessLogic\Dto\BaseDtoTest; +use Logeecom\Tests\Infrastructure\Common\TestServiceRegister; +use Packlink\BusinessLogic\Brand\BrandConfigurationService; use Packlink\BusinessLogic\DTO\Exceptions\FrontDtoValidationException; use Packlink\BusinessLogic\Registration\RegistrationRequest; @@ -19,12 +21,15 @@ class RegistrationRequestDtoTest extends BaseDtoTest public function testValidRegistrationRequest() { $request = RegistrationRequest::fromArray($this->getRequest()); + /** @var BrandConfigurationService $brandConfigurationService */ + $brandConfigurationService = TestServiceRegister::getService(BrandConfigurationService::CLASS_NAME); + $brand = $brandConfigurationService->get(); self::assertEquals('john.doe@example.com', $request->email); self::assertEquals('test1234', $request->password); self::assertEquals('(024) 418 52 52', $request->phone); self::assertEquals('1 - 10', $request->estimatedDeliveryVolume); - self::assertEquals('PRO', $request->platform); + self::assertEquals($brand->platformCode, $request->platform); self::assertEquals('de_DE', $request->language); self::assertEquals('UN', $request->platformCountry); self::assertEquals('http://example.com', $request->source); @@ -144,12 +149,16 @@ function ($error) { */ private function getRequest() { + /** @var BrandConfigurationService $brandConfigurationService */ + $brandConfigurationService = TestServiceRegister::getService(BrandConfigurationService::CLASS_NAME); + $brand = $brandConfigurationService->get(); + return array( 'email' => 'john.doe@example.com', 'password' => 'test1234', 'phone' => '(024) 418 52 52', 'estimated_delivery_volume' => '1 - 10', - 'platform' => 'PRO', + 'platform' => $brand->platformCode, 'language' => 'de_DE', 'platform_country' => 'UN', 'policies' => array( diff --git a/tests/BusinessLogic/Registration/RegistrationServiceTest.php b/tests/BusinessLogic/Registration/RegistrationServiceTest.php index 940821a5..ea265af3 100644 --- a/tests/BusinessLogic/Registration/RegistrationServiceTest.php +++ b/tests/BusinessLogic/Registration/RegistrationServiceTest.php @@ -6,6 +6,7 @@ use Logeecom\Infrastructure\ServiceRegister; use Logeecom\Tests\BusinessLogic\Common\BaseTestWithServices; use Logeecom\Tests\Infrastructure\Common\TestServiceRegister; +use Packlink\BusinessLogic\Brand\BrandConfigurationService; use Packlink\BusinessLogic\Registration\Exceptions\UnableToRegisterAccountException; use Packlink\BusinessLogic\Registration\RegistrationRequest; use Packlink\BusinessLogic\Registration\RegistrationService; @@ -105,13 +106,17 @@ function () { */ private function getRequest() { + /** @var BrandConfigurationService $brandConfigurationService */ + $brandConfigurationService = ServiceRegister::getService(BrandConfigurationService::CLASS_NAME); + $brand = $brandConfigurationService->get(); + return RegistrationRequest::fromArray( array( 'email' => 'john.doe@example.com', 'password' => 'test1234', 'phone' => '(024) 418 52 52', 'estimated_delivery_volume' => '1 - 10', - 'platform' => 'PRO', + 'platform' => $brand->platformCode, 'language' => 'de_DE', 'platform_country' => 'UN', 'policies' => array( From 96b17f5cc61f4d8bf3b06d691e323462031feacf Mon Sep 17 00:00:00 2001 From: marija Date: Fri, 26 Feb 2021 14:26:39 +0100 Subject: [PATCH 04/37] Refactor Registration to eliminate hardcoded platform country code PLCR24-10 --- .../Controllers/RegistrationController.php | 23 +++++++++++++++++++ .../Resources/js/RegisterController.js | 10 ++++---- .../Resources/js/RegisterModalController.js | 2 +- src/DemoUI/composer.json | 3 ++- .../RegistrationControllerTest.php | 3 ++- 5 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/BusinessLogic/Controllers/RegistrationController.php b/src/BusinessLogic/Controllers/RegistrationController.php index 40715e61..c617f118 100644 --- a/src/BusinessLogic/Controllers/RegistrationController.php +++ b/src/BusinessLogic/Controllers/RegistrationController.php @@ -4,6 +4,7 @@ use Logeecom\Infrastructure\Configuration\Configuration; use Logeecom\Infrastructure\ServiceRegister; +use Packlink\BusinessLogic\Brand\BrandConfigurationService; use Packlink\BusinessLogic\DTO\FrontDtoFactory; use Packlink\BusinessLogic\Registration\RegistrationInfoService; use Packlink\BusinessLogic\Registration\RegistrationRequest; @@ -20,6 +21,10 @@ class RegistrationController * @var Configuration */ protected $configService; + /** + * @var BrandConfigurationService + */ + protected $brandConfigurationService; /** * List of terms and conditions URLs for different country codes. * @@ -74,6 +79,8 @@ public function getRegisterData($country) $registrationInfoService = ServiceRegister::getService(RegistrationInfoService::CLASS_NAME); $registrationData = $registrationInfoService->getRegistrationInfoData(); + $brand = $this->getBrandConfigurationService()->get(); + return array( 'context' => $this->getConfigService()->getContext(), 'email' => $registrationData->getEmail(), @@ -83,6 +90,8 @@ public function getRegisterData($country) self::$termsAndConditionsUrls[$country] : self::$termsAndConditionsUrls[self::DEFAULT_COUNTRY], 'privacyPolicyUrl' => !empty(self::$privacyPolicyUrls[$country]) ? self::$privacyPolicyUrls[$country] : self::$privacyPolicyUrls[self::DEFAULT_COUNTRY], + 'platform_country' => in_array($country, $brand->platformCountries, true) ? + $country : $brand->platformCountries[0], ); } @@ -151,6 +160,20 @@ protected function getConfigService() return $this->configService; } + /** + * Returns an instance of brand configuration service. + * + * @return BrandConfigurationService + */ + protected function getBrandConfigurationService() + { + if ($this->brandConfigurationService === null) { + $this->brandConfigurationService = ServiceRegister::getService(BrandConfigurationService::CLASS_NAME); + } + + return $this->brandConfigurationService; + } + /** * Returns shop language in format which Packlink expects. * diff --git a/src/BusinessLogic/Resources/js/RegisterController.js b/src/BusinessLogic/Resources/js/RegisterController.js index 7ae525f5..4da6b48a 100644 --- a/src/BusinessLogic/Resources/js/RegisterController.js +++ b/src/BusinessLogic/Resources/js/RegisterController.js @@ -42,9 +42,6 @@ if (!window.Packlink) { templateService.getComponent('pl-go-to-login', registerPage).addEventListener('click', goToLogin); - templateService.getComponent('pl-register-platform-country', registerPage).value = - additionalConfig.hasOwnProperty('platform_country') ? additionalConfig.platform_country : 'ES'; - initInputField('pl-register-email'); initInputField('pl-register-password'); initInputField('pl-register-phone'); @@ -60,17 +57,20 @@ if (!window.Packlink) { * phone: string, * source: string, * termsAndConditionsUrl: string, - * privacyPolicyUrl: string + * privacyPolicyUrl: string, + * platform_country: string * }} response */ const populateInitialValues = (response) => { const emailInput = templateService.getComponent('pl-register-email'), phoneInput = templateService.getComponent('pl-register-phone'), - sourceInput = templateService.getComponent('pl-register-source'); + sourceInput = templateService.getComponent('pl-register-source'), + platformCountry = templateService.getComponent('pl-register-platform-country'); emailInput.value = response.email; phoneInput.value = response.phone; sourceInput.value = response.source; + platformCountry.value = response.platform_country; let termsAndConditionsLabel = templateService.getComponent('pl-register-terms-and-conditions-label'), termsTranslation = translationService.translate( diff --git a/src/BusinessLogic/Resources/js/RegisterModalController.js b/src/BusinessLogic/Resources/js/RegisterModalController.js index 6fec3cfe..c3d13fef 100644 --- a/src/BusinessLogic/Resources/js/RegisterModalController.js +++ b/src/BusinessLogic/Resources/js/RegisterModalController.js @@ -73,7 +73,7 @@ if (!window.Packlink) { */ const handleCountrySelected = (country) => { modal.close(); - Packlink.state.goToState('register', {country: country.code, platform_country: country.platform_country}); + Packlink.state.goToState('register', {country: country.code}); }; /** diff --git a/src/DemoUI/composer.json b/src/DemoUI/composer.json index cbfaddbc..880ec775 100755 --- a/src/DemoUI/composer.json +++ b/src/DemoUI/composer.json @@ -12,7 +12,8 @@ "Logeecom\\Tests\\": "../../tests", "Packlink\\BusinessLogic\\": "../BusinessLogic", "Packlink\\DemoUI\\Lib\\": "Lib", - "Packlink\\DemoUI\\": "src" + "Packlink\\DemoUI\\": "src", + "Packlink\\Brands\\": "../Brands" } }, "scripts": { diff --git a/tests/BusinessLogic/Controllers/RegistrationControllerTest.php b/tests/BusinessLogic/Controllers/RegistrationControllerTest.php index ea006927..c317feb9 100644 --- a/tests/BusinessLogic/Controllers/RegistrationControllerTest.php +++ b/tests/BusinessLogic/Controllers/RegistrationControllerTest.php @@ -44,10 +44,11 @@ function () { public function testGetRegisterData() { - $data = $this->registrationController->getRegisterData('ES'); + $data = $this->registrationController->getRegisterData('FR'); $this->assertEquals('test@test.com', $data['email']); $this->assertEquals('1111111111111', $data['phone']); $this->assertEquals('localhost:7000', $data['source']); + $this->assertEquals('FR', $data['platform_country']); } } From fe48e34490f49e5aa7e80f28edcd20eec12151fa Mon Sep 17 00:00:00 2001 From: marija Date: Fri, 26 Feb 2021 15:07:04 +0100 Subject: [PATCH 05/37] Remove obsolete registration link and platform country from CountryService PLCR24-11 --- src/BusinessLogic/BootstrapComponent.php | 2 - src/BusinessLogic/Country/CountryService.php | 38 +------- .../Country/RegistrationCountry.php | 96 ------------------- .../Resources/js/RegisterModalController.js | 4 +- .../Common/BaseTestWithServices.php | 2 - .../Dto/TestRegistrationCountry.php | 27 ------ .../Country/CountryServiceTest.php | 4 - .../Country/RegistrationCountryDtoTest.php | 70 -------------- 8 files changed, 3 insertions(+), 240 deletions(-) delete mode 100644 src/BusinessLogic/Country/RegistrationCountry.php delete mode 100644 tests/BusinessLogic/Common/TestComponents/Dto/TestRegistrationCountry.php delete mode 100644 tests/BusinessLogic/Country/RegistrationCountryDtoTest.php diff --git a/src/BusinessLogic/BootstrapComponent.php b/src/BusinessLogic/BootstrapComponent.php index 4fb94eaa..12deb1c0 100644 --- a/src/BusinessLogic/BootstrapComponent.php +++ b/src/BusinessLogic/BootstrapComponent.php @@ -12,7 +12,6 @@ use Packlink\BusinessLogic\Controllers\ShippingMethodController; use Packlink\BusinessLogic\Country\Country; use Packlink\BusinessLogic\Country\CountryService; -use Packlink\BusinessLogic\Country\RegistrationCountry; use Packlink\BusinessLogic\Country\WarehouseCountryService; use Packlink\BusinessLogic\DTO\FrontDtoFactory; use Packlink\BusinessLogic\DTO\ValidationError; @@ -217,7 +216,6 @@ protected static function initDtoRegistry() FrontDtoFactory::register(ParcelInfo::CLASS_KEY, ParcelInfo::CLASS_NAME); FrontDtoFactory::register(DashboardStatus::CLASS_KEY, DashboardStatus::CLASS_NAME); FrontDtoFactory::register(Country::CLASS_KEY, Country::CLASS_NAME); - FrontDtoFactory::register(RegistrationCountry::CLASS_KEY, RegistrationCountry::CLASS_NAME); FrontDtoFactory::register(RegistrationRequest::CLASS_KEY, RegistrationRequest::CLASS_NAME); FrontDtoFactory::register(RegistrationLegalPolicy::CLASS_KEY, RegistrationLegalPolicy::CLASS_NAME); FrontDtoFactory::register(ShippingPricePolicy::CLASS_KEY, ShippingPricePolicy::CLASS_NAME); diff --git a/src/BusinessLogic/Country/CountryService.php b/src/BusinessLogic/Country/CountryService.php index 1f7166d2..5ed84c5e 100644 --- a/src/BusinessLogic/Country/CountryService.php +++ b/src/BusinessLogic/Country/CountryService.php @@ -2,9 +2,7 @@ namespace Packlink\BusinessLogic\Country; -use Logeecom\Infrastructure\ServiceRegister; use Packlink\BusinessLogic\BaseService; -use Packlink\BusinessLogic\Configuration; use Packlink\BusinessLogic\DTO\FrontDtoFactory; use Packlink\BusinessLogic\Language\Translator; @@ -41,85 +39,61 @@ class CountryService extends BaseService 'name' => 'Spain', 'code' => 'ES', 'postal_code' => '28001', - 'registration_link' => 'https://auth.packlink.com/es-ES/{integration}/registro', - 'platform_country' => 'ES', ), 'DE' => array( 'name' => 'Germany', 'code' => 'DE', 'postal_code' => '10115', - 'registration_link' => 'https://auth.packlink.com/de-DE/{integration}/registrieren', - 'platform_country' => 'DE', ), 'FR' => array( 'name' => 'France', 'code' => 'FR', 'postal_code' => '75001', - 'registration_link' => 'https://auth.packlink.com/fr-FR/{integration}/inscription', - 'platform_country' => 'FR', ), 'IT' => array( 'name' => 'Italy', 'code' => 'IT', 'postal_code' => '00118', - 'registration_link' => 'https://auth.packlink.com/it-IT/{integration}/registro', - 'platform_country' => 'IT', ), 'AT' => array( 'name' => 'Austria', 'code' => 'AT', 'postal_code' => '1010', - 'registration_link' => 'https://auth.packlink.com/de-DE/{integration}/registrieren', - 'platform_country' => 'UN', ), 'NL' => array( 'name' => 'Netherlands', 'code' => 'NL', 'postal_code' => '1011', - 'registration_link' => 'https://auth.packlink.com/nl-NL/{integration}/registrieren', - 'platform_country' => 'UN', ), 'BE' => array( 'name' => 'Belgium', 'code' => 'BE', 'postal_code' => '1000', - 'registration_link' => 'https://auth.packlink.com/nl-NL/{integration}/registrieren', - 'platform_country' => 'UN', ), 'PT' => array( 'name' => 'Portugal', 'code' => 'PT', 'postal_code' => '1000-017', - 'registration_link' => 'https://auth.packlink.com/pt-PT/{integration}/registo', - 'platform_country' => 'UN', ), 'TR' => array( 'name' => 'Turkey', 'code' => 'TR', 'postal_code' => '06010', - 'registration_link' => 'https://auth.packlink.com/tr-TR/{integration}/kayıt-yap', - 'platform_country' => 'UN', ), 'IE' => array( 'name' => 'Ireland', 'code' => 'IE', 'postal_code' => 'D1', - 'registration_link' => 'https://auth.packlink.com/en-GB/{integration}/register', - 'platform_country' => 'UN', ), 'GB' => array( 'name' => 'United Kingdom', 'code' => 'GB', 'postal_code' => 'E1 6AN', - 'registration_link' => 'https://auth.packlink.com/en-GB/{integration}/register?platform_country=UN', - 'platform_country' => 'UN', ), 'HU' => array( 'name' => 'Hungary', 'code' => 'HU', 'postal_code' => '1014', - 'registration_link' => 'https://auth.packlink.com/hu-HU/{integration}/regisztracio?platform_country=UN', - 'platform_country' => 'UN', ), ); @@ -140,7 +114,7 @@ public function isBaseCountry($countryCode) * * @param bool $associative Indicates whether the result should be an associative array. * - * @return RegistrationCountry[] + * @return Country[] * * @noinspection PhpUnhandledExceptionInspection * @noinspection PhpDocMissingThrowsInspection @@ -148,18 +122,10 @@ public function isBaseCountry($countryCode) public function getSupportedCountries($associative = true) { $countries = array(); - $configuration = ServiceRegister::getService(Configuration::CLASS_NAME); foreach (static::$supportedCountries as $country) { - $integration = strtolower($configuration->getIntegrationName()); - $country['registration_link'] = str_replace( - '{integration}', - $integration, - $country['registration_link'] - ) . '?platform=PRO&platform_country=' . $country['platform_country']; - $country['name'] = Translator::translate('countries.' . $country['code']); - $countries[$country['code']] = FrontDtoFactory::get(RegistrationCountry::CLASS_KEY, $country); + $countries[$country['code']] = FrontDtoFactory::get(Country::CLASS_KEY, $country); } return $associative ? $countries : array_values($countries); diff --git a/src/BusinessLogic/Country/RegistrationCountry.php b/src/BusinessLogic/Country/RegistrationCountry.php deleted file mode 100644 index 8a5495e0..00000000 --- a/src/BusinessLogic/Country/RegistrationCountry.php +++ /dev/null @@ -1,96 +0,0 @@ -registrationLink = static::getDataValue($raw, 'registration_link'); - $instance->platformCountry = static::getDataValue($raw, 'platform_country'); - - return $instance; - } - - /** - * Transforms DTO to its array format. - * - * @return array DTO in array format. - */ - public function toArray() - { - return array_merge( - parent::toArray(), - array( - 'registration_link' => $this->registrationLink, - 'platform_country' => $this->platformCountry, - ) - ); - } -} diff --git a/src/BusinessLogic/Resources/js/RegisterModalController.js b/src/BusinessLogic/Resources/js/RegisterModalController.js index c3d13fef..92e1a095 100644 --- a/src/BusinessLogic/Resources/js/RegisterModalController.js +++ b/src/BusinessLogic/Resources/js/RegisterModalController.js @@ -10,9 +10,7 @@ if (!window.Packlink) { * @typedef {{ * name: string, * code: string, - * postal_code: string, - * registration_link: string, - * platform_country: string + * postal_code: string * }} Country */ diff --git a/tests/BusinessLogic/Common/BaseTestWithServices.php b/tests/BusinessLogic/Common/BaseTestWithServices.php index a609e93e..eed38e65 100644 --- a/tests/BusinessLogic/Common/BaseTestWithServices.php +++ b/tests/BusinessLogic/Common/BaseTestWithServices.php @@ -21,7 +21,6 @@ use Packlink\BusinessLogic\Brand\BrandConfigurationService; use Packlink\BusinessLogic\Country\Country; use Packlink\BusinessLogic\Country\CountryService; -use Packlink\BusinessLogic\Country\RegistrationCountry; use Packlink\BusinessLogic\Country\WarehouseCountryService; use Packlink\BusinessLogic\DTO\ValidationError; use Packlink\BusinessLogic\Http\DTO\ParcelInfo; @@ -136,7 +135,6 @@ function () { TestFrontDtoFactory::register(ParcelInfo::CLASS_KEY, ParcelInfo::CLASS_NAME); TestFrontDtoFactory::register(ValidationError::CLASS_KEY, ValidationError::CLASS_NAME); TestFrontDtoFactory::register(Country::CLASS_KEY, Country::CLASS_NAME); - TestFrontDtoFactory::register(RegistrationCountry::CLASS_KEY, RegistrationCountry::CLASS_NAME); } protected function tearDown() diff --git a/tests/BusinessLogic/Common/TestComponents/Dto/TestRegistrationCountry.php b/tests/BusinessLogic/Common/TestComponents/Dto/TestRegistrationCountry.php deleted file mode 100644 index 1c049f0a..00000000 --- a/tests/BusinessLogic/Common/TestComponents/Dto/TestRegistrationCountry.php +++ /dev/null @@ -1,27 +0,0 @@ -name = 'Cuba'; - $this->code = 'CU'; - $this->postalCode = '10400'; - $this->registrationLink = 'https://pro.packlink.com/register'; - $this->platformCountry = 'UN'; - } -} diff --git a/tests/BusinessLogic/Country/CountryServiceTest.php b/tests/BusinessLogic/Country/CountryServiceTest.php index 66414f23..c99b973e 100644 --- a/tests/BusinessLogic/Country/CountryServiceTest.php +++ b/tests/BusinessLogic/Country/CountryServiceTest.php @@ -26,9 +26,5 @@ public function testGetSupportedCountries() $this->assertEquals('Spain', $countries['ES']->name); $this->assertEquals('ES', $countries['ES']->code); $this->assertEquals('28001', $countries['ES']->postalCode); - $this->assertEquals( - 'https://auth.packlink.com/es-ES/test-system/registro?platform=PRO&platform_country=ES', - $countries['ES']->registrationLink - ); } } diff --git a/tests/BusinessLogic/Country/RegistrationCountryDtoTest.php b/tests/BusinessLogic/Country/RegistrationCountryDtoTest.php deleted file mode 100644 index 2854db06..00000000 --- a/tests/BusinessLogic/Country/RegistrationCountryDtoTest.php +++ /dev/null @@ -1,70 +0,0 @@ - array( - 'name' => 'Germany', - 'code' => 'DE', - 'postal_code' => '10115', - 'registration_link' => 'https://pro.packlink.de/registrieren', - 'platform_country' => 'DE', - ), - 'nl' => array( - 'name' => 'Netherlands', - 'code' => 'NL', - 'postal_code' => '1011', - 'registration_link' => 'https://pro.packlink.com/register', - 'platform_country' => 'UN', - ), - ); - - /** @var RegistrationCountry[] $countries */ - $countries = TestFrontDtoFactory::getFromBatch(RegistrationCountry::CLASS_KEY, $data); - $this->assertCount(2, $countries); - - $this->assertEquals('Germany', $countries['de']->name); - $this->assertEquals('DE', $countries['de']->code); - $this->assertEquals('10115', $countries['de']->postalCode); - $this->assertEquals('https://pro.packlink.de/registrieren', $countries['de']->registrationLink); - $this->assertEquals('DE', $countries['de']->platformCountry); - - $this->assertEquals('Netherlands', $countries['nl']->name); - $this->assertEquals('NL', $countries['nl']->code); - $this->assertEquals('1011', $countries['nl']->postalCode); - $this->assertEquals('https://pro.packlink.com/register', $countries['nl']->registrationLink); - $this->assertEquals('UN', $countries['nl']->platformCountry); - } - - public function testToArray() - { - $country = new TestRegistrationCountry(); - - $data = $country->toArray(); - $this->assertArrayHasKey('name', $data); - $this->assertArrayHasKey('code', $data); - $this->assertArrayHasKey('postal_code', $data); - $this->assertArrayHasKey('registration_link', $data); - $this->assertArrayHasKey('platform_country', $data); - } -} From 3ab46190aeab4877b5ff1647e7461ce4a39973e6 Mon Sep 17 00:00:00 2001 From: marija Date: Mon, 1 Mar 2021 10:18:24 +0100 Subject: [PATCH 06/37] Refactor login/registration validation to check country code PLCR24-12 --- ...ormCountryNotSupportedByBrandException.php | 16 ++++++++++ .../Controllers/RegistrationController.php | 5 +++- .../Registration/RegistrationRequest.php | 6 ++-- src/BusinessLogic/User/UserAccountService.php | 30 +++++++++++++++++++ .../ApiResponses/userUnsupportedCountry.json | 27 +++++++++++++++++ .../User/UserAccountLoginTest.php | 25 ++++++++++++++-- 6 files changed, 103 insertions(+), 6 deletions(-) create mode 100644 src/BusinessLogic/Brand/Exceptions/PlatformCountryNotSupportedByBrandException.php create mode 100644 tests/BusinessLogic/Common/ApiResponses/userUnsupportedCountry.json diff --git a/src/BusinessLogic/Brand/Exceptions/PlatformCountryNotSupportedByBrandException.php b/src/BusinessLogic/Brand/Exceptions/PlatformCountryNotSupportedByBrandException.php new file mode 100644 index 00000000..e3447abc --- /dev/null +++ b/src/BusinessLogic/Brand/Exceptions/PlatformCountryNotSupportedByBrandException.php @@ -0,0 +1,16 @@ +getBrandConfigurationService()->get(); + + $payload['platform'] = $brand->platformCode; $payload['language'] = $this->getLanguage(); if (isset($payload['source'])) { diff --git a/src/BusinessLogic/Registration/RegistrationRequest.php b/src/BusinessLogic/Registration/RegistrationRequest.php index d0cc5a0f..9805e1cd 100644 --- a/src/BusinessLogic/Registration/RegistrationRequest.php +++ b/src/BusinessLogic/Registration/RegistrationRequest.php @@ -211,6 +211,8 @@ protected static function doValidate(array $payload, array &$validationErrors) { parent::doValidate($payload, $validationErrors); + $brand = static::getBrandConfigurationService()->get(); + if (!empty($payload['email']) && !DtoValidator::isEmailValid($payload['email'])) { static::setInvalidFieldError('email', $validationErrors, Translator::translate('validation.invalidEmail')); } @@ -246,7 +248,7 @@ protected static function doValidate(array $payload, array &$validationErrors) } if (!empty($payload['platform_country']) - && !in_array($payload['platform_country'], static::$supportedPlatformCountries, true) + && !in_array($payload['platform_country'], $brand->platformCountries, true) ) { static::setInvalidFieldError( 'platform_country', @@ -259,8 +261,6 @@ protected static function doValidate(array $payload, array &$validationErrors) static::setInvalidFieldError('source', $validationErrors, Translator::translate('validation.invalidUrl')); } - $brand = static::getBrandConfigurationService()->get(); - if (!empty($payload['platform']) && $payload['platform'] !== $brand->platformCode) { static::setInvalidFieldError( 'platform', diff --git a/src/BusinessLogic/User/UserAccountService.php b/src/BusinessLogic/User/UserAccountService.php index d5f92237..60173890 100644 --- a/src/BusinessLogic/User/UserAccountService.php +++ b/src/BusinessLogic/User/UserAccountService.php @@ -9,6 +9,8 @@ use Logeecom\Infrastructure\ServiceRegister; use Logeecom\Infrastructure\TaskExecution\QueueService; use Packlink\BusinessLogic\BaseService; +use Packlink\BusinessLogic\Brand\BrandConfigurationService; +use Packlink\BusinessLogic\Brand\Exceptions\PlatformCountryNotSupportedByBrandException; use Packlink\BusinessLogic\Configuration; use Packlink\BusinessLogic\Country\WarehouseCountryService; use Packlink\BusinessLogic\Http\DTO\Analytics; @@ -47,6 +49,12 @@ class UserAccountService extends BaseService * @var Proxy */ private $proxy; + /** + * BrandConfigurationService instance. + * + * @var BrandConfigurationService + */ + private $brandConfigurationService; /** * Validates provided API key and initializes user's data. @@ -57,6 +65,7 @@ class UserAccountService extends BaseService * * @throws \Logeecom\Infrastructure\ORM\Exceptions\RepositoryNotRegisteredException * @throws \Logeecom\Infrastructure\TaskExecution\Exceptions\QueueStorageUnavailableException + * @throws PlatformCountryNotSupportedByBrandException */ public function login($apiKey) { @@ -159,9 +168,16 @@ public function setWarehouseInfo($force) * @throws \Logeecom\Infrastructure\Http\Exceptions\HttpCommunicationException * @throws \Logeecom\Infrastructure\Http\Exceptions\HttpRequestException * @throws \Logeecom\Infrastructure\TaskExecution\Exceptions\QueueStorageUnavailableException + * @throws PlatformCountryNotSupportedByBrandException */ protected function initializeUser(User $user) { + $brand = $this->getBrandConfigurationService()->get(); + + if (!in_array($user->country, $brand->platformCountries, true)) { + throw new PlatformCountryNotSupportedByBrandException('Platform country not supported by brand!'); + } + $this->getConfigService()->setUserInfo($user); $defaultQueueName = $this->getConfigService()->getDefaultQueueName(); @@ -268,4 +284,18 @@ protected function getConfigService() return $this->configuration; } + + /** + * Returns an instance of brand configuration service. + * + * @return BrandConfigurationService + */ + protected function getBrandConfigurationService() + { + if ($this->brandConfigurationService === null) { + $this->brandConfigurationService = ServiceRegister::getService(BrandConfigurationService::CLASS_NAME); + } + + return $this->brandConfigurationService; + } } diff --git a/tests/BusinessLogic/Common/ApiResponses/userUnsupportedCountry.json b/tests/BusinessLogic/Common/ApiResponses/userUnsupportedCountry.json new file mode 100644 index 00000000..4b0f3cc8 --- /dev/null +++ b/tests/BusinessLogic/Common/ApiResponses/userUnsupportedCountry.json @@ -0,0 +1,27 @@ +{ + "active": true, + "name": "first name", + "surname": "last name", + "company_name": "my company", + "email": "email@address.com", + "address": null, + "address2": null, + "city": null, + "state": null, + "platform_country": "AT", + "location": null, + "postal_code": null, + "phone": "+38163645336", + "debtor": false, + "estimated_deliveries_volume": "11 - 50", + "tax_id": null, + "marketplaces": [], + "ecommerces": [], + "created_at": 1544009477294, + "updated_at": 1544009477388, + "customer_type": "OTHERS", + "deregistration_date": null, + "direct_debit_requested": false, + "deferred_payment_blocked": false, + "referral": null +} \ No newline at end of file diff --git a/tests/BusinessLogic/User/UserAccountLoginTest.php b/tests/BusinessLogic/User/UserAccountLoginTest.php index 8229c6e9..f1d006e7 100644 --- a/tests/BusinessLogic/User/UserAccountLoginTest.php +++ b/tests/BusinessLogic/User/UserAccountLoginTest.php @@ -2,6 +2,7 @@ namespace Logeecom\Tests\BusinessLogic\User; +use Logeecom\Infrastructure\Exceptions\BaseException; use Logeecom\Infrastructure\Http\HttpResponse; use Logeecom\Infrastructure\ORM\RepositoryRegistry; use Logeecom\Infrastructure\TaskExecution\Interfaces\TaskRunnerWakeup; @@ -150,6 +151,23 @@ public function testLogin() $this->assertEmpty($expectedSchedules); } + /** + * Test user login when platform country is not supported. + */ + public function testLoginNotSupportedCountry() + { + $exceptionThrown = false; + $this->httpClient->setMockResponses($this->getMockResponses(true, true, false)); + + try { + $this->assertTrue($this->userAccountService->login('GoodApiKey')); + } catch (BaseException $e) { + $exceptionThrown = true; + } + + $this->assertTrue($exceptionThrown); + } + /** * Tests user login and user initialization * @@ -200,14 +218,17 @@ public function testLoginNoWarehouse() * * @param bool $parcel If parcel info should be set. * @param bool $warehouse If warehouse info should be set. + * @param bool $supportedCountry If response with supported or unsupported country should be set. * * @return HttpResponse[] Array of Http responses. */ - private function getMockResponses($parcel = true, $warehouse = true) + private function getMockResponses($parcel = true, $warehouse = true, $supportedCountry = true) { return array( new HttpResponse( - 200, array(), file_get_contents(__DIR__ . '/../Common/ApiResponses/user.json') + 200, array(), $supportedCountry ? + file_get_contents(__DIR__ . '/../Common/ApiResponses/user.json') : + file_get_contents(__DIR__ . '/../Common/ApiResponses/userUnsupportedCountry.json') ), new HttpResponse( 200, array(), $parcel ? file_get_contents(__DIR__ . '/../Common/ApiResponses/parcels.json') : '' From 28be84806d1a5e54201613884afcc4c0cbf011b6 Mon Sep 17 00:00:00 2001 From: marija Date: Mon, 1 Mar 2021 10:48:34 +0100 Subject: [PATCH 07/37] Replace hardcoded registration and warehouse countries PLCR24-13 --- src/BusinessLogic/Country/CountryService.php | 90 +++++-------------- .../Country/WarehouseCountryService.php | 63 +------------ 2 files changed, 27 insertions(+), 126 deletions(-) diff --git a/src/BusinessLogic/Country/CountryService.php b/src/BusinessLogic/Country/CountryService.php index 5ed84c5e..2da96846 100644 --- a/src/BusinessLogic/Country/CountryService.php +++ b/src/BusinessLogic/Country/CountryService.php @@ -2,7 +2,9 @@ namespace Packlink\BusinessLogic\Country; +use Logeecom\Infrastructure\ServiceRegister; use Packlink\BusinessLogic\BaseService; +use Packlink\BusinessLogic\Brand\BrandConfigurationService; use Packlink\BusinessLogic\DTO\FrontDtoFactory; use Packlink\BusinessLogic\Language\Translator; @@ -24,78 +26,17 @@ class CountryService extends BaseService */ protected static $instance; /** - * List of four default countries. + * BrandConfigurationService instance. * - * @var array + * @var BrandConfigurationService */ - protected static $baseCountries = array('ES', 'DE', 'FR', 'IT'); + protected $brandConfigurationService; /** - * List of supported countries. + * List of four default countries. * * @var array */ - protected static $supportedCountries = array( - 'ES' => array( - 'name' => 'Spain', - 'code' => 'ES', - 'postal_code' => '28001', - ), - 'DE' => array( - 'name' => 'Germany', - 'code' => 'DE', - 'postal_code' => '10115', - ), - 'FR' => array( - 'name' => 'France', - 'code' => 'FR', - 'postal_code' => '75001', - ), - 'IT' => array( - 'name' => 'Italy', - 'code' => 'IT', - 'postal_code' => '00118', - ), - 'AT' => array( - 'name' => 'Austria', - 'code' => 'AT', - 'postal_code' => '1010', - ), - 'NL' => array( - 'name' => 'Netherlands', - 'code' => 'NL', - 'postal_code' => '1011', - ), - 'BE' => array( - 'name' => 'Belgium', - 'code' => 'BE', - 'postal_code' => '1000', - ), - 'PT' => array( - 'name' => 'Portugal', - 'code' => 'PT', - 'postal_code' => '1000-017', - ), - 'TR' => array( - 'name' => 'Turkey', - 'code' => 'TR', - 'postal_code' => '06010', - ), - 'IE' => array( - 'name' => 'Ireland', - 'code' => 'IE', - 'postal_code' => 'D1', - ), - 'GB' => array( - 'name' => 'United Kingdom', - 'code' => 'GB', - 'postal_code' => 'E1 6AN', - ), - 'HU' => array( - 'name' => 'Hungary', - 'code' => 'HU', - 'postal_code' => '1014', - ), - ); + protected static $baseCountries = array('ES', 'DE', 'FR', 'IT'); /** * Checks if given country is one of the four base countries ('ES', 'DE', 'FR', 'IT'). @@ -122,12 +63,27 @@ public function isBaseCountry($countryCode) public function getSupportedCountries($associative = true) { $countries = array(); + $brand = $this->getBrandConfigurationService()->get(); - foreach (static::$supportedCountries as $country) { + foreach ($brand->registrationCountries as $country) { $country['name'] = Translator::translate('countries.' . $country['code']); $countries[$country['code']] = FrontDtoFactory::get(Country::CLASS_KEY, $country); } return $associative ? $countries : array_values($countries); } + + /** + * Gets BrandConfigurationService. + * + * @return BrandConfigurationService + */ + protected function getBrandConfigurationService() + { + if ($this->brandConfigurationService === null) { + $this->brandConfigurationService = ServiceRegister::getService(BrandConfigurationService::CLASS_NAME); + } + + return $this->brandConfigurationService; + } } diff --git a/src/BusinessLogic/Country/WarehouseCountryService.php b/src/BusinessLogic/Country/WarehouseCountryService.php index 6cd1435a..1a7c6a1c 100644 --- a/src/BusinessLogic/Country/WarehouseCountryService.php +++ b/src/BusinessLogic/Country/WarehouseCountryService.php @@ -22,63 +22,6 @@ class WarehouseCountryService extends CountryService * @var static */ protected static $instance; - /** - * List of countries available only for warehouse selection. - * - * @var array - */ - protected static $additionalWarehouseCountries = array( - 'PL' => array( - 'name' => 'Poland', - 'code' => 'PL', - 'postal_code' => '00-694', - ), - 'CH' => array( - 'name' => 'Switzerland', - 'code' => 'CH', - 'postal_code' => '3000', - ), - 'LU' => array( - 'name' => 'Luxembourg', - 'code' => 'LU', - 'postal_code' => '1009', - ), - 'AR' => array( - 'name' => 'Argentina', - 'code' => 'AR', - 'postal_code' => 'C1258 AAA', - ), - 'US' => array( - 'name' => 'United States', - 'code' => 'US', - 'postal_code' => '01223', - ), - 'BO' => array( - 'name' => 'Bolivia', - 'code' => 'BO', - 'postal_code' => 'La Paz', - ), - 'MX' => array( - 'name' => 'Mexico', - 'code' => 'MX', - 'postal_code' => '21900', - ), - 'CL' => array( - 'name' => 'Chile', - 'code' => 'CL', - 'postal_code' => '7500599', - ), - 'CZ' => array( - 'name' => 'Czech Republic', - 'code' => 'CZ', - 'postal_code' => '186 00', - ), - 'SE' => array( - 'name' => 'Sweden', - 'code' => 'SE', - 'postal_code' => '103 16', - ), - ); /** * Returns a list of supported country DTOs. @@ -92,7 +35,7 @@ class WarehouseCountryService extends CountryService */ public function getSupportedCountries($associative = true) { - $countries = array_merge(static::$supportedCountries, static::$additionalWarehouseCountries); + $countries = $this->getBrandConfigurationService()->get()->warehouseCountries; foreach ($countries as $country) { $country['name'] = Translator::translate('countries.' . $country['code']); @@ -111,6 +54,8 @@ public function getSupportedCountries($associative = true) */ public function isCountrySupported($isoCode) { - return array_key_exists($isoCode, array_merge(static::$supportedCountries, static::$additionalWarehouseCountries)); + $countries = $this->getBrandConfigurationService()->get()->warehouseCountries; + + return array_key_exists($isoCode, $countries); } } From 91e5aef6f0be9e494f154f4c85109a4002e953f5 Mon Sep 17 00:00:00 2001 From: marija Date: Thu, 4 Mar 2021 13:14:50 +0100 Subject: [PATCH 08/37] Replace hardcoded registration and warehouse countries Code review fixes. PLCR24-13 --- CHANGELOG.md | 18 +++++++++++++ src/BusinessLogic/Country/CountryService.php | 27 ++++++++++++++++--- .../Country/WarehouseCountryService.php | 8 ++---- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb6a8481..1429441d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,24 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Added additional ISO codes to the postal code transformer. - Added missing carrier logos for Italy and Spain. +**BREAKING CHANGES** +Whitelabel project changes: + +## Added +- Added BrandConfigurationService. +- Added PacklinkConfigurationService. + +### Changed +- Removed hardcoded source value from ShippingServiceSearch. +- Removed hardcoded platform code from Proxy, Draft and RegistrationRequest. +- Removed platform country code from RegisterModalController.js. +- Added platform_country to RegistrationController:getRegisterData response. +- RegisterController.js function populateInitialValues() populates platform_country. +- Registration link and platform country removed from CountryService::$supportedCountries. +- Removed Packlink\BusinessLogic\Country\RegistrationCountry. +- Added validation for platform country in RegistrationRequest::doValidate and UserAccountService::initializeUser. +- Removed $supportedCountries from CountryService and WarehouseCountryService. + ## [3.1.0](https://github.com/packlink-dev/ecommerce_module_core/compare/v3.0.6...v3.1.0) - 2020-12-11 ### Added - Added postal code transformer service that transforms postal code into supported postal code format for some countries. diff --git a/src/BusinessLogic/Country/CountryService.php b/src/BusinessLogic/Country/CountryService.php index 2da96846..b5ae8016 100644 --- a/src/BusinessLogic/Country/CountryService.php +++ b/src/BusinessLogic/Country/CountryService.php @@ -5,6 +5,8 @@ use Logeecom\Infrastructure\ServiceRegister; use Packlink\BusinessLogic\BaseService; use Packlink\BusinessLogic\Brand\BrandConfigurationService; +use Packlink\BusinessLogic\DTO\Exceptions\FrontDtoNotRegisteredException; +use Packlink\BusinessLogic\DTO\Exceptions\FrontDtoValidationException; use Packlink\BusinessLogic\DTO\FrontDtoFactory; use Packlink\BusinessLogic\Language\Translator; @@ -62,15 +64,32 @@ public function isBaseCountry($countryCode) */ public function getSupportedCountries($associative = true) { - $countries = array(); $brand = $this->getBrandConfigurationService()->get(); + $countries = $this->formatCountries($brand->registrationCountries); - foreach ($brand->registrationCountries as $country) { + return $associative ? $countries : array_values($countries); + } + + /** + * Formats country DTOs. + * + * @param $countries + * + * @return Country[] + * + * @throws FrontDtoNotRegisteredException + * @throws FrontDtoValidationException + */ + protected function formatCountries($countries) + { + $formattedCountries = array(); + + foreach ($countries as $country) { $country['name'] = Translator::translate('countries.' . $country['code']); - $countries[$country['code']] = FrontDtoFactory::get(Country::CLASS_KEY, $country); + $formattedCountries[$country['code']] = FrontDtoFactory::get(Country::CLASS_KEY, $country); } - return $associative ? $countries : array_values($countries); + return $formattedCountries; } /** diff --git a/src/BusinessLogic/Country/WarehouseCountryService.php b/src/BusinessLogic/Country/WarehouseCountryService.php index 1a7c6a1c..e71f25ec 100644 --- a/src/BusinessLogic/Country/WarehouseCountryService.php +++ b/src/BusinessLogic/Country/WarehouseCountryService.php @@ -36,13 +36,9 @@ class WarehouseCountryService extends CountryService public function getSupportedCountries($associative = true) { $countries = $this->getBrandConfigurationService()->get()->warehouseCountries; + $formattedCountries = $this->formatCountries($countries); - foreach ($countries as $country) { - $country['name'] = Translator::translate('countries.' . $country['code']); - $countries[$country['code']] = FrontDtoFactory::get(Country::CLASS_KEY, $country); - } - - return $associative ? $countries : array_values($countries); + return $associative ? $formattedCountries : array_values($formattedCountries); } /** From aba277297565429a5a0d9a2300ca01a25e382c50 Mon Sep 17 00:00:00 2001 From: marija Date: Thu, 4 Mar 2021 14:31:30 +0100 Subject: [PATCH 09/37] Transform DemoUI to be white label compatible PLCR24-14 --- src/DemoUI/.gitignore | 8 ++++---- src/DemoUI/Lib/Composer.php | 2 +- src/DemoUI/index.php | 10 ++++++++++ src/DemoUI/run.sh | 10 +++++++++- src/DemoUI/src/Services/Integration/UrlService.php | 6 ++++-- src/DemoUI/src/Views/{ => PRO}/index.php | 4 ++-- src/DemoUI/src/Views/{ => PRO}/resources/.gitkeep | 0 7 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 src/DemoUI/index.php rename src/DemoUI/src/Views/{ => PRO}/index.php (99%) rename src/DemoUI/src/Views/{ => PRO}/resources/.gitkeep (100%) diff --git a/src/DemoUI/.gitignore b/src/DemoUI/.gitignore index 92a15be4..5bdadde1 100644 --- a/src/DemoUI/.gitignore +++ b/src/DemoUI/.gitignore @@ -1,6 +1,6 @@ # Custom content vendor -src/Views/resources/js/ -src/Views/resources/images/ -src/Views/resources/css/location/ -src/Views/resources/css/* +src/Views/PRO/resources/js/ +src/Views/PRO/resources/images/ +src/Views/PRO/resources/css/location/ +src/Views/PRO/resources/css/* diff --git a/src/DemoUI/Lib/Composer.php b/src/DemoUI/Lib/Composer.php index e93b10c3..0ef75b08 100644 --- a/src/DemoUI/Lib/Composer.php +++ b/src/DemoUI/Lib/Composer.php @@ -9,7 +9,7 @@ class Composer public static function postUpdate() { $fromBase = __DIR__ . '/../../BusinessLogic/Resources/'; - $toBase = __DIR__ . '/../src/Views/resources/'; + $toBase = __DIR__ . '/../src/Views/PRO/resources/'; $map = array( $fromBase . 'js' => $toBase . 'js', diff --git a/src/DemoUI/index.php b/src/DemoUI/index.php new file mode 100644 index 00000000..07ef4980 --- /dev/null +++ b/src/DemoUI/index.php @@ -0,0 +1,10 @@ + document.addEventListener( 'DOMContentLoaded', diff --git a/src/DemoUI/src/Views/resources/.gitkeep b/src/DemoUI/src/Views/PRO/resources/.gitkeep similarity index 100% rename from src/DemoUI/src/Views/resources/.gitkeep rename to src/DemoUI/src/Views/PRO/resources/.gitkeep From 6839a30ffcb5b47a440a0acef07a8a7a64940e9a Mon Sep 17 00:00:00 2001 From: marija Date: Thu, 4 Mar 2021 16:07:21 +0100 Subject: [PATCH 10/37] Add Acme DemoUI brand PLCR24-15 --- src/DemoUI/.gitignore | 4 + src/DemoUI/src/Bootstrap.php | 27 ++ .../Brands/Acme/AcmeConfigurationService.php | 85 +++++ src/DemoUI/src/Views/ACME/index.php | 323 ++++++++++++++++++ src/DemoUI/src/Views/ACME/resources/.gitkeep | 0 5 files changed, 439 insertions(+) create mode 100644 src/DemoUI/src/Brands/Acme/AcmeConfigurationService.php create mode 100644 src/DemoUI/src/Views/ACME/index.php create mode 100644 src/DemoUI/src/Views/ACME/resources/.gitkeep diff --git a/src/DemoUI/.gitignore b/src/DemoUI/.gitignore index 5bdadde1..840e4a6e 100644 --- a/src/DemoUI/.gitignore +++ b/src/DemoUI/.gitignore @@ -4,3 +4,7 @@ src/Views/PRO/resources/js/ src/Views/PRO/resources/images/ src/Views/PRO/resources/css/location/ src/Views/PRO/resources/css/* +src/Views/ACME/resources/js/ +src/Views/ACME/resources/images/ +src/Views/ACME/resources/css/location/ +src/Views/ACME/resources/css/* \ No newline at end of file diff --git a/src/DemoUI/src/Bootstrap.php b/src/DemoUI/src/Bootstrap.php index fc89976c..c2dde899 100644 --- a/src/DemoUI/src/Bootstrap.php +++ b/src/DemoUI/src/Bootstrap.php @@ -17,7 +17,9 @@ use Logeecom\Infrastructure\TaskExecution\QueueItem; use Logeecom\Tests\Infrastructure\Common\TestComponents\ORM\MemoryQueueItemRepository; use Logeecom\Tests\Infrastructure\Common\TestComponents\TestRegistrationInfoService; +use Packlink\Brands\Packlink\PacklinkConfigurationService; use Packlink\BusinessLogic\BootstrapComponent; +use Packlink\BusinessLogic\Brand\BrandConfigurationService; use Packlink\BusinessLogic\Configuration; use Packlink\BusinessLogic\Order\Interfaces\ShopOrderService as ShopOrderServiceInterface; use Packlink\BusinessLogic\OrderShipmentDetails\Models\OrderShipmentDetails; @@ -27,6 +29,7 @@ use Packlink\BusinessLogic\ShippingMethod\Interfaces\ShopShippingMethodService; use Packlink\BusinessLogic\ShippingMethod\Models\ShippingMethod; use Packlink\BusinessLogic\User\UserAccountService; +use Packlink\DemoUI\Brands\Acme\AcmeConfigurationService; use Packlink\DemoUI\Repository\SessionRepository; use Packlink\DemoUI\Services\BusinessLogic\CarrierService; use Packlink\DemoUI\Services\BusinessLogic\ConfigurationService; @@ -112,6 +115,7 @@ protected static function initServices() parent::initServices(); static::$instance->initInstanceServices(); + static::$instance->initBrandService(); } /** @@ -197,4 +201,27 @@ function () use ($instance) { } ); } + + protected function initBrandService() + { + $brandPlatformCode = getenv('PL_PLATFORM'); + + switch ($brandPlatformCode) { + case 'PRO': + ServiceRegister::registerService( + BrandConfigurationService::CLASS_NAME, + function () { + return new PacklinkConfigurationService(); + } + ); + break; + case 'ACME': + ServiceRegister::registerService( + BrandConfigurationService::CLASS_NAME, + function () { + return new AcmeConfigurationService(); + } + ); + } + } } \ No newline at end of file diff --git a/src/DemoUI/src/Brands/Acme/AcmeConfigurationService.php b/src/DemoUI/src/Brands/Acme/AcmeConfigurationService.php new file mode 100644 index 00000000..ffbb46a4 --- /dev/null +++ b/src/DemoUI/src/Brands/Acme/AcmeConfigurationService.php @@ -0,0 +1,85 @@ + array( + 'code' => 'ES', + 'postal_code' => '28001', + ), + 'DE' => array( + 'code' => 'DE', + 'postal_code' => '10115', + ), + 'FR' => array( + 'code' => 'FR', + 'postal_code' => '75001', + ), + 'IT' => array( + 'code' => 'IT', + 'postal_code' => '00118', + ), + ); + /** + * List of countries available only for warehouse selection. + * + * @var array + */ + protected static $additionalWarehouseCountries = array( + 'PL' => array( + 'code' => 'PL', + 'postal_code' => '00-694', + ), + 'CH' => array( + 'code' => 'CH', + 'postal_code' => '3000', + ), + ); + + /** + * @inheritDoc + */ + public function get() + { + $brandConfiguration = new BrandConfiguration(); + + $brandConfiguration->platformCode = 'PRO'; + $brandConfiguration->shippingServiceSource = 'PRO'; + $brandConfiguration->platformCountries = static::$supportedPlatformCountries; + $brandConfiguration->registrationCountries = static::$supportedRegistrationCountries; + $brandConfiguration->warehouseCountries = array_merge( + static::$supportedRegistrationCountries, + static::$additionalWarehouseCountries + ); + + return $brandConfiguration; + } +} \ No newline at end of file diff --git a/src/DemoUI/src/Views/ACME/index.php b/src/DemoUI/src/Views/ACME/index.php new file mode 100644 index 00000000..35c2dffb --- /dev/null +++ b/src/DemoUI/src/Views/ACME/index.php @@ -0,0 +1,323 @@ + + + + + + Demo UI + + + + + + + + + +
+
+ +
+
+ +
+ +
+
+
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/DemoUI/src/Views/ACME/resources/.gitkeep b/src/DemoUI/src/Views/ACME/resources/.gitkeep new file mode 100644 index 00000000..e69de29b From e3b57424ee162b717ba1bae3174009ba441d6fa8 Mon Sep 17 00:00:00 2001 From: marija Date: Fri, 12 Mar 2021 13:33:33 +0100 Subject: [PATCH 11/37] Implement hierarchical content extending of key/value files PLCR24-16 --- CHANGELOG.md | 7 +- .../FileResolver/FileResolverService.php | 77 ++++++++++++++++ .../FileResolver/FileResolverServiceTest.php | 92 +++++++++++++++++++ .../FileResolver/Translations/en.json | 4 + .../FileResolver/Translations/fr.json | 6 ++ 5 files changed, 184 insertions(+), 2 deletions(-) create mode 100644 src/BusinessLogic/FileResolver/FileResolverService.php create mode 100644 tests/BusinessLogic/FileResolver/FileResolverServiceTest.php create mode 100644 tests/BusinessLogic/FileResolver/Translations/en.json create mode 100644 tests/BusinessLogic/FileResolver/Translations/fr.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 1429441d..63d5f25e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,11 +11,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). **BREAKING CHANGES** Whitelabel project changes: -## Added -- Added BrandConfigurationService. +### Added +- Added BrandConfigurationService. Integration should register PacklinkConfigurationService instance for Packlink brand or adequate implementation for other brand(s) during the bootstraping. - Added PacklinkConfigurationService. +- Added FileResolverService. Integration should initialize FileResolverService with an array of folders where source files should be searched for. ### Changed + +Following changes will work properly once BrandConfigurationService is registered in Bootstrap: - Removed hardcoded source value from ShippingServiceSearch. - Removed hardcoded platform code from Proxy, Draft and RegistrationRequest. - Removed platform country code from RegisterModalController.js. diff --git a/src/BusinessLogic/FileResolver/FileResolverService.php b/src/BusinessLogic/FileResolver/FileResolverService.php new file mode 100644 index 00000000..f582bd66 --- /dev/null +++ b/src/BusinessLogic/FileResolver/FileResolverService.php @@ -0,0 +1,77 @@ +folders = $folders; + } + + /** + * Returns merged content of the requested source file. + * + * @param string $sourceFile + * + * @return array + */ + public function getContent($sourceFile) + { + $content = array(); + + foreach ($this->folders as $folder) { + $filePath = $folder . '/' . $sourceFile . '.json'; + + if (!file_exists($filePath)) { + continue; + } + + $serializedJson = file_get_contents($filePath); + + if ($serializedJson) { + $content[] = json_decode($serializedJson, true); + } + } + + return $content === array() ? $content : call_user_func_array('array_merge', $content); + } + + /** + * Adds new folder to the folders array. + * + * @param string $folder + */ + public function addFolder($folder) + { + $this->folders[] = $folder; + } + + /** + * Gets folders array. + * + * @return array + */ + public function getFolders() + { + return $this->folders; + } +} diff --git a/tests/BusinessLogic/FileResolver/FileResolverServiceTest.php b/tests/BusinessLogic/FileResolver/FileResolverServiceTest.php new file mode 100644 index 00000000..c1682af5 --- /dev/null +++ b/tests/BusinessLogic/FileResolver/FileResolverServiceTest.php @@ -0,0 +1,92 @@ + 'testValueEn 2', + 'testKey1' => 'testValueEn1', + 'testKey2' => 'testValueEn2' + ); + private static $frenchValues = array( + 'testKey' => 'testValueFr', + 'namespace' => array( + 'nestedKeyWithPlaceholder' => 'Nested key fr.' + ) + ); + + /** + * @var FileResolverService + */ + private $fileResolverService; + + public function setUp() + { + parent::setUp(); + + $this->fileResolverService = new FileResolverService( + array( + __DIR__ . '/../Language/Translations', + __DIR__ . '/Translations' + ) + ); + } + + /** + * Tests getContent function when files exist. + */ + public function testGetContentFilesExist() + { + $content = $this->fileResolverService->getContent('en'); + + $this->assertEquals(static::$englishValues, $content); + } + + /** + * Tests getContent function when files do not exist. + */ + public function testGetContentFilesDoNotExist() + { + $content = $this->fileResolverService->getContent('rs'); + + $this->assertEquals(array(), $content); + } + + /** + * Tests getContent function when one file exists and the other one does not exist. + */ + public function testGetContentOneFileDoesNotExist() + { + $content = $this->fileResolverService->getContent('fr'); + + $this->assertEquals(static::$frenchValues, $content); + } + + /** + * Test addFolder function. + */ + public function testAddFolder() + { + $this->fileResolverService->addFolder(__DIR__); + + $folders = $this->fileResolverService->getFolders(); + + $this->assertEquals( + array( + __DIR__ . '/../Language/Translations', + __DIR__ . '/Translations', + __DIR__ + ), + $folders); + } +} \ No newline at end of file diff --git a/tests/BusinessLogic/FileResolver/Translations/en.json b/tests/BusinessLogic/FileResolver/Translations/en.json new file mode 100644 index 00000000..39e741a8 --- /dev/null +++ b/tests/BusinessLogic/FileResolver/Translations/en.json @@ -0,0 +1,4 @@ +{ + "testKey": "testValueEn 2", + "testKey2": "testValueEn2" +} \ No newline at end of file diff --git a/tests/BusinessLogic/FileResolver/Translations/fr.json b/tests/BusinessLogic/FileResolver/Translations/fr.json new file mode 100644 index 00000000..30887213 --- /dev/null +++ b/tests/BusinessLogic/FileResolver/Translations/fr.json @@ -0,0 +1,6 @@ +{ + "testKey": "testValueFr", + "namespace": { + "nestedKeyWithPlaceholder": "Nested key fr." + } +} \ No newline at end of file From 8e0307f46f920d07f9dba3ccde7e22c05e9253b2 Mon Sep 17 00:00:00 2001 From: marija Date: Fri, 12 Mar 2021 14:47:27 +0100 Subject: [PATCH 12/37] Transform DemoUI to be white label compatible PLCR24-14 --- src/DemoUI/run.sh | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/DemoUI/run.sh b/src/DemoUI/run.sh index 43bae29e..1cbbc41d 100644 --- a/src/DemoUI/run.sh +++ b/src/DemoUI/run.sh @@ -2,11 +2,7 @@ composer install -PL_PLATFORM="$1" - -if [ "$PL_PLATFORM" = "" ]; then - PL_PLATFORM = "PRO" -fi +PL_PLATFORM="${1:-"PRO"}" export PL_PLATFORM From bcb0125bfa367a96af6bca9b28ee710e79a4d1bb Mon Sep 17 00:00:00 2001 From: marija Date: Fri, 12 Mar 2021 14:54:43 +0100 Subject: [PATCH 13/37] Add Acme DemoUI brand PLCR24-15 --- src/DemoUI/Lib/Composer.php | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/DemoUI/Lib/Composer.php b/src/DemoUI/Lib/Composer.php index 0ef75b08..1d31bcdb 100644 --- a/src/DemoUI/Lib/Composer.php +++ b/src/DemoUI/Lib/Composer.php @@ -9,14 +9,29 @@ class Composer public static function postUpdate() { $fromBase = __DIR__ . '/../../BusinessLogic/Resources/'; - $toBase = __DIR__ . '/../src/Views/PRO/resources/'; + $toBasePacklink = __DIR__ . '/../src/Views/PRO/resources/'; + $toBaseAcme = __DIR__ . '/../src/Views/ACME/resources/'; - $map = array( - $fromBase . 'js' => $toBase . 'js', - $fromBase . 'css' => $toBase . 'css', - $fromBase . 'images' => $toBase . 'images', - ); + static::copy(array( + $fromBase . 'js' => $toBasePacklink . 'js', + $fromBase . 'css' => $toBasePacklink . 'css', + $fromBase . 'images' => $toBasePacklink . 'images', + )); + static::copy( array( + $fromBase . 'js' => $toBaseAcme . 'js', + $fromBase . 'css' => $toBaseAcme . 'css', + $fromBase . 'images' => $toBaseAcme . 'images', + )); + } + + /** + * Copies directories according to data provided by $map parameter. + * + * @param array $map + */ + private static function copy($map) + { foreach ($map as $from => $to) { self::copyDirectory($from, $to); } From b9ba64e94b44f9a8b352c69ca834b3e369c197c4 Mon Sep 17 00:00:00 2001 From: marija Date: Fri, 12 Mar 2021 16:16:26 +0100 Subject: [PATCH 14/37] Refactor TranslationService to use hierarchical content extending PLCR24-17 --- CHANGELOG.md | 6 ++ src/BusinessLogic/BootstrapComponent.php | 21 ++++- .../Controllers/RegistrationController.php | 2 +- .../FileResolver/FileResolverService.php | 4 + ...nslationService.php => CountryService.php} | 76 +++++++++-------- ...nslationService.php => CountryService.php} | 16 +++- src/BusinessLogic/Language/Translator.php | 4 +- .../Resources/{lang => countries}/de.json | 0 .../Resources/{lang => countries}/en.json | 0 .../Resources/{lang => countries}/es.json | 0 .../Resources/{lang => countries}/fr.json | 0 .../Resources/{lang => countries}/fromCSV.php | 2 +- .../Resources/{lang => countries}/it.json | 0 .../Resources/{lang => countries}/toCSV.php | 0 .../{lang => countries}/translations.csv | 0 src/BusinessLogic/Utility/UrlService.php | 2 +- src/DemoUI/src/Controllers/Index.php | 2 +- src/DemoUI/src/Views/ACME/index.php | 8 +- src/DemoUI/src/Views/PRO/index.php | 8 +- .../Configuration/Configuration.php | 8 +- .../Common/BaseTestWithServices.php | 21 ++++- ...tionService.php => TestCountryService.php} | 8 +- .../Language/TranslationServiceTest.php | 82 +++++++++++++++---- 23 files changed, 183 insertions(+), 87 deletions(-) rename src/BusinessLogic/Language/{TranslationService.php => CountryService.php} (57%) rename src/BusinessLogic/Language/Interfaces/{TranslationService.php => CountryService.php} (73%) rename src/BusinessLogic/Resources/{lang => countries}/de.json (100%) rename src/BusinessLogic/Resources/{lang => countries}/en.json (100%) rename src/BusinessLogic/Resources/{lang => countries}/es.json (100%) rename src/BusinessLogic/Resources/{lang => countries}/fr.json (100%) rename src/BusinessLogic/Resources/{lang => countries}/fromCSV.php (96%) rename src/BusinessLogic/Resources/{lang => countries}/it.json (100%) rename src/BusinessLogic/Resources/{lang => countries}/toCSV.php (100%) rename src/BusinessLogic/Resources/{lang => countries}/translations.csv (100%) rename tests/BusinessLogic/Language/{TestTranslationService.php => TestCountryService.php} (51%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 63d5f25e..44913c8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,9 +15,15 @@ Whitelabel project changes: - Added BrandConfigurationService. Integration should register PacklinkConfigurationService instance for Packlink brand or adequate implementation for other brand(s) during the bootstraping. - Added PacklinkConfigurationService. - Added FileResolverService. Integration should initialize FileResolverService with an array of folders where source files should be searched for. +- Added new method getTranslations to \Packlink\BusinessLogic\Language\TranslationService (service renamed to CountryService). ### Changed +- \Packlink\BusinessLogic\Language\TranslationService renamed to CountryService. +- TranslationService::translate renamed to CountryService::getText. +- Files from Resources/lang moved to Resources/countries. In integration, change path to translations to fit new folder names in core. +- Configuration::getCurrentLanguage and Configuration::setCurrentLanguage changed to Configuration::getUICountryCode and Configuration::setUICountryCode. + Following changes will work properly once BrandConfigurationService is registered in Bootstrap: - Removed hardcoded source value from ShippingServiceSearch. - Removed hardcoded platform code from Proxy, Draft and RegistrationRequest. diff --git a/src/BusinessLogic/BootstrapComponent.php b/src/BusinessLogic/BootstrapComponent.php index 12deb1c0..41a696f1 100644 --- a/src/BusinessLogic/BootstrapComponent.php +++ b/src/BusinessLogic/BootstrapComponent.php @@ -15,10 +15,11 @@ use Packlink\BusinessLogic\Country\WarehouseCountryService; use Packlink\BusinessLogic\DTO\FrontDtoFactory; use Packlink\BusinessLogic\DTO\ValidationError; +use Packlink\BusinessLogic\FileResolver\FileResolverService; use Packlink\BusinessLogic\Http\DTO\ParcelInfo; use Packlink\BusinessLogic\Http\Proxy; -use Packlink\BusinessLogic\Language\Interfaces\TranslationService as TranslationServiceInterface; -use Packlink\BusinessLogic\Language\TranslationService; +use Packlink\BusinessLogic\Language\Interfaces\CountryService as TranslationServiceInterface; +use Packlink\BusinessLogic\Language\CountryService as CountryTranslationService; use Packlink\BusinessLogic\Location\LocationService; use Packlink\BusinessLogic\Order\OrderService; use Packlink\BusinessLogic\OrderShipmentDetails\OrderShipmentDetailsService; @@ -169,10 +170,24 @@ function () { } ); + ServiceRegister::registerService( + FileResolverService::CLASS_NAME, + function () { + return new FileResolverService( + array( + __DIR__ . '/Resources/countries', + ) + ); + } + ); + ServiceRegister::registerService( TranslationServiceInterface::CLASS_NAME, function () { - return new TranslationService(); + /** @var FileResolverService $fileResolverService */ + $fileResolverService = ServiceRegister::getService(FileResolverService::CLASS_NAME); + + return new CountryTranslationService($fileResolverService); } ); diff --git a/src/BusinessLogic/Controllers/RegistrationController.php b/src/BusinessLogic/Controllers/RegistrationController.php index 2761f987..25650485 100644 --- a/src/BusinessLogic/Controllers/RegistrationController.php +++ b/src/BusinessLogic/Controllers/RegistrationController.php @@ -192,7 +192,7 @@ private function getLanguage() 'it' => 'it_IT', ); - $locale = Configuration::getCurrentLanguage(); + $locale = Configuration::getUICountryCode(); $language = 'en_GB'; if (array_key_exists($locale, $supportedLanguages)) { diff --git a/src/BusinessLogic/FileResolver/FileResolverService.php b/src/BusinessLogic/FileResolver/FileResolverService.php index f582bd66..a85b4d1e 100644 --- a/src/BusinessLogic/FileResolver/FileResolverService.php +++ b/src/BusinessLogic/FileResolver/FileResolverService.php @@ -10,6 +10,10 @@ */ class FileResolverService { + /** + * Class name. + */ + const CLASS_NAME = __CLASS__; /** * Array of folders where the source files should be searched for. * diff --git a/src/BusinessLogic/Language/TranslationService.php b/src/BusinessLogic/Language/CountryService.php similarity index 57% rename from src/BusinessLogic/Language/TranslationService.php rename to src/BusinessLogic/Language/CountryService.php index a78efbf4..1d93cee8 100644 --- a/src/BusinessLogic/Language/TranslationService.php +++ b/src/BusinessLogic/Language/CountryService.php @@ -2,17 +2,16 @@ namespace Packlink\BusinessLogic\Language; -use Exception; use Logeecom\Infrastructure\Configuration\Configuration; -use Logeecom\Infrastructure\Logger\Logger; -use Packlink\BusinessLogic\Language\Interfaces\TranslationService as BaseService; +use Packlink\BusinessLogic\FileResolver\FileResolverService; +use Packlink\BusinessLogic\Language\Interfaces\CountryService as BaseService; /** - * Class TranslationService. + * Class CountryService * * @package Packlink\BusinessLogic\Language */ -class TranslationService implements BaseService +class CountryService implements BaseService { /** * Default language. @@ -27,9 +26,9 @@ class TranslationService implements BaseService protected static $translations = array(); /** - * @var string $translationsFileBasePath + * @var FileResolverService */ - protected $translationsFileBasePath; + protected $fileResolverService; /** * @var string @@ -39,15 +38,11 @@ class TranslationService implements BaseService /** * TranslationService constructor. * - * @param string|null $translationsFileBasePath + * @param FileResolverService $fileResolverService */ - public function __construct($translationsFileBasePath = null) + public function __construct(FileResolverService $fileResolverService) { - $this->translationsFileBasePath = $translationsFileBasePath; - - if (empty($this->translationsFileBasePath)) { - $this->translationsFileBasePath = __DIR__ . '/../Resources/lang'; - } + $this->fileResolverService = $fileResolverService; } /** @@ -64,9 +59,9 @@ public function __construct($translationsFileBasePath = null) * * @return string A translated string if translation is found; otherwise, the input key. */ - public function translate($key, array $arguments = array()) + public function getText($key, array $arguments = array()) { - $this->currentLanguage = Configuration::getCurrentLanguage() ?: static::DEFAULT_LANG; + $this->currentLanguage = Configuration::getUICountryCode() ?: static::DEFAULT_LANG; if (empty(static::$translations[$this->currentLanguage])) { $this->initializeTranslations(); @@ -85,43 +80,48 @@ public function translate($key, array $arguments = array()) return vsprintf($result, $arguments); } + /** + * Fetches translations for a specific country (provided by $countryCode parameter) + * and default country. + * + * @param string $countryCode + * + * @return array + */ + public function getTranslations($countryCode) + { + $translations[$countryCode] = $this->fileResolverService->getContent($countryCode); + $translations[static::DEFAULT_LANG] = $this->fileResolverService->getContent(static::DEFAULT_LANG); + + return $translations; + } + /** * Initializes the translations from a file to in-memory map. */ protected function initializeTranslations() { $languageLowerCase = strtolower($this->currentLanguage); - $this->translationsFileBasePath = rtrim($this->translationsFileBasePath, '/') . '/'; - $translationFilePath = "{$this->translationsFileBasePath}{$languageLowerCase}.json"; - $this->initializeLanguage($translationFilePath, $this->currentLanguage); + $this->initializeLanguage($languageLowerCase); $this->initializeFallbackLanguage(); } /** * Initializes the language to translations dictionary. * - * @param $translationFilePath * @param $language */ - protected function initializeLanguage($translationFilePath, $language) + protected function initializeLanguage($language) { - try { - $serializedJson = file_get_contents($translationFilePath); - } catch (Exception $ex) { - $serializedJson = false; - Logger::logWarning($ex->getMessage()); - } + $translations = $this->fileResolverService->getContent($language); - if ($serializedJson !== false) { - $translations = json_decode($serializedJson, true); - foreach ($translations as $groupKey => $group) { - if (is_array($group)) { - foreach ($group as $key => $value) { - static::$translations[$language][$groupKey . '.' . $key] = $value; - } - } else { - static::$translations[$language][$groupKey] = $group; + foreach ($translations as $groupKey => $group) { + if (is_array($group)) { + foreach ($group as $key => $value) { + static::$translations[$language][$groupKey . '.' . $key] = $value; } + } else { + static::$translations[$language][$groupKey] = $group; } } } @@ -132,9 +132,7 @@ protected function initializeLanguage($translationFilePath, $language) protected function initializeFallbackLanguage() { if (strtolower($this->currentLanguage) !== static::DEFAULT_LANG) { - $defaultLang = static::DEFAULT_LANG; - $translationFilePath = "{$this->translationsFileBasePath}{$defaultLang}.json"; - $this->initializeLanguage($translationFilePath, static::DEFAULT_LANG); + $this->initializeLanguage(static::DEFAULT_LANG); } } diff --git a/src/BusinessLogic/Language/Interfaces/TranslationService.php b/src/BusinessLogic/Language/Interfaces/CountryService.php similarity index 73% rename from src/BusinessLogic/Language/Interfaces/TranslationService.php rename to src/BusinessLogic/Language/Interfaces/CountryService.php index 8dcae2ab..2ccd96d8 100644 --- a/src/BusinessLogic/Language/Interfaces/TranslationService.php +++ b/src/BusinessLogic/Language/Interfaces/CountryService.php @@ -3,11 +3,11 @@ namespace Packlink\BusinessLogic\Language\Interfaces; /** - * Interface TranslationService + * Interface CountryService * * @package Packlink\BusinessLogic\Language\Interfaces */ -interface TranslationService +interface CountryService { /** * Class name. @@ -28,5 +28,15 @@ interface TranslationService * * @return string A translated string if translation is found; otherwise, the input key. */ - public function translate($key, array $arguments = array()); + public function getText($key, array $arguments = array()); + + /** + * Fetches translations for a specific country (provided by $countryCode parameter) + * and default country. + * + * @param string $countryCode + * + * @return array + */ + public function getTranslations($countryCode); } diff --git a/src/BusinessLogic/Language/Translator.php b/src/BusinessLogic/Language/Translator.php index 152add01..a5fc4f3b 100644 --- a/src/BusinessLogic/Language/Translator.php +++ b/src/BusinessLogic/Language/Translator.php @@ -3,7 +3,7 @@ namespace Packlink\BusinessLogic\Language; use Logeecom\Infrastructure\ServiceRegister; -use Packlink\BusinessLogic\Language\Interfaces\TranslationService as TranslationServiceInterface; +use Packlink\BusinessLogic\Language\Interfaces\CountryService as TranslationServiceInterface; /** * Class Translator. @@ -27,7 +27,7 @@ class Translator */ public static function translate($key, array $arguments = array()) { - return static::getTranslationService()->translate($key, $arguments); + return static::getTranslationService()->getText($key, $arguments); } /** diff --git a/src/BusinessLogic/Resources/lang/de.json b/src/BusinessLogic/Resources/countries/de.json similarity index 100% rename from src/BusinessLogic/Resources/lang/de.json rename to src/BusinessLogic/Resources/countries/de.json diff --git a/src/BusinessLogic/Resources/lang/en.json b/src/BusinessLogic/Resources/countries/en.json similarity index 100% rename from src/BusinessLogic/Resources/lang/en.json rename to src/BusinessLogic/Resources/countries/en.json diff --git a/src/BusinessLogic/Resources/lang/es.json b/src/BusinessLogic/Resources/countries/es.json similarity index 100% rename from src/BusinessLogic/Resources/lang/es.json rename to src/BusinessLogic/Resources/countries/es.json diff --git a/src/BusinessLogic/Resources/lang/fr.json b/src/BusinessLogic/Resources/countries/fr.json similarity index 100% rename from src/BusinessLogic/Resources/lang/fr.json rename to src/BusinessLogic/Resources/countries/fr.json diff --git a/src/BusinessLogic/Resources/lang/fromCSV.php b/src/BusinessLogic/Resources/countries/fromCSV.php similarity index 96% rename from src/BusinessLogic/Resources/lang/fromCSV.php rename to src/BusinessLogic/Resources/countries/fromCSV.php index 5968a5d9..cb62008e 100644 --- a/src/BusinessLogic/Resources/lang/fromCSV.php +++ b/src/BusinessLogic/Resources/countries/fromCSV.php @@ -35,7 +35,7 @@ function fromCsv() function exportJson($lang, $data) { file_put_contents( - __DIR__ . "/$lang.json", + __DIR__ . "/fromCSV.php", str_replace( ' ', ' ', diff --git a/src/BusinessLogic/Resources/lang/it.json b/src/BusinessLogic/Resources/countries/it.json similarity index 100% rename from src/BusinessLogic/Resources/lang/it.json rename to src/BusinessLogic/Resources/countries/it.json diff --git a/src/BusinessLogic/Resources/lang/toCSV.php b/src/BusinessLogic/Resources/countries/toCSV.php similarity index 100% rename from src/BusinessLogic/Resources/lang/toCSV.php rename to src/BusinessLogic/Resources/countries/toCSV.php diff --git a/src/BusinessLogic/Resources/lang/translations.csv b/src/BusinessLogic/Resources/countries/translations.csv similarity index 100% rename from src/BusinessLogic/Resources/lang/translations.csv rename to src/BusinessLogic/Resources/countries/translations.csv diff --git a/src/BusinessLogic/Utility/UrlService.php b/src/BusinessLogic/Utility/UrlService.php index f5a19214..89d6d19c 100644 --- a/src/BusinessLogic/Utility/UrlService.php +++ b/src/BusinessLogic/Utility/UrlService.php @@ -24,7 +24,7 @@ public static function getUrlLocaleKey() /** @var \Packlink\BusinessLogic\Configuration $configService */ $configService = ServiceRegister::getService(Configuration::CLASS_NAME); $userInfo = $configService->getUserInfo(); - $currentLang = $configService::getCurrentLanguage(); + $currentLang = $configService::getUICountryCode(); if ($userInfo !== null && in_array($userInfo->country, array('ES', 'DE', 'FR', 'IT'), true)) { $locale = $userInfo->country; diff --git a/src/DemoUI/src/Controllers/Index.php b/src/DemoUI/src/Controllers/Index.php index 8fd2ad2c..b5463872 100644 --- a/src/DemoUI/src/Controllers/Index.php +++ b/src/DemoUI/src/Controllers/Index.php @@ -11,6 +11,6 @@ session_start(); Bootstrap::init(); -Configuration::setCurrentLanguage('en'); +Configuration::setUICountryCode('en'); $routingController = new ResolverController(); $routingController->handleAction(); \ No newline at end of file diff --git a/src/DemoUI/src/Views/ACME/index.php b/src/DemoUI/src/Views/ACME/index.php index 35c2dffb..92d60cef 100644 --- a/src/DemoUI/src/Views/ACME/index.php +++ b/src/DemoUI/src/Views/ACME/index.php @@ -5,8 +5,8 @@ require_once __DIR__ . '/../../../vendor/autoload.php'; -Configuration::setCurrentLanguage('en'); -$lang = Configuration::getCurrentLanguage() ?: 'en'; +Configuration::setUICountryCode('en'); +$lang = Configuration::getUICountryCode() ?: 'en'; function getUrl($controller, $action) { @@ -145,8 +145,8 @@ function getUrl($controller, $action) 'DOMContentLoaded', () => { Packlink.translations = { - default: , - current: , + current: , }; diff --git a/src/DemoUI/src/Views/PRO/index.php b/src/DemoUI/src/Views/PRO/index.php index 35c2dffb..92d60cef 100644 --- a/src/DemoUI/src/Views/PRO/index.php +++ b/src/DemoUI/src/Views/PRO/index.php @@ -5,8 +5,8 @@ require_once __DIR__ . '/../../../vendor/autoload.php'; -Configuration::setCurrentLanguage('en'); -$lang = Configuration::getCurrentLanguage() ?: 'en'; +Configuration::setUICountryCode('en'); +$lang = Configuration::getUICountryCode() ?: 'en'; function getUrl($controller, $action) { @@ -145,8 +145,8 @@ function getUrl($controller, $action) 'DOMContentLoaded', () => { Packlink.translations = { - default: , - current: , + current: , }; diff --git a/src/Infrastructure/Configuration/Configuration.php b/src/Infrastructure/Configuration/Configuration.php index 63951b06..dc9de5d9 100644 --- a/src/Infrastructure/Configuration/Configuration.php +++ b/src/Infrastructure/Configuration/Configuration.php @@ -63,21 +63,21 @@ abstract class Configuration extends Singleton protected $repository; /** - * Retrieves current language. + * Retrieves current UI country code. * * @return string */ - public static function getCurrentLanguage() + public static function getUICountryCode() { return self::$currentLanguage; } /** - * Sets current language. + * Sets current UI country code. * * @param string $currentLanguage */ - public static function setCurrentLanguage($currentLanguage) + public static function setUICountryCode($currentLanguage) { self::$currentLanguage = $currentLanguage; } diff --git a/tests/BusinessLogic/Common/BaseTestWithServices.php b/tests/BusinessLogic/Common/BaseTestWithServices.php index eed38e65..dc4e7eff 100644 --- a/tests/BusinessLogic/Common/BaseTestWithServices.php +++ b/tests/BusinessLogic/Common/BaseTestWithServices.php @@ -4,6 +4,7 @@ use Logeecom\Infrastructure\Configuration\Configuration; use Logeecom\Infrastructure\Http\HttpClient; +use Logeecom\Infrastructure\ServiceRegister; use Logeecom\Infrastructure\TaskExecution\Interfaces\TaskRunnerWakeup; use Logeecom\Infrastructure\TaskExecution\QueueItem; use Logeecom\Infrastructure\TaskExecution\QueueService; @@ -23,9 +24,10 @@ use Packlink\BusinessLogic\Country\CountryService; use Packlink\BusinessLogic\Country\WarehouseCountryService; use Packlink\BusinessLogic\DTO\ValidationError; +use Packlink\BusinessLogic\FileResolver\FileResolverService; use Packlink\BusinessLogic\Http\DTO\ParcelInfo; use Packlink\BusinessLogic\Http\Proxy; -use Packlink\BusinessLogic\Language\TranslationService; +use Packlink\BusinessLogic\Language\CountryService as CountryTranslationService; use Packlink\BusinessLogic\Warehouse\Warehouse; use Packlink\BusinessLogic\Warehouse\WarehouseService; @@ -116,9 +118,22 @@ function () use ($wakeupService) { ); TestServiceRegister::registerService( - \Packlink\BusinessLogic\Language\Interfaces\TranslationService::CLASS_NAME, + FileResolverService::CLASS_NAME, function () { - return new TranslationService(); + return new FileResolverService( + array( + __DIR__ . '/../../../src/BusinessLogic/Resources/countries' + ) + ); + } + ); + + TestServiceRegister::registerService( + \Packlink\BusinessLogic\Language\Interfaces\CountryService::CLASS_NAME, + function () { + $fileResolverService = ServiceRegister::getService(FileResolverService::CLASS_NAME); + + return new CountryTranslationService($fileResolverService); } ); diff --git a/tests/BusinessLogic/Language/TestTranslationService.php b/tests/BusinessLogic/Language/TestCountryService.php similarity index 51% rename from tests/BusinessLogic/Language/TestTranslationService.php rename to tests/BusinessLogic/Language/TestCountryService.php index ad26bc6a..ecd6578a 100644 --- a/tests/BusinessLogic/Language/TestTranslationService.php +++ b/tests/BusinessLogic/Language/TestCountryService.php @@ -2,18 +2,18 @@ namespace Logeecom\Tests\BusinessLogic\Language; -use Packlink\BusinessLogic\Language\TranslationService; +use Packlink\BusinessLogic\Language\CountryService; /** * Class TestTranslationService. * * @package BusinessLogic\Language */ -class TestTranslationService extends TranslationService +class TestCountryService extends CountryService { - public function __construct($translationsFileBasePath = null) + public function __construct($fileResolverService) { - parent::__construct($translationsFileBasePath); + parent::__construct($fileResolverService); // reset translations for each instance. static::$translations = array(); diff --git a/tests/BusinessLogic/Language/TranslationServiceTest.php b/tests/BusinessLogic/Language/TranslationServiceTest.php index 4c6e7ff1..26b1044d 100644 --- a/tests/BusinessLogic/Language/TranslationServiceTest.php +++ b/tests/BusinessLogic/Language/TranslationServiceTest.php @@ -9,6 +9,7 @@ use Logeecom\Tests\Infrastructure\Common\TestComponents\Utility\TestTimeProvider; use Logeecom\Tests\Infrastructure\Common\TestServiceRegister; use Packlink\BusinessLogic\Configuration; +use Packlink\BusinessLogic\FileResolver\FileResolverService; use PHPUnit\Framework\TestCase; /** @@ -18,6 +19,27 @@ */ class TranslationServiceTest extends TestCase { + private static $englishValues = array( + 'rs' => array(), + 'en' => array( + 'testKey' => 'testValueEn 2', + 'testKey1' => 'testValueEn1', + 'testKey2' => 'testValueEn2' + ) + ); + private static $englishAndFrenchValues = array( + 'fr' => array( + 'testKey' => 'testValueFr', + 'namespace' => array( + 'nestedKeyWithPlaceholder' => 'Nested key fr.' + ) + ), + 'en' => array( + 'testKey' => 'testValueEn 2', + 'testKey1' => 'testValueEn1', + 'testKey2' => 'testValueEn2' + ), + ); private $translationService; /** @@ -28,11 +50,17 @@ public function setUp() { parent::setUp(); - $baseFilePath = __DIR__ . '/Translations/'; - $this->translationService = new TestTranslationService($baseFilePath); + $fileResolverService = new FileResolverService( + array( + __DIR__ . '/Translations', + __DIR__ . '/../FileResolver/Translations', + ) + ); + + $this->translationService = new TestCountryService($fileResolverService); $configuration = new TestShopConfiguration(); - Configuration::setCurrentLanguage('de'); + Configuration::setUICountryCode('de'); new TestServiceRegister( array( @@ -44,12 +72,12 @@ public function setUp() } /** - * Tests translation function when current language is not set in config service. + * Tests getText function when current language is not set in config service. */ public function testTranslateCurrentLanguageNotSet() { $configuration = new TestShopConfiguration(); - Configuration::setCurrentLanguage(null); + Configuration::setUICountryCode(null); $logger = new TestShopLogger(); $timeProvider = new TestTimeProvider(); @@ -67,18 +95,18 @@ public function testTranslateCurrentLanguageNotSet() ) ); - $translation = $this->translationService->translate('testKey'); + $translation = $this->translationService->getText('testKey'); $this->assertStringStartsWith('testValueEn', $translation); } /** - * Tests translation function when non existing key is tried to be translated for not supported language. + * Tests getText function when non existing key is tried to be translated for not supported language. */ public function testTranslateNotSupportedLanguage() { $configuration = new TestShopConfiguration(); - Configuration::setCurrentLanguage('rs'); + Configuration::setUICountryCode('rs'); $logger = new TestShopLogger(); $timeProvider = new TestTimeProvider(); @@ -96,53 +124,73 @@ public function testTranslateNotSupportedLanguage() ) ); - $translation = $this->translationService->translate('testKey'); + $translation = $this->translationService->getText('testKey'); $this->assertStringStartsWith('testValueEn', $translation); } /** - * Tests translation function when non existing key is tried to be translated. + * Tests getText function when non existing key is tried to be translated. */ public function testTranslateNonExistingKey() { $nonExistingKey = 'noKey'; - $translation = $this->translationService->translate($nonExistingKey); + $translation = $this->translationService->getText($nonExistingKey); $this->assertEquals($nonExistingKey, $translation); } /** - * Tests translation function when non existing key in current language is tried to be translated. Key exists in the + * Tests getText function when non existing key in current language is tried to be translated. Key exists in the * fallback language. */ public function testTranslateFallbackToEnglish() { $key = 'testKey1'; - $translation = $this->translationService->translate($key); + $translation = $this->translationService->getText($key); $this->assertEquals('testValueEn1', $translation); } /** - * Tests translation function when non existing key is tried to be translated. + * Tests getText function when non existing key is tried to be translated. */ public function testTranslateToGerman() { $key = 'testKey'; - $translation = $this->translationService->translate($key); + $translation = $this->translationService->getText($key); $this->assertEquals('testValueDe', $translation); } /** - * Tests translation function with existing nested key with placeholders. + * Tests getText function with existing nested key with placeholders. */ public function testTranslateToGermanNestedKeyWithPlaceholders() { $key = 'namespace.nestedKeyWithPlaceholder'; - $translation = $this->translationService->translate($key, array(1, 2)); + $translation = $this->translationService->getText($key, array(1, 2)); $this->assertEquals('Test1 1, test2 2.', $translation); } + + /** + * Tests getTranslation function with existing language. + */ + public function testGetTranslations() + { + $translations = $this->translationService->getTranslations('fr'); + + $this->assertEquals(static::$englishAndFrenchValues, $translations); + } + + /** + * Tests getTranslation function with non existing language. + */ + public function testGetTranslationsWithNonExistingLanguage() + { + $translations = $this->translationService->getTranslations('rs'); + + $this->assertEquals(static::$englishValues, $translations); + } } From c88492e9b241773948445a23b4a81d5f6c981021 Mon Sep 17 00:00:00 2001 From: marija Date: Mon, 15 Mar 2021 15:32:49 +0100 Subject: [PATCH 15/37] Replace links generation logic with new CountryService usage PLCR24-18 --- .../Controllers/ConfigurationController.php | 24 +++---- .../Controllers/RegistrationController.php | 62 ++++++------------- src/BusinessLogic/Country/CountryService.php | 18 ------ .../OrderShipmentDetailsService.php | 13 ++-- src/BusinessLogic/Resources/countries/at.json | 6 ++ src/BusinessLogic/Resources/countries/be.json | 6 ++ src/BusinessLogic/Resources/countries/de.json | 10 ++- src/BusinessLogic/Resources/countries/en.json | 10 ++- src/BusinessLogic/Resources/countries/es.json | 10 ++- src/BusinessLogic/Resources/countries/fr.json | 10 ++- src/BusinessLogic/Resources/countries/gb.json | 6 ++ src/BusinessLogic/Resources/countries/hu.json | 6 ++ src/BusinessLogic/Resources/countries/ie.json | 6 ++ src/BusinessLogic/Resources/countries/it.json | 10 ++- src/BusinessLogic/Resources/countries/nl.json | 6 ++ src/BusinessLogic/Resources/countries/pt.json | 6 ++ src/BusinessLogic/Resources/countries/tr.json | 6 ++ .../Resources/templates/configuration.html | 2 +- src/BusinessLogic/Utility/UrlService.php | 4 +- .../Country/CountryServiceTest.php | 2 + .../Country/WarehouseCountryServiceTest.php | 2 + 21 files changed, 128 insertions(+), 97 deletions(-) create mode 100644 src/BusinessLogic/Resources/countries/at.json create mode 100644 src/BusinessLogic/Resources/countries/be.json create mode 100644 src/BusinessLogic/Resources/countries/gb.json create mode 100644 src/BusinessLogic/Resources/countries/hu.json create mode 100644 src/BusinessLogic/Resources/countries/ie.json create mode 100644 src/BusinessLogic/Resources/countries/nl.json create mode 100644 src/BusinessLogic/Resources/countries/pt.json create mode 100644 src/BusinessLogic/Resources/countries/tr.json diff --git a/src/BusinessLogic/Controllers/ConfigurationController.php b/src/BusinessLogic/Controllers/ConfigurationController.php index 97266643..0ced1430 100644 --- a/src/BusinessLogic/Controllers/ConfigurationController.php +++ b/src/BusinessLogic/Controllers/ConfigurationController.php @@ -2,6 +2,9 @@ namespace Packlink\BusinessLogic\Controllers; +use Logeecom\Infrastructure\Configuration\Configuration; +use Logeecom\Infrastructure\ServiceRegister; +use Packlink\BusinessLogic\Language\Interfaces\CountryService; use Packlink\BusinessLogic\Utility\UrlService; /** @@ -11,30 +14,17 @@ */ class ConfigurationController { - /** - * List of help URLs for different country codes. - * - * @var array - */ - private static $helpUrls = array( - 'EN' => 'https://support-pro.packlink.com/hc/en-gb', - 'ES' => 'https://support-pro.packlink.com/hc/es-es', - 'DE' => 'https://support-pro.packlink.com/hc/de', - 'FR' => 'https://support-pro.packlink.com/hc/fr-fr', - 'IT' => 'https://support-pro.packlink.com/hc/it', - ); - /** * @return mixed|string */ public function getHelpLink() { $lang = UrlService::getUrlLocaleKey(); + Configuration::setUICountryCode(strtolower($lang)); - if (!array_key_exists($lang, static::$helpUrls)) { - $lang = 'EN'; - } + /** @var CountryService $countryService */ + $countryService = ServiceRegister::getService(CountryService::CLASS_NAME); - return static::$helpUrls[$lang]; + return $countryService->getText('configuration.helpUrl'); } } diff --git a/src/BusinessLogic/Controllers/RegistrationController.php b/src/BusinessLogic/Controllers/RegistrationController.php index 25650485..2bfed281 100644 --- a/src/BusinessLogic/Controllers/RegistrationController.php +++ b/src/BusinessLogic/Controllers/RegistrationController.php @@ -6,6 +6,7 @@ use Logeecom\Infrastructure\ServiceRegister; use Packlink\BusinessLogic\Brand\BrandConfigurationService; use Packlink\BusinessLogic\DTO\FrontDtoFactory; +use Packlink\BusinessLogic\Language\Interfaces\CountryService; use Packlink\BusinessLogic\Registration\RegistrationInfoService; use Packlink\BusinessLogic\Registration\RegistrationRequest; use Packlink\BusinessLogic\Registration\RegistrationService; @@ -26,45 +27,9 @@ class RegistrationController */ protected $brandConfigurationService; /** - * List of terms and conditions URLs for different country codes. - * - * @var array - */ - private static $termsAndConditionsUrls = array( - 'EN' => 'https://support-pro.packlink.com/hc/en-gb/articles/360010011480', - 'ES' => 'https://pro.packlink.es/terminos-y-condiciones/', - 'DE' => 'https://pro.packlink.de/agb/', - 'FR' => 'https://pro.packlink.fr/conditions-generales/', - 'IT' => 'https://pro.packlink.it/termini-condizioni/', - 'AT' => 'https://support-pro.packlink.com/hc/de/articles/360010011480', - 'NL' => 'https://support-pro.packlink.com/hc/nl/articles/360010011480', - 'BE' => 'https://support-pro.packlink.com/hc/nl/articles/360010011480', - 'PT' => 'https://support-pro.packlink.com/hc/pt/articles/360010011480', - 'TR' => 'https://support-pro.packlink.com/hc/tr/articles/360010011480', - 'IE' => 'https://support-pro.packlink.com/hc/en-gb/articles/360010011480', - 'GB' => 'https://support-pro.packlink.com/hc/en-gb/articles/360010011480', - 'HU' => 'https://support-pro.packlink.com/hc/hu/articles/360010011480', - ); - /** - * List of terms and conditions URLs for different country codes. - * - * @var array + * @var CountryService */ - private static $privacyPolicyUrls = array( - 'EN' => 'https://support-pro.packlink.com/hc/en-gb/articles/360010011560', - 'ES' => 'https://support-pro.packlink.com/hc/es-es/articles/360010011560-Pol%C3%ADtica-de-Privacidad', - 'DE' => 'https://support-pro.packlink.com/hc/de/articles/360010011560-Datenschutzerkl%C3%A4rung-der-Packlink-Shipping-S-L-', - 'FR' => 'https://support-pro.packlink.com/hc/fr-fr/articles/360010011560-Politique-de-confidentialit%C3%A9', - 'IT' => 'https://support-pro.packlink.com/hc/it/articles/360010011560-Politica-di-Privacy', - 'AT' => 'https://support-pro.packlink.com/hc/de/articles/360010011480', - 'NL' => 'https://support-pro.packlink.com/hc/nl/articles/360010011560', - 'BE' => 'https://support-pro.packlink.com/hc/nl/articles/360010011560', - 'PT' => 'https://support-pro.packlink.com/hc/pt/articles/360010011560', - 'TR' => 'https://support-pro.packlink.com/hc/tr/articles/360010011560', - 'IE' => 'https://support-pro.packlink.com/hc/en-gb/articles/360010011560', - 'GB' => 'https://support-pro.packlink.com/hc/en-gb/articles/360010011560', - 'HU' => 'https://support-pro.packlink.com/hc/hu/articles/360010011560', - ); + protected $countryService; /** * Gets the data needed for a registration page. @@ -75,6 +40,7 @@ class RegistrationController */ public function getRegisterData($country) { + Configuration::setUICountryCode(strtolower($country)); /** @var RegistrationInfoService $registrationInfoService */ $registrationInfoService = ServiceRegister::getService(RegistrationInfoService::CLASS_NAME); $registrationData = $registrationInfoService->getRegistrationInfoData(); @@ -86,10 +52,8 @@ public function getRegisterData($country) 'email' => $registrationData->getEmail(), 'phone' => $registrationData->getPhone(), 'source' => $registrationData->getSource(), - 'termsAndConditionsUrl' => !empty(self::$termsAndConditionsUrls[$country]) ? - self::$termsAndConditionsUrls[$country] : self::$termsAndConditionsUrls[self::DEFAULT_COUNTRY], - 'privacyPolicyUrl' => !empty(self::$privacyPolicyUrls[$country]) ? - self::$privacyPolicyUrls[$country] : self::$privacyPolicyUrls[self::DEFAULT_COUNTRY], + 'termsAndConditionsUrl' => $this->getCountryService()->getText('register.termsAndConditionsUrl'), + 'privacyPolicyUrl' => $this->getCountryService()->getText('register.privacyPolicyUrl'), 'platform_country' => in_array($country, $brand->platformCountries, true) ? $country : $brand->platformCountries[0], ); @@ -177,6 +141,20 @@ protected function getBrandConfigurationService() return $this->brandConfigurationService; } + /** + * Returns an instance of country service. + * + * @return CountryService + */ + protected function getCountryService() + { + if ($this->countryService === null) { + $this->countryService = ServiceRegister::getService(CountryService::CLASS_NAME); + } + + return $this->countryService; + } + /** * Returns shop language in format which Packlink expects. * diff --git a/src/BusinessLogic/Country/CountryService.php b/src/BusinessLogic/Country/CountryService.php index b5ae8016..c921c044 100644 --- a/src/BusinessLogic/Country/CountryService.php +++ b/src/BusinessLogic/Country/CountryService.php @@ -33,24 +33,6 @@ class CountryService extends BaseService * @var BrandConfigurationService */ protected $brandConfigurationService; - /** - * List of four default countries. - * - * @var array - */ - protected static $baseCountries = array('ES', 'DE', 'FR', 'IT'); - - /** - * Checks if given country is one of the four base countries ('ES', 'DE', 'FR', 'IT'). - * - * @param string $countryCode Country ISO-2 code. - * - * @return bool - */ - public function isBaseCountry($countryCode) - { - return in_array(strtoupper($countryCode), static::$baseCountries, true); - } /** * Returns a list of supported country DTOs. diff --git a/src/BusinessLogic/OrderShipmentDetails/OrderShipmentDetailsService.php b/src/BusinessLogic/OrderShipmentDetails/OrderShipmentDetailsService.php index 2f6fe1ac..9813d748 100644 --- a/src/BusinessLogic/OrderShipmentDetails/OrderShipmentDetailsService.php +++ b/src/BusinessLogic/OrderShipmentDetails/OrderShipmentDetailsService.php @@ -5,8 +5,8 @@ use Logeecom\Infrastructure\Configuration\Configuration; use Logeecom\Infrastructure\ServiceRegister; use Packlink\BusinessLogic\BaseService; -use Packlink\BusinessLogic\Country\CountryService; use Packlink\BusinessLogic\Http\DTO\ShipmentLabel; +use Packlink\BusinessLogic\Language\Interfaces\CountryService; use Packlink\BusinessLogic\OrderShipmentDetails\Exceptions\OrderShipmentDetailsNotFound; use Packlink\BusinessLogic\OrderShipmentDetails\Models\OrderShipmentDetails; use Packlink\BusinessLogic\ShippingMethod\Utility\ShipmentStatus; @@ -273,14 +273,13 @@ protected function getDraftShipmentUrl($reference) $configService = ServiceRegister::getService(Configuration::CLASS_NAME); $userInfo = $configService->getUserInfo(); + if($userInfo) { + Configuration::setUICountryCode(strtolower($userInfo->country)); + } + /** @var CountryService $countryService */ $countryService = ServiceRegister::getService(CountryService::CLASS_NAME); - $userDomain = 'com'; - if ($userInfo !== null && $countryService->isBaseCountry($userInfo->country)) { - $userDomain = strtolower($userInfo->country); - } - - return "https://pro.packlink.$userDomain/private/shipments/$reference"; + return $countryService->getText('orderListAndDetails.shipmentUrl') . $reference; } } diff --git a/src/BusinessLogic/Resources/countries/at.json b/src/BusinessLogic/Resources/countries/at.json new file mode 100644 index 00000000..80e17cfc --- /dev/null +++ b/src/BusinessLogic/Resources/countries/at.json @@ -0,0 +1,6 @@ +{ + "register": { + "termsAndConditionsUrl": "https://support-pro.packlink.com/hc/de/articles/360010011480", + "privacyPolicyUrl": "https://support-pro.packlink.com/hc/de/articles/360010011480" + } +} \ No newline at end of file diff --git a/src/BusinessLogic/Resources/countries/be.json b/src/BusinessLogic/Resources/countries/be.json new file mode 100644 index 00000000..07d4b919 --- /dev/null +++ b/src/BusinessLogic/Resources/countries/be.json @@ -0,0 +1,6 @@ +{ + "register": { + "termsAndConditionsUrl": "https://support-pro.packlink.com/hc/nl/articles/360010011480", + "privacyPolicyUrl": "https://support-pro.packlink.com/hc/nl/articles/360010011560" + } +} \ No newline at end of file diff --git a/src/BusinessLogic/Resources/countries/de.json b/src/BusinessLogic/Resources/countries/de.json index c63762cb..c0c77ea8 100644 --- a/src/BusinessLogic/Resources/countries/de.json +++ b/src/BusinessLogic/Resources/countries/de.json @@ -89,6 +89,8 @@ "monthlyShipmentVolume": "Wie hoch ist Ihr monatliches Sendungsaufkommen?", "phone": "Telefonnummer", "termsAndConditions": "
Ich akzeptiere die Nutzungsbedingungen und die Datenschutzerklärung von Packlink
", + "termsAndConditionsUrl": "https://pro.packlink.de/agb/", + "privacyPolicyUrl": "https://support-pro.packlink.com/hc/de/articles/360010011560-Datenschutzerkl%%C3%%A4rung-der-Packlink-Shipping-S-L-", "marketingEmails": "Ich ermächtige Packlink Shipping S.L., mir kommerzielle Mitteilungen per E-Mail zuzusenden", "submit": "Registrieren", "chooseYourCountry": "Wählen Sie Ihr Land aus", @@ -151,7 +153,10 @@ "parcel": "Standardpaket", "help": "Hilfe", "contactUs": "Kontaktieren Sie uns:", - "systemInfo": "Systeminformationen" + "systemInfo": "Systeminformationen", + "helpUrl": "https://support-pro.packlink.com/hc/de", + "contactUrl": "business@packlink.com", + "contactUrlMail": "mailto::business@packlink.com" }, "systemInfo": { "title": "Systeminfodatei
und debug mode", @@ -288,7 +293,8 @@ "bulkFailCreateFail": "Die Datei der Versandetiketten konnte nicht erstellt werden", "draftOrderDelayed": "Die Erstellung des Entwurfs verzögert sich", "completeServicesSetup": "You need to complete the services setup to create order draft.", - "sendWithPacklink": "Send with Packlink" + "sendWithPacklink": "Send with Packlink", + "shipmentUrl": "https://pro.packlink.de/private/shipments/" }, "checkoutProcess": { "choseDropOffLocation": "Dieser Versanddienst unterstützt die Zustellung an vordefinierte Abgabestellen. Bitte wählen Sie den für Sie günstigsten Ort aus, indem Sie auf \"Abgabestelle auswählen\" klicken.", diff --git a/src/BusinessLogic/Resources/countries/en.json b/src/BusinessLogic/Resources/countries/en.json index 5cc5d3bb..4e4a0459 100644 --- a/src/BusinessLogic/Resources/countries/en.json +++ b/src/BusinessLogic/Resources/countries/en.json @@ -89,6 +89,8 @@ "monthlyShipmentVolume": "What is your monthly shipment volume?", "phone": "Phone number", "termsAndConditions": "
I accept the Terms of Service and the Privacy Policy of Packlink
", + "termsAndConditionsUrl": "https://support-pro.packlink.com/hc/en-gb/articles/360010011480", + "privacyPolicyUrl": "https://support-pro.packlink.com/hc/en-gb/articles/360010011560", "marketingEmails": "I authorise Packlink Shipping S.L. to send me commercial communications by e-mail", "submit": "Register", "chooseYourCountry": "Choose your country", @@ -151,7 +153,10 @@ "parcel": "Default parcel", "help": "Help", "contactUs": "Contact us at:", - "systemInfo": "System information" + "systemInfo": "System information", + "helpUrl": "https://support-pro.packlink.com/hc/en-gb", + "contactUrl": "business@packlink.com", + "contactUrlMail": "mailto::business@packlink.com" }, "systemInfo": { "title": "System information file
and debug mode", @@ -288,7 +293,8 @@ "bulkFailCreateFail": "Unable to create bulk labels file", "draftOrderDelayed": "Creation of the draft is delayed", "completeServicesSetup": "You need to complete the services setup to create order draft.", - "sendWithPacklink": "Send with Packlink" + "sendWithPacklink": "Send with Packlink", + "shipmentUrl": "https://pro.packlink.en/private/shipments/" }, "checkoutProcess": { "choseDropOffLocation": "This shipping service supports delivery to pre-defined drop-off locations. Please choose location that suits you the most by clicking on the \"Select drop-off location\" button.", diff --git a/src/BusinessLogic/Resources/countries/es.json b/src/BusinessLogic/Resources/countries/es.json index d914a7ba..4ebe1a1a 100644 --- a/src/BusinessLogic/Resources/countries/es.json +++ b/src/BusinessLogic/Resources/countries/es.json @@ -89,6 +89,8 @@ "monthlyShipmentVolume": "¿Cuántos envíos sueles hacer al mes?", "phone": "Teléfono", "termsAndConditions": "
Acepto los Términos y condiciones y la Política de privacidad de Packlink
", + "termsAndConditionsUrl": "https://pro.packlink.es/terminos-y-condiciones/", + "privacyPolicyUrl": "https://support-pro.packlink.com/hc/es-es/articles/360010011560-Pol%%C3%%ADtica-de-Privacidad", "marketingEmails": "Autorizo a Packlink Shipping S.L. a enviarme información comercial por correo electrónico", "submit": "Regístrate", "chooseYourCountry": "Elige tu país", @@ -151,7 +153,10 @@ "parcel": "Paquete predeterminado", "help": "Ayuda", "contactUs": "Contáctanos:", - "systemInfo": "Información del sistema" + "systemInfo": "Información del sistema", + "helpUrl": "https://support-pro.packlink.com/hc/es-es", + "contactUrl": "business@packlink.com", + "contactUrlMail": "mailto::business@packlink.com" }, "systemInfo": { "title": "System information file
and debug mode", @@ -288,7 +293,8 @@ "bulkFailCreateFail": "No se puede crear el archivo de etiquetas masivas", "draftOrderDelayed": "La creación del borrador se ha retrasado", "completeServicesSetup": "You need to complete the services setup to create order draft.", - "sendWithPacklink": "Send with Packlink" + "sendWithPacklink": "Send with Packlink", + "shipmentUrl": "https://pro.packlink.es/private/shipments/" }, "checkoutProcess": { "choseDropOffLocation": "Este servicio de envío admite la entrega a ubicaciones de entrega predefinidas. Elige la ubicación que más te convenga haciendo clic en el botón \"Seleccionar ubicación de entrega\"..", diff --git a/src/BusinessLogic/Resources/countries/fr.json b/src/BusinessLogic/Resources/countries/fr.json index 123550f2..c7a7906a 100644 --- a/src/BusinessLogic/Resources/countries/fr.json +++ b/src/BusinessLogic/Resources/countries/fr.json @@ -89,6 +89,8 @@ "monthlyShipmentVolume": "Combien d’envois faites-vous généralement par mois?", "phone": "Numéro de téléphone", "termsAndConditions": "
IJ’accepte les Conditions de service et la Politique de confidentialité de Packlink
", + "termsAndConditionsUrl": "https://pro.packlink.fr/conditions-generales/", + "privacyPolicyUrl": "https://support-pro.packlink.com/hc/fr-fr/articles/360010011560-Politique-de-confidentialit%%C3%%A9", "marketingEmails": "J’autorise Packlink Shipping S.L. à m’envoyer des communications commerciales par courriel", "submit": "S'inscrire", "chooseYourCountry": "Sélectionnez votre pays", @@ -151,7 +153,10 @@ "parcel": "Colis par défaut", "help": "Aide", "contactUs": "Contactez-nous:", - "systemInfo": "Informations du système" + "systemInfo": "Informations du système", + "helpUrl": "https://support-pro.packlink.com/hc/fr-fr", + "contactUrl": "business@packlink.com", + "contactUrlMail": "mailto::business@packlink.com" }, "systemInfo": { "title": "Fichier d’informations du système
et mode débogage", @@ -288,7 +293,8 @@ "bulkFailCreateFail": "Création d'un dossier d'étiquettes en masse impossible.", "draftOrderDelayed": "La création du brouillon a été retardée", "completeServicesSetup": "You need to complete the services setup to create order draft.", - "sendWithPacklink": "Send with Packlink" + "sendWithPacklink": "Send with Packlink", + "shipmentUrl": "https://pro.packlink.fr/private/shipments/" }, "checkoutProcess": { "choseDropOffLocation": "Ce service de transport soutient la livraison vers des lieux de dépôts prédéfinis. Veuillez choisir la localisation qui vous convient le mieux en cliquant sur le bouton \"Sélectionner le lieu de dépôt\"", diff --git a/src/BusinessLogic/Resources/countries/gb.json b/src/BusinessLogic/Resources/countries/gb.json new file mode 100644 index 00000000..0f805ad4 --- /dev/null +++ b/src/BusinessLogic/Resources/countries/gb.json @@ -0,0 +1,6 @@ +{ + "register": { + "termsAndConditionsUrl": "https://support-pro.packlink.com/hc/en-gb/articles/360010011480", + "privacyPolicyUrl": "https://support-pro.packlink.com/hc/en-gb/articles/360010011560" + } +} \ No newline at end of file diff --git a/src/BusinessLogic/Resources/countries/hu.json b/src/BusinessLogic/Resources/countries/hu.json new file mode 100644 index 00000000..82f12c8c --- /dev/null +++ b/src/BusinessLogic/Resources/countries/hu.json @@ -0,0 +1,6 @@ +{ + "register": { + "termsAndConditionsUrl": "https://support-pro.packlink.com/hc/hu/articles/360010011480", + "privacyPolicyUrl": "https://support-pro.packlink.com/hc/hu/articles/360010011560" + } +} \ No newline at end of file diff --git a/src/BusinessLogic/Resources/countries/ie.json b/src/BusinessLogic/Resources/countries/ie.json new file mode 100644 index 00000000..0f805ad4 --- /dev/null +++ b/src/BusinessLogic/Resources/countries/ie.json @@ -0,0 +1,6 @@ +{ + "register": { + "termsAndConditionsUrl": "https://support-pro.packlink.com/hc/en-gb/articles/360010011480", + "privacyPolicyUrl": "https://support-pro.packlink.com/hc/en-gb/articles/360010011560" + } +} \ No newline at end of file diff --git a/src/BusinessLogic/Resources/countries/it.json b/src/BusinessLogic/Resources/countries/it.json index 32edd36f..e10440f8 100644 --- a/src/BusinessLogic/Resources/countries/it.json +++ b/src/BusinessLogic/Resources/countries/it.json @@ -89,6 +89,8 @@ "monthlyShipmentVolume": "Quante spedizioni fai solitamente al mese?", "phone": "Numero di telefono", "termsAndConditions": "
Accetto i Termini del servizio e l’Informativa sulla privacy di Packlink
", + "termsAndConditionsUrl": "https://pro.packlink.it/termini-condizioni/", + "privacyPolicyUrl": "https://support-pro.packlink.com/hc/it/articles/360010011560-Politica-di-Privacy", "marketingEmails": "Autorizzo Packlink Shipping S.L. a inviarmi comunicazioni commerciali via email", "submit": "Registrati", "chooseYourCountry": "Scegli il paese", @@ -151,7 +153,10 @@ "parcel": "Pacco predefinito", "help": "Aiuto", "contactUs": "Contattaci:", - "systemInfo": "Informazioni del sistema" + "systemInfo": "Informazioni del sistema", + "helpUrl": "https://support-pro.packlink.com/hc/it", + "contactUrl": "business@packlink.com", + "contactUrlMail": "mailto::business@packlink.com" }, "systemInfo": { "title": "File di informazioni del sistema
e modalità debug", @@ -288,7 +293,8 @@ "bulkFailCreateFail": "Impossibile creare il file di etichette in blocco", "draftOrderDelayed": "La creazione della bozza è stata ritardata", "completeServicesSetup": "You need to complete the services setup to create order draft.", - "sendWithPacklink": "Send with Packlink" + "sendWithPacklink": "Send with Packlink", + "shipmentUrl": "https://pro.packlink.it/private/shipments/" }, "checkoutProcess": { "choseDropOffLocation": "Questo servizio di spedizione supporta la consegna a punti corriere predefiniti. Scegli la località più adatta a te, facendo clic sul pulsante \"Seleziona punto corriere\".", diff --git a/src/BusinessLogic/Resources/countries/nl.json b/src/BusinessLogic/Resources/countries/nl.json new file mode 100644 index 00000000..07d4b919 --- /dev/null +++ b/src/BusinessLogic/Resources/countries/nl.json @@ -0,0 +1,6 @@ +{ + "register": { + "termsAndConditionsUrl": "https://support-pro.packlink.com/hc/nl/articles/360010011480", + "privacyPolicyUrl": "https://support-pro.packlink.com/hc/nl/articles/360010011560" + } +} \ No newline at end of file diff --git a/src/BusinessLogic/Resources/countries/pt.json b/src/BusinessLogic/Resources/countries/pt.json new file mode 100644 index 00000000..a4a65b0f --- /dev/null +++ b/src/BusinessLogic/Resources/countries/pt.json @@ -0,0 +1,6 @@ +{ + "register": { + "termsAndConditionsUrl": "https://support-pro.packlink.com/hc/pt/articles/360010011480", + "privacyPolicyUrl": "https://support-pro.packlink.com/hc/pt/articles/360010011560" + } +} \ No newline at end of file diff --git a/src/BusinessLogic/Resources/countries/tr.json b/src/BusinessLogic/Resources/countries/tr.json new file mode 100644 index 00000000..ea17d41a --- /dev/null +++ b/src/BusinessLogic/Resources/countries/tr.json @@ -0,0 +1,6 @@ +{ + "register": { + "termsAndConditionsUrl": "https://support-pro.packlink.com/hc/tr/articles/360010011480", + "privacyPolicyUrl": "https://support-pro.packlink.com/hc/tr/articles/360010011560" + } +} \ No newline at end of file diff --git a/src/BusinessLogic/Resources/templates/configuration.html b/src/BusinessLogic/Resources/templates/configuration.html index 0c7ef492..00657bb3 100644 --- a/src/BusinessLogic/Resources/templates/configuration.html +++ b/src/BusinessLogic/Resources/templates/configuration.html @@ -49,7 +49,7 @@

{$configuration.menu}