Skip to content

Commit

Permalink
Merge pull request #15 from logeecom/feature/multi-currency-support
Browse files Browse the repository at this point in the history
Release version 1.3.0
  • Loading branch information
logeecom authored Jul 12, 2021
2 parents de5d58f + f72e85a commit 30986e4
Show file tree
Hide file tree
Showing 29 changed files with 344 additions and 52 deletions.
16 changes: 15 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,19 @@ build
./Packlink.zip
Packlink/Infrastructure
Packlink/BusinessLogic
Packlink/Brands
Packlink/Tests/Core
Packlink/Resources/views/backend/_resources
Packlink/Resources/views/backend/_resources/packlink/countries/*
Packlink/Resources/views/backend/_resources/packlink/brand/*
Packlink/Resources/views/backend/_resources/packlink/css/*
Packlink/Resources/views/backend/_resources/packlink/images/*
Packlink/Resources/views/backend/_resources/packlink/js/*
Packlink/Resources/views/backend/_resources/packlink/location/*
Packlink/Resources/views/backend/_resources/packlink/templates/*
!Packlink/Resources/views/backend/_resources/packlink/countries/.gitkeep
!Packlink/Resources/views/backend/_resources/packlink/brand/.gitkeep
!Packlink/Resources/views/backend/_resources/packlink/css/.gitkeep
!Packlink/Resources/views/backend/_resources/packlink/images/.gitkeep
!Packlink/Resources/views/backend/_resources/packlink/js/.gitkeep
!Packlink/Resources/views/backend/_resources/packlink/location/.gitkeep
!Packlink/Resources/views/backend/_resources/packlink/templates/.gitkeep
29 changes: 29 additions & 0 deletions Packlink/Bootstrap/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace Packlink\Bootstrap;

use Packlink\Brands\Packlink\PacklinkConfigurationService;
use Packlink\BusinessLogic\BootstrapComponent;
use Packlink\BusinessLogic\Brand\BrandConfigurationService;
use Packlink\BusinessLogic\FileResolver\FileResolverService;
use Packlink\BusinessLogic\Order\Interfaces\ShopOrderService as ShopOrderServiceInterface;
use Packlink\BusinessLogic\OrderShipmentDetails\Models\OrderShipmentDetails;
use Packlink\BusinessLogic\Registration\RegistrationInfoService;
Expand Down Expand Up @@ -30,6 +33,8 @@
use Packlink\Services\BusinessLogic\ConfigurationService;
use Packlink\Services\BusinessLogic\ShopOrderService;
use Packlink\Services\BusinessLogic\ShopShippingMethodService as ConcreteShopShippingMethodService;
use Packlink\BusinessLogic\SystemInformation\SystemInfoService as SystemInfoInterface;
use Packlink\Services\BusinessLogic\SystemInfoService;
use Packlink\Services\Infrastructure\LoggerService;

class Bootstrap extends BootstrapComponent
Expand Down Expand Up @@ -62,6 +67,13 @@ function () {
}
);

ServiceRegister::registerService(
BrandConfigurationService::CLASS_NAME,
static function () {
return new PacklinkConfigurationService();
}
);

ServiceRegister::registerService(
HttpClient::CLASS_NAME,
function () {
Expand Down Expand Up @@ -95,6 +107,23 @@ function () {
function () {
return new \Packlink\Services\BusinessLogic\RegistrationInfoService();
});

ServiceRegister::registerService(
SystemInfoInterface::class,
function () {
return new SystemInfoService();
}
);

ServiceRegister::registerService(
FileResolverService::CLASS_NAME,
function () {
return new FileResolverService([
__DIR__ . '/../BusinessLogic/Resources/countries',
__DIR__ . '/../Brands/Packlink/Resources/countries',
]);
}
);
}

/**
Expand Down
45 changes: 17 additions & 28 deletions Packlink/Controllers/Backend/PacklinkConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Packlink\Utilities\Shop;
use Packlink\Utilities\Url;
use Shopware\Components\CSRFWhitelistAware;
use Packlink\BusinessLogic\CountryLabels\Interfaces\CountryService;
use Packlink\Infrastructure\ServiceRegister;

/**
* Class Shopware_Controllers_Backend_PacklinkConfiguration
Expand All @@ -25,7 +27,7 @@ public function getWhitelistedCSRFActions()

public function indexAction()
{
Configuration::setCurrentLanguage($this->getLocale());
Configuration::setUICountryCode($this->getLocale());

$data = Request::getPostData();

Expand Down Expand Up @@ -205,6 +207,8 @@ protected function getUrls()
'my-shipping-services' => [
'getServicesUrl' => Url::getBackendUrl('PacklinkShippingMethod', 'getActive'),
'deleteServiceUrl' => Url::getBackendUrl('PacklinkShippingMethod', 'deactivate'),
'getCurrencyDetailsUrl' => Url::getBackendUrl('PacklinkSystemInfoController', 'get'),
'systemId' => (string)Shop::getDefaultShop()->getId()
],
'pick-shipping-service' => [
'getActiveServicesUrl' => Url::getBackendUrl('PacklinkShippingMethod', 'getActive'),
Expand All @@ -215,6 +219,8 @@ protected function getUrls()
'PacklinkShopShippingMethod',
'deactivateShopShippingMethods'
),
'getCurrencyDetailsUrl' => Url::getBackendUrl('PacklinkSystemInfoController', 'get'),
'systemId' => (string)Shop::getDefaultShop()->getId()
],
'edit-service' => [
'getServiceUrl' => $shopUrl . Url::getBackendUrl('PacklinkShippingMethod', 'getShippingMethod'),
Expand All @@ -224,6 +230,7 @@ protected function getUrls()
'hasTaxConfiguration' => true,
'hasCountryConfiguration' => true,
'canDisplayCarrierLogos' => true,
'getCurrencyDetailsUrl' => Url::getBackendUrl('PacklinkSystemInfoController', 'get')
],
];
}
Expand All @@ -235,35 +242,17 @@ protected function getUrls()
*/
protected function getTranslations()
{
return [
'default' => $this->getDefaultTranslations(),
'current' => $this->getCurrentTranslations(),
];
}

/**
* Returns JSON encoded module page translations in the default language and some module-specific translations.
*
* @return mixed
*/
protected function getDefaultTranslations()
{
$baseDir = __DIR__ . '/../../Resources/views/backend/_resources/packlink/lang/';

return json_decode(file_get_contents($baseDir . 'en.json'), true);
}

/**
* Returns JSON encoded module page translations in the current language and some module-specific translations.
*
* @return mixed
*/
protected function getCurrentTranslations()
{
$baseDir = __DIR__ . '/../../Resources/views/backend/_resources/packlink/lang/';
$locale = $this->getLocale();

return json_decode(file_get_contents($baseDir . $locale . '.json'), true);
/** @var CountryService $countryService */
$countryService = ServiceRegister::getService(CountryService::class);
$default = $countryService->getAllLabels('en');
$current_lang = $countryService->getAllLabels($locale);

return [
'default' => $default['en'],
'current' => $current_lang[$locale],
];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Packlink/Controllers/Backend/PacklinkDefaultWarehouse.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function searchAction()
*/
public function getCountriesAction()
{
Configuration::setCurrentLanguage($this->getLocale());
Configuration::setUICountryCode($this->getLocale());
$warehouseController = new WarehouseController();

Response::dtoEntitiesResponse($warehouseController->getWarehouseCountries());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ public function indexAction()

$details = [
'orderCost' => $order->getInvoiceShipping(),
'orderCurrency' => '(' . $order->getCurrency() . ')',
'cost' => $orderDetails->getShippingCost(),
'currency' => '(' . $orderDetails->getCurrency() . ')',
'status' => Translation::get('shipment/packlink/status/' . $orderDetails->getStatus()),
'reference' => $orderDetails->getReference(),
'isLabelsAvailable' => false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Shopware_Controllers_Backend_PacklinkRegistrationRegionsController extends
*/
public function getRegionsAction()
{
Configuration::setCurrentLanguage($this->getLocale());
Configuration::setUICountryCode($this->getLocale());
$controller = new RegistrationRegionsController();

Response::dtoEntitiesResponse($controller->getRegions());
Expand Down
47 changes: 47 additions & 0 deletions Packlink/Controllers/Backend/PacklinkSystemInfoController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

use Packlink\BusinessLogic\Controllers\SystemInfoController;
use Packlink\Utilities\Response;

/**
* Class Shopware_Controllers_Backend_PacklinkSystemInfo
*/
class Shopware_Controllers_Backend_PacklinkSystemInfoController extends Enlight_Controller_Action
{
/**
* @var SystemInfoController
*/
private $baseController;

/**
* Returns a list with actions which should not be validated for CSRF protection
*
* @return string[]
*/
public function getWhitelistedCSRFActions()
{
return [
'get'
];
}

/**
* Returns system information.
*/
public function getAction()
{
Response::dtoEntitiesResponse($this->getBaseController()->get());
}

/**
* @return SystemInfoController
*/
protected function getBaseController()
{
if ($this->baseController === null) {
$this->baseController = new SystemInfoController();
}

return $this->baseController;
}
}
6 changes: 4 additions & 2 deletions Packlink/Lib/Composer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class Composer
{
protected static $fromBase = __DIR__ . '/../vendor/packlink/integration-core/src/BusinessLogic/Resources/';
protected static $brandBase = __DIR__ . '/../vendor/packlink/integration-core/src/Brands/Packlink/Resources/';
protected static $toBase = __DIR__ . '/../Resources/views/backend/_resources/';


Expand All @@ -17,7 +18,8 @@ public static function postUpdate()
$map = [
static::$fromBase . 'js' => static::$toBase . 'packlink/js',
static::$fromBase . 'css' => static::$toBase . 'packlink/css',
static::$fromBase . 'lang' => static::$toBase . 'packlink/lang',
static::$fromBase . 'countries' => static::$toBase . 'packlink/countries',
static::$brandBase . 'countries' => static::$toBase . 'packlink/brand/countries',
static::$fromBase . 'templates' => static::$toBase . 'packlink/templates',
static::$fromBase . 'images' => static::$toBase . 'packlink/images',
static::$fromBase . 'LocationPicker' => static::$toBase . 'packlink/location',
Expand Down Expand Up @@ -63,7 +65,7 @@ private static function copyDirectory($src, $dst)
*/
private static function mkdir($destination)
{
if (!file_exists($destination) && !mkdir($destination) && !is_dir($destination)) {
if (!file_exists($destination) && !mkdir($destination, 0777, true) && !is_dir($destination)) {
throw new RuntimeException(sprintf('Directory "%s" was not created', $destination));
}
}
Expand Down
6 changes: 1 addition & 5 deletions Packlink/Migrations/Scripts/migration.v.0.9.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Packlink\Infrastructure\TaskExecution\Exceptions\QueueStorageUnavailableException;
use Packlink\Infrastructure\TaskExecution\QueueItem;
use Packlink\Infrastructure\TaskExecution\QueueService;
use Packlink\BusinessLogic\Country\CountryService;
use Packlink\BusinessLogic\OrderShipmentDetails\Models\OrderShipmentDetails;
use Packlink\BusinessLogic\Scheduler\Models\HourlySchedule;
use Packlink\BusinessLogic\Scheduler\Models\Schedule;
Expand Down Expand Up @@ -53,12 +52,9 @@
$orderShipmentDetailsRepository = RepositoryRegistry::getRepository(OrderShipmentDetails::getClassName());
$orderSendDraftRepository = RepositoryRegistry::getRepository(OrderSendDraftTaskMap::getClassName());

/** @var CountryService $countryService */
$countryService = ServiceRegister::getService(CountryService::CLASS_NAME);

$userInfo = $configuration->getUserInfo();
$userDomain = 'com';
if ($userInfo && $countryService->isBaseCountry($userInfo->country)) {
if ($userInfo && in_array($userInfo->country, array('ES', 'DE', 'FR', 'IT'))) {
$userDomain = strtolower($userInfo->country);
}

Expand Down
Loading

0 comments on commit 30986e4

Please sign in to comment.