Skip to content

Commit

Permalink
Merge pull request #13 from logeecom/feature/ui-redesign
Browse files Browse the repository at this point in the history
Release version 1.1.0
  • Loading branch information
logeecom authored Apr 28, 2021
2 parents ee3793c + 51a7964 commit 911b4be
Show file tree
Hide file tree
Showing 75 changed files with 3,381 additions and 2,756 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ build
./Packlink.zip
Packlink/Infrastructure
Packlink/BusinessLogic
Packlink/Tests/Core
Packlink/Tests/Core
Packlink/Resources/views/backend/_resources
31 changes: 19 additions & 12 deletions Packlink/Bootstrap/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

namespace Packlink\Bootstrap;

use Packlink\BusinessLogic\BootstrapComponent;
use Packlink\BusinessLogic\Order\Interfaces\ShopOrderService as ShopOrderServiceInterface;
use Packlink\BusinessLogic\OrderShipmentDetails\Models\OrderShipmentDetails;
use Packlink\BusinessLogic\Registration\RegistrationInfoService;
use Packlink\BusinessLogic\Scheduler\Models\Schedule;
use Packlink\BusinessLogic\ShipmentDraft\Models\OrderSendDraftTaskMap;
use Packlink\BusinessLogic\ShippingMethod\Interfaces\ShopShippingMethodService;
use Packlink\BusinessLogic\ShippingMethod\Models\ShippingMethod;
use Packlink\Contracts\Services\BusinessLogic\DebugService;
use Packlink\Entities\OrderDropoffMap;
use Packlink\Entities\ShippingMethodMap;
use Packlink\Infrastructure\Configuration\ConfigEntity;
use Packlink\Infrastructure\Configuration\Configuration;
use Packlink\Infrastructure\Http\CurlHttpClient;
Expand All @@ -14,22 +25,12 @@
use Packlink\Infrastructure\ServiceRegister;
use Packlink\Infrastructure\TaskExecution\Process;
use Packlink\Infrastructure\TaskExecution\QueueItem;
use Packlink\BusinessLogic\BootstrapComponent;
use Packlink\BusinessLogic\Order\Interfaces\ShopOrderService as ShopOrderServiceInterface;
use Packlink\BusinessLogic\ShipmentDraft\Models\OrderSendDraftTaskMap;
use Packlink\Services\BusinessLogic\ShopOrderService;
use Packlink\BusinessLogic\OrderShipmentDetails\Models\OrderShipmentDetails;
use Packlink\BusinessLogic\Scheduler\Models\Schedule;
use Packlink\BusinessLogic\ShippingMethod\Interfaces\ShopShippingMethodService;
use Packlink\BusinessLogic\ShippingMethod\Models\ShippingMethod;
use Packlink\Contracts\Services\BusinessLogic\DebugService;
use Packlink\Entities\OrderDropoffMap;
use Packlink\Entities\ShippingMethodMap;
use Packlink\Repositories\BaseRepository;
use Packlink\Repositories\QueueItemRepository;
use Packlink\Services\BusinessLogic\ConfigurationService;
use Packlink\Services\Infrastructure\LoggerService;
use Packlink\Services\BusinessLogic\ShopOrderService;
use Packlink\Services\BusinessLogic\ShopShippingMethodService as ConcreteShopShippingMethodService;
use Packlink\Services\Infrastructure\LoggerService;

class Bootstrap extends BootstrapComponent
{
Expand Down Expand Up @@ -88,6 +89,12 @@ function () {
return new \Packlink\Services\BusinessLogic\DebugService();
}
);

ServiceRegister::registerService(
RegistrationInfoService::class,
function () {
return new \Packlink\Services\BusinessLogic\RegistrationInfoService();
});
}

/**
Expand Down
304 changes: 263 additions & 41 deletions Packlink/Controllers/Backend/PacklinkConfiguration.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,60 +1,282 @@
<?php

use Packlink\Infrastructure\ServiceRegister;
use Packlink\BusinessLogic\Country\CountryService;
use Packlink\Controllers\Common\CanInstantiateServices;
use Packlink\BusinessLogic\Configuration;
use Packlink\BusinessLogic\Controllers\ConfigurationController;
use Packlink\BusinessLogic\Controllers\LoginController;
use Packlink\Utilities\Plugin;
use Packlink\Utilities\Request;
use Packlink\Utilities\Response;
use Packlink\Utilities\Shop;
use Packlink\Utilities\Url;
use Shopware\Components\CSRFWhitelistAware;

class Shopware_Controllers_Backend_PacklinkConfiguration extends Enlight_Controller_Action
/**
* Class Shopware_Controllers_Backend_PacklinkConfiguration
*/
class Shopware_Controllers_Backend_PacklinkConfiguration extends Enlight_Controller_Action implements CSRFWhitelistAware
{
use CanInstantiateServices;
/**
* List of help URLs for different country codes.
* @inheritDoc
*/
public function getWhitelistedCSRFActions()
{
return ['index', 'getData'];
}

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

$data = Request::getPostData();

if (!empty($data['method']) && $data['method'] === 'Login') {
$this->View()->assign($this->login());
} else {
$this->View()->assign([
$this->getHelpUrl(),
'version' => Plugin::getVersion(),
]);
}
}

/**
* Gets data for StateController initialization.
*/
public function getDataAction()
{
Response::json([
'baseResourcesUrl' => '/custom/plugins/Packlink/Resources/views/backend/_resources/packlink',
'stateUrl' => Url::getBackendUrl(
'PacklinkModuleStateController',
'getCurrentState'
),
'urls' => $this->getUrls(),
'templates' => $this->getTemplates(),
'lang' => $this->getTranslations(),
]);
}

/**
* Retrieves help link.
*/
public function getHelpLinkAction()
{
Response::json([
'helpUrl' => $this->getHelpUrl(),
'version' => Plugin::getVersion(),
]);
}

/**
* Attempts to log the user in with the provided Packlink API key.
*/
public function loginAction()
{
Response::json(['success' => $this->login()]);
}

/**
* @return mixed|string
*/
protected function getHelpUrl()
{
$controller = new ConfigurationController();

return $controller->getHelpLink();
}

/**
* @return bool
*/
protected function login()
{
$data = Request::getPostData();
$controller = new LoginController();

return $controller->login(!empty($data['apiKey']) ? $data['apiKey'] : '');
}

/**
* Returns Packlink module templates.
*/
protected function getTemplates()
{
$baseDir = __DIR__ . '/../../Resources/views/backend/_resources/packlink/templates/';

return [
'pl-configuration-page' => [
'pl-main-page-holder' => file_get_contents($baseDir . 'configuration.html'),
],
'pl-countries-selection-modal' => file_get_contents($baseDir . 'countries-selection-modal.html'),
'pl-default-parcel-page' => [
'pl-main-page-holder' => file_get_contents($baseDir . 'default-parcel.html'),
],
'pl-default-warehouse-page' => [
'pl-main-page-holder' => file_get_contents($baseDir . 'default-warehouse.html'),
],
'pl-disable-carriers-modal' => file_get_contents($baseDir . 'disable-carriers-modal.html'),
'pl-edit-service-page' => [
'pl-header-section' => '',
'pl-main-page-holder' => file_get_contents($baseDir . 'edit-shipping-service.html'),
'pl-pricing-policies' => file_get_contents($baseDir . 'pricing-policies-list.html'),
],
'pl-login-page' => [
'pl-main-page-holder' => file_get_contents($baseDir . 'login.html'),
],
'pl-my-shipping-services-page' => [
'pl-main-page-holder' => file_get_contents($baseDir . 'my-shipping-services.html'),
'pl-header-section' => file_get_contents($baseDir . 'shipping-services-header.html'),
'pl-shipping-services-table' => file_get_contents($baseDir . 'shipping-services-table.html'),
'pl-shipping-services-list' => file_get_contents($baseDir . 'shipping-services-list.html'),
],
'pl-onboarding-overview-page' => [
'pl-main-page-holder' => file_get_contents($baseDir . 'onboarding-overview.html'),
],
'pl-onboarding-welcome-page' => [
'pl-main-page-holder' => file_get_contents($baseDir . 'onboarding-welcome.html'),
],
'pl-order-status-mapping-page' => [
'pl-main-page-holder' => file_get_contents($baseDir . 'order-status-mapping.html'),
],
'pl-pick-service-page' => [
'pl-header-section' => '',
'pl-main-page-holder' => file_get_contents($baseDir . 'pick-shipping-services.html'),
'pl-shipping-services-table' => file_get_contents($baseDir . 'shipping-services-table.html'),
'pl-shipping-services-list' => file_get_contents($baseDir . 'shipping-services-list.html'),
],
'pl-pricing-policy-modal' => file_get_contents($baseDir . 'pricing-policy-modal.html'),
'pl-register-page' => [
'pl-main-page-holder' => file_get_contents($baseDir . 'register.html'),
],
'pl-register-modal' => file_get_contents($baseDir . 'register-modal.html'),
'pl-system-info-modal' => file_get_contents($baseDir . 'system-info-modal.html'),
];
}

/**
* Returns Packlink module controller URLs.
*/
protected function getUrls()
{
$shopUrl = $this->request->getServer()['REQUEST_SCHEME'] . '://' . Shop::getDefaultShop()->getHost();

return [
'login' => [
'submit' => Url::getBackendUrl('PacklinkConfiguration', 'login'),
'listOfCountriesUrl' => Url::getBackendUrl('PacklinkRegistrationRegionsController', 'getRegions'),
'logoPath' => '',
],
'register' => [
'getRegistrationData' => $shopUrl . Url::getBackendUrl(
'PacklinkRegistrationController',
'getRegisterData'
),
'submit' => Url::getBackendUrl('PacklinkRegistrationController', 'register'),
],
'onboarding-state' => [
'getState' => Url::getBackendUrl('PacklinkOnboardingController', 'getCurrentState'),
],
'onboarding-welcome' => [],
'onboarding-overview' => [
'defaultParcelGet' => Url::getBackendUrl('PacklinkDefaultParcel', 'index'),
'defaultWarehouseGet' => Url::getBackendUrl('PacklinkDefaultWarehouse', 'index'),
],
'default-parcel' => [
'getUrl' => Url::getBackendUrl('PacklinkDefaultParcel', 'index'),
'submitUrl' => Url::getBackendUrl('PacklinkDefaultParcel', 'update'),
],
'default-warehouse' => [
'getUrl' => Url::getBackendUrl('PacklinkDefaultWarehouse', 'index'),
'getSupportedCountriesUrl' => Url::getBackendUrl('PacklinkDefaultWarehouse', 'getCountries'),
'submitUrl' => Url::getBackendUrl('PacklinkDefaultWarehouse', 'update'),
'searchPostalCodesUrl' => Url::getBackendUrl('PacklinkDefaultWarehouse', 'search'),
],
'configuration' => [
'getDataUrl' => Url::getBackendUrl('PacklinkConfiguration', 'getHelpLink'),
],
'system-info' => [
'getStatusUrl' => Url::getBackendUrl('PacklinkDebug', 'getStatus'),
'setStatusUrl' => Url::getBackendUrl('PacklinkDebug', 'updateStatus'),
],
'order-status-mapping' => [
'getMappingAndStatusesUrl' => Url::getBackendUrl('PacklinkOrderStatusMap', 'index'),
'setUrl' => Url::getBackendUrl('PacklinkOrderStatusMap', 'update'),
],
'my-shipping-services' => [
'getServicesUrl' => Url::getBackendUrl('PacklinkShippingMethod', 'getActive'),
'deleteServiceUrl' => Url::getBackendUrl('PacklinkShippingMethod', 'deactivate'),
],
'pick-shipping-service' => [
'getActiveServicesUrl' => Url::getBackendUrl('PacklinkShippingMethod', 'getActive'),
'getServicesUrl' => Url::getBackendUrl('PacklinkShippingMethod', 'getInactive'),
'getTaskStatusUrl' => Url::getBackendUrl('PacklinkShippingMethod', 'getTaskStatus'),
'startAutoConfigureUrl' => Url::getBackendUrl('PacklinkAutoConfigure', 'index'),
'disableCarriersUrl' => Url::getBackendUrl(
'PacklinkShopShippingMethod',
'deactivateShopShippingMethods'
),
],
'edit-service' => [
'getServiceUrl' => $shopUrl . Url::getBackendUrl('PacklinkShippingMethod', 'getShippingMethod'),
'saveServiceUrl' => Url::getBackendUrl('PacklinkShippingMethod', 'save'),
'getTaxClassesUrl' => Url::getBackendUrl('PacklinkShippingMethod', 'getTaxClasses'),
'getCountriesListUrl' => Url::getBackendUrl('PacklinkShippingCountriesController', 'getAll'),
'hasTaxConfiguration' => true,
'hasCountryConfiguration' => true,
'canDisplayCarrierLogos' => true,
],
];
}

/**
* Returns Packlink module translations in the default and the current system language.
*
* @var array
* @return array
*/
protected static $helpUrls = [
'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',
];
protected function getTranslations()
{
return [
'default' => $this->getDefaultTranslations(),
'current' => $this->getCurrentTranslations(),
];
}

/**
* List of terms and conditions URLs for different country codes.
* Returns JSON encoded module page translations in the default language and some module-specific translations.
*
* @var array
* @return mixed
*/
protected static $termsAndConditionsUrls = [
'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/',
];
protected function getDefaultTranslations()
{
$baseDir = __DIR__ . '/../../Resources/views/backend/_resources/packlink/lang/';

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

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

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

/**
* @return string
*/
protected function getLocale()
{
$userInfo = $this->getConfigService()->getUserInfo();
/** @var \Packlink\BusinessLogic\Country\CountryService $countryService */
$countryService = ServiceRegister::getService(CountryService::CLASS_NAME);
$locale = 'en';

$urlKey = 'EN';
if ($userInfo && $countryService->isBaseCountry($userInfo->country)) {
$urlKey = $userInfo->country;
if ($auth = Shopware()->Container()->get('auth')) {
$locale = substr($auth->getIdentity()->locale->getLocale(), 0, 2);
}

$this->View()->assign(
[
'helpUrl' => self::$helpUrls[$urlKey],
'termsUrl' => self::$termsAndConditionsUrls[$urlKey],
'pluginVersion' => $this->configService->getModuleVersion(),
'csrfToken' => $this->container->get('BackendSession')->offsetGet('X-CSRF-Token'),
]
);
return in_array($locale, ['en', 'de', 'es', 'fr', 'it']) ? $locale : 'en';
}
}
}
Loading

0 comments on commit 911b4be

Please sign in to comment.