Skip to content

Commit

Permalink
Merge pull request #3 from logeecom/feature/cr-16
Browse files Browse the repository at this point in the history
Feature CR-16 and release v0.9.0
  • Loading branch information
afidalgomoran82 committed Apr 13, 2020
2 parents b80a407 + 74f7d0f commit 36cd69e
Show file tree
Hide file tree
Showing 133 changed files with 1,535 additions and 1,616 deletions.
3 changes: 3 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions Packlink/Bootstrap/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@
use Logeecom\Infrastructure\TaskExecution\Process;
use Logeecom\Infrastructure\TaskExecution\QueueItem;
use Packlink\BusinessLogic\BootstrapComponent;
use Packlink\BusinessLogic\Order\Interfaces\OrderRepository as OrderRepositoryInterface;
use Packlink\BusinessLogic\Order\Models\OrderShipmentDetails;
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\OrderRepository;
use Packlink\Repositories\QueueItemRepository;
use Packlink\Services\BusinessLogic\ConfigurationService;
use Packlink\Services\Infrastructure\LoggerService;
Expand Down Expand Up @@ -68,9 +69,9 @@ function () {
);

ServiceRegister::registerService(
OrderRepositoryInterface::CLASS_NAME,
ShopOrderServiceInterface::CLASS_NAME,
function () {
return new OrderRepository();
return new ShopOrderService();
}
);

Expand Down Expand Up @@ -107,5 +108,6 @@ protected static function initRepositories()
RepositoryRegistry::registerRepository(ShippingMethod::getClassName(), BaseRepository::getClassName());
RepositoryRegistry::registerRepository(OrderDropoffMap::getClassName(), BaseRepository::getClassName());
RepositoryRegistry::registerRepository(LogData::CLASS_NAME, BaseRepository::getClassName());
RepositoryRegistry::registerRepository(OrderSendDraftTaskMap::getClassName(), BaseRepository::getClassName());
}
}
46 changes: 17 additions & 29 deletions Packlink/Controllers/Backend/PacklinkConfiguration.php
Original file line number Diff line number Diff line change
@@ -1,44 +1,36 @@
<?php

use Logeecom\Infrastructure\ServiceRegister;
use Packlink\BusinessLogic\Country\CountryService;
use Packlink\Controllers\Common\CanInstantiateServices;
use Packlink\Utilities\Translation;

class Shopware_Controllers_Backend_PacklinkConfiguration extends Enlight_Controller_Action
{
use CanInstantiateServices;
/**
* List of supported countries.
*
* @var array
*/
protected static $supportedCountries = [
'DE',
'ES',
'FR',
'IT',
];
/**
* List of help URLs for different country codes.
*
* @var array
*/
protected static $helpUrls = array(
'ES' => 'https://support-pro.packlink.com/hc/es-es/sections/202755109-Prestashop',
'DE' => 'https://support-pro.packlink.com/hc/de/sections/202755109-Prestashop',
'FR' => 'https://support-pro.packlink.com/hc/fr-fr/sections/202755109-Prestashop',
'IT' => 'https://support-pro.packlink.com/hc/it/sections/202755109-Prestashop',
);
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',
];
/**
* List of terms and conditions URLs for different country codes.
*
* @var array
*/
protected static $termsAndConditionsUrls = array(
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/',
);
];

/**
* Renders configuration page.
Expand All @@ -48,15 +40,11 @@ class Shopware_Controllers_Backend_PacklinkConfiguration extends Enlight_Control
public function indexAction()
{
$userInfo = $this->getConfigService()->getUserInfo();
/** @var \Packlink\BusinessLogic\Country\CountryService $countryService */
$countryService = ServiceRegister::getService(CountryService::CLASS_NAME);

$urlKey = 'ES';
if ($userInfo && $userInfo->country && in_array($userInfo->country, static::$supportedCountries)) {
$this->View()->assign(
[
'defaultWarehouse' => Translation::get("configuration/country/{$userInfo->country}"),
]
);

$urlKey = 'EN';
if ($userInfo && $countryService->isBaseCountry($userInfo->country)) {
$urlKey = $userInfo->country;
}

Expand All @@ -69,4 +57,4 @@ public function indexAction()
]
);
}
}
}
5 changes: 3 additions & 2 deletions Packlink/Controllers/Backend/PacklinkDashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public function indexAction()
{
$controller = new DashboardController();

Response::json($controller->getStatus()->toArray());
$status = $controller->getStatus();
Response::json($status->toArray());
}
}
}
52 changes: 12 additions & 40 deletions Packlink/Controllers/Backend/PacklinkDefaultParcel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,23 @@
use Packlink\Controllers\Common\CanInstantiateServices;
use Packlink\Utilities\Request;
use Packlink\Utilities\Response;
use Packlink\Utilities\Translation;

class Shopware_Controllers_Backend_PacklinkDefaultParcel extends Enlight_Controller_Action
{
use CanInstantiateServices;
/** @var array */
protected static $fields = [
'weight',
'width',
'height',
'length',
];

/**
* Retrieves default parcel.
*/
public function indexAction()
{
$parcel = $this->getConfigService()->getDefaultParcel();
$data = $parcel ? $parcel->toArray() : [];

Response::json($data);
if (!$parcel) {
Response::json();
}

Response::json($parcel->toArray());
}

/**
Expand All @@ -34,37 +29,14 @@ public function indexAction()
public function updateAction()
{
$data = Request::getPostData();
$validationResult = $this->validate($data);

if (!empty($validationResult)) {
Response::json($validationResult, 400);
}

$data['default'] = true;
$this->getConfigService()->setDefaultParcel(ParcelInfo::fromArray($data));

Response::json($data);
}

/**
* Validates default parcel.
*
* @param array $data
*
* @return array
*/
protected function validate(array $data)
{
$result = [];

foreach (self::$fields as $field) {
if (empty($data[$field])) {
$result[$field] = Translation::get('error/required');
} else if (!is_numeric($data[$field]) || $data[$field] <= 0) {
$result[$field] = Translation::get('error/number');
}
try {
$parcelInfo = ParcelInfo::fromArray($data);
$this->getConfigService()->setDefaultParcel($parcelInfo);
Response::json($parcelInfo->toArray());
} catch (\Packlink\BusinessLogic\DTO\Exceptions\FrontDtoValidationException $e) {
Response::validationErrorsResponse($e->getValidationErrors());
}

return $result;
}
}
}
108 changes: 32 additions & 76 deletions Packlink/Controllers/Backend/PacklinkDefaultWarehouse.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

use Logeecom\Infrastructure\Logger\Logger;
use Packlink\BusinessLogic\Http\DTO\Warehouse;
use Logeecom\Infrastructure\ServiceRegister;
use Packlink\BusinessLogic\Country\CountryService;
use Packlink\BusinessLogic\Warehouse\WarehouseService;
use Packlink\Controllers\Common\CanInstantiateServices;
use Packlink\Utilities\Request;
use Packlink\Utilities\Response;
Expand All @@ -10,48 +12,41 @@
class Shopware_Controllers_Backend_PacklinkDefaultWarehouse extends Enlight_Controller_Action
{
use CanInstantiateServices;
/** @var array */
protected static $fields = [
'alias',
'name',
'surname',
'country',
'postal_code',
'address',
'phone',
'email',
];

/**
* Retrieves default warehouse.
*/
public function indexAction()
{
$warehouse = $this->getConfigService()->getDefaultWarehouse();
if (!$warehouse) {
$userInfo = $this->configService->getUserInfo();
/** @noinspection NullPointerExceptionInspection */
$warehouse = Warehouse::fromArray(array('country' => $userInfo->country));
}
/** @var WarehouseService $warehouseService */
$warehouseService = ServiceRegister::getService(WarehouseService::CLASS_NAME);

$warehouse = $warehouseService->getWarehouse();

Response::json($warehouse->toArray());
}

/**
* Updates default warehouse.
*
* @throws \Packlink\BusinessLogic\DTO\Exceptions\FrontDtoNotRegisteredException
* @throws \Logeecom\Infrastructure\TaskExecution\Exceptions\QueueStorageUnavailableException
*/
public function updateAction()
{
$data = Request::getPostData();
$validationResult = $this->validate($data);
if (!empty($validationResult)) {
Response::json($validationResult, 400);
}

$data['default'] = true;
$this->getConfigService()->setDefaultWarehouse(Warehouse::fromArray($data));

Response::json($data);
/** @var WarehouseService $warehouseService */
$warehouseService = ServiceRegister::getService(WarehouseService::CLASS_NAME);

try {
$warehouse = $warehouseService->updateWarehouseData($data);

Response::json($warehouse->toArray());
} catch (\Packlink\BusinessLogic\DTO\Exceptions\FrontDtoValidationException $e) {
Response::validationErrorsResponse($e->getValidationErrors());
}
}

/**
Expand All @@ -60,73 +55,34 @@ public function updateAction()
public function searchAction()
{
$input = Request::getPostData();
if (empty($input['query'])) {
if (empty($input['query']) || empty($input['country'])) {
Response::json();
}

$country = $this->getConfigService()->getUserInfo()->country;

try {
$result = $this->getLocationService()->searchLocations($country, $input['query']);
$result = $this->getLocationService()->searchLocations($input['country'], $input['query']);
} catch (Exception $e) {
$result = [];

Logger::logError("Location search failed because: [{$e->getMessage()}]");
}

$arrayResult = [];
foreach ($result as $item) {
$arrayResult[] = $item->toArray();
}

Response::json($arrayResult);
Response::dtoEntitiesResponse($result);
}

/**
* Validates default warehouse.
*
* @param array $data
*
* @return array
* Returns countries supported by Packlink.
*/
protected function validate(array $data)
public function getCountriesAction()
{
$result = [];

foreach (self::$fields as $field) {
if (empty($data[$field])) {
$result[$field] = Translation::get('error/required');
}
}

if (!empty($data['country']) && !empty($data['postal_code'])) {
try {
$postalCodes = $this->getProxy()->getPostalCodes($data['country'], $data['postal_code']);
if (empty($postalCodes)) {
$result['postal_code'] = Translation::get('error/postalcode');
}
} catch (Exception $e) {
$result['postal_code'] = Translation::get('error/postalcode');
}
}

if (!empty($data['email']) && !filter_var($data['email'], FILTER_VALIDATE_EMAIL)) {
$result['email'] = Translation::get('error/email');
}

if (!empty($data['phone'])) {
$regex = '/^(\+|\/|\.|-|\(|\)|\d)+$/m';
$phoneError = !preg_match($regex, $data['phone']);

$digits = '/\d/m';
$match = preg_match_all($digits, $data['phone']);
$phoneError |= $match === false || $match < 3;
/** @var \Packlink\BusinessLogic\Country\CountryService $countryService */
$countryService = ServiceRegister::getService(CountryService::CLASS_NAME);
$supportedCountries = $countryService->getSupportedCountries();

if ($phoneError) {
$result['phone'] = Translation::get('error/phone');
}
foreach ($supportedCountries as $country) {
$country->name = Translation::get("configuration/country/{$country->code}");
}

return $result;
Response::dtoEntitiesResponse($supportedCountries);
}
}
}
Loading

0 comments on commit 36cd69e

Please sign in to comment.