-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from logeecom/feature/ui-redesign
Release version 1.1.0
- Loading branch information
Showing
75 changed files
with
3,381 additions
and
2,756 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
304 changes: 263 additions & 41 deletions
304
Packlink/Controllers/Backend/PacklinkConfiguration.php
100644 → 100755
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} | ||
} | ||
} |
Oops, something went wrong.