Skip to content

Commit

Permalink
Merge pull request #31 from logeecom/dev
Browse files Browse the repository at this point in the history
Release v3.1.0
  • Loading branch information
logeecom authored Dec 17, 2020
2 parents de481ce + 4d83c54 commit 1bf9d72
Show file tree
Hide file tree
Showing 17 changed files with 875 additions and 101 deletions.
Binary file added PluginInstallation/3.1.0/packlink.zip
Binary file not shown.
6 changes: 6 additions & 0 deletions PluginInstallation/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

## [3.1.0](https://github.com/packlink-dev/prestashop_module/compare/v3.0.4...v3.1.0)
### Added
- Added compatibility with PrestaShop version 1.7.7.
- Added postal code transformer service that transforms postal code into supported postal code format for GB, NL, US and PT countries.
- Added new warehouse countries.

## [v3.0.4](https://github.com/packlink-dev/prestashop_module/compare/v3.0.2...v3.0.4) - 2020-11-10
### Changed
- Update to the latest core version 3.0.6.
Expand Down
186 changes: 133 additions & 53 deletions src/classes/Utility/AdminShippingTabDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Logeecom\Infrastructure\ServiceRegister;
use Logeecom\Infrastructure\TaskExecution\QueueItem;
use Logeecom\Infrastructure\Utility\TimeProvider;
use Packlink\BusinessLogic\Configuration;
use Packlink\BusinessLogic\Language\Translator;
use Packlink\BusinessLogic\Order\OrderService;
use Packlink\BusinessLogic\OrderShipmentDetails\Models\OrderShipmentDetails;
use Packlink\BusinessLogic\OrderShipmentDetails\OrderShipmentDetailsService;
Expand Down Expand Up @@ -47,6 +49,8 @@ public static function prepareShippingTabData(\Context $context, \Module $module
self::$context = $context;
self::$module = $module;

Configuration::setCurrentLanguage($context->language->iso_code);

/* @var OrderShipmentDetailsService $shipmentDetailsService */
$shipmentDetailsService = ServiceRegister::getService(OrderShipmentDetailsService::CLASS_NAME);

Expand All @@ -57,18 +61,7 @@ public static function prepareShippingTabData(\Context $context, \Module $module
self::prepareLabelsTemplate($shipmentDetails);
}

self::$context->smarty->assign(array(
'printLabelsUrl' => self::$context->link->getAdminLink('BulkShipmentLabels'),
'pluginBasePath' => self::$module->getPathUri(),
'orderId' => $orderId,
'createDraftUrl' => self::$context->link->getAdminLink('OrderDraft') . '&' .
http_build_query(
array(
'ajax' => true,
'action' => 'createOrderDraft',
)
),
));
self::$context->smarty->assign(self::getLinks($orderId));

self::$context->controller->addJS(
array(
Expand All @@ -82,6 +75,38 @@ public static function prepareShippingTabData(\Context $context, \Module $module
);
}

/**
* Returns shipping content data for the order with provided ID.
*
* @param \Context $context
* @param \Module $module
* @param int $orderId
*
* @return array
* @throws \Logeecom\Infrastructure\ORM\Exceptions\QueryFilterInvalidParamException
* @throws \Logeecom\Infrastructure\ORM\Exceptions\RepositoryNotRegisteredException
* @throws \PrestaShopDatabaseException
* @throws \PrestaShopException
*/
public static function getShippingContentData(\Context $context, \Module $module, $orderId)
{
Configuration::setCurrentLanguage($context->language->iso_code);

self::$context = $context;
self::$module = $module;

/* @var OrderShipmentDetailsService $shipmentDetailsService */
$shipmentDetailsService = ServiceRegister::getService(OrderShipmentDetailsService::CLASS_NAME);
$shipmentDetails = $shipmentDetailsService->getDetailsByOrderId($orderId);

return array_merge(
self::getLinks($orderId),
self::getDraftParams($orderId, $shipmentDetails),
self::getShippingDetails($orderId, $shipmentDetails),
$shipmentDetails ? self::getLabelParams($shipmentDetails) : array()
);
}

/**
* Prepares a section with a button for creating a shipment draft.
*
Expand All @@ -95,37 +120,11 @@ public static function prepareShippingTabData(\Context $context, \Module $module
*/
private static function prepareDraftButtonSection($orderId, $shipmentDetails = null)
{
/** @var ShipmentDraftService $shipmentDraftService */
$shipmentDraftService = ServiceRegister::getService(ShipmentDraftService::CLASS_NAME);

$draftStatus = $shipmentDraftService->getDraftStatus($orderId);
$displayDraftButton = true;

switch ($draftStatus->status) {
case ShipmentDraftStatus::NOT_QUEUED:
$message = TranslationUtility::__('Create order draft in Packlink PRO');
break;
case QueueItem::FAILED:
$message = TranslationUtility::__(
'Previous attempt to create a draft failed. Error: %s',
array($draftStatus->message)
);
break;
default:
$message = TranslationUtility::__('Draft is currently being created in Packlink');
$displayDraftButton = false;
break;
}

self::$context->smarty->assign(array(
'shipping' => !$displayDraftButton ? (object)self::prepareShippingObject($orderId, $shipmentDetails) : '',
'message' => $message,
'displayDraftButton' => $displayDraftButton,
));
self::$context->smarty->assign(self::getDraftParams($orderId, $shipmentDetails));
}

/**
* Prepares shipping details object for Packlink shipping tab.
* Returns shipping details for Packlink shipping tab.
*
* @param string $orderId ID of the order.
* @param OrderShipmentDetails $shipmentDetails Shipment details for an order.
Expand All @@ -137,10 +136,12 @@ private static function prepareDraftButtonSection($orderId, $shipmentDetails = n
* @throws \PrestaShopDatabaseException
* @throws \PrestaShopException
*/
private static function prepareShippingObject($orderId, OrderShipmentDetails $shipmentDetails = null)
private static function getShippingDetails($orderId, OrderShipmentDetails $shipmentDetails = null)
{
if ($shipmentDetails === null) {
return array();
return array(
'reference' => ''
);
}

/** @var TimeProvider $timeProvider */
Expand Down Expand Up @@ -191,6 +192,87 @@ private static function prepareLabelsTemplate(OrderShipmentDetails $shipmentDeta
false
);

self::$context->smarty->assign(self::getLabelParams($shipmentDetails));
}

/**
* Returns links for shipment details page.
*
* @param int $orderId
*
* @return array
*
* @throws \PrestaShopException
*/
private static function getLinks($orderId)
{
return array(
'printLabelsUrl' => self::$context->link->getAdminLink('BulkShipmentLabels'),
'pluginBasePath' => self::$module->getPathUri(),
'orderId' => $orderId,
'createDraftUrl' => self::$context->link->getAdminLink('OrderDraft') . '&' .
http_build_query(
array(
'ajax' => true,
'action' => 'createOrderDraft',
)
),
);
}

/**
* Returns order shipment draft parameters.
*
* @param int $orderId
* @param \Packlink\BusinessLogic\OrderShipmentDetails\Models\OrderShipmentDetails $shipmentDetails
*
* @return array
*
* @throws \Logeecom\Infrastructure\ORM\Exceptions\QueryFilterInvalidParamException
* @throws \Logeecom\Infrastructure\ORM\Exceptions\RepositoryNotRegisteredException
* @throws \PrestaShopDatabaseException
* @throws \PrestaShopException
*/
private static function getDraftParams($orderId, $shipmentDetails = null)
{
/** @var ShipmentDraftService $shipmentDraftService */
$shipmentDraftService = ServiceRegister::getService(ShipmentDraftService::CLASS_NAME);

$draftStatus = $shipmentDraftService->getDraftStatus($orderId);
$displayDraftButton = true;

switch ($draftStatus->status) {
case ShipmentDraftStatus::NOT_QUEUED:
$message = Translator::translate('orderListAndDetails.createOrderDraft');
break;
case QueueItem::FAILED:
$message = Translator::translate(
'orderListAndDetails.draftCreateFailed',
array($draftStatus->message)
);
break;
default:
$message = Translator::translate('orderListAndDetails.draftIsBeingCreated');
$displayDraftButton = false;
break;
}

return array(
'shipping' => !$displayDraftButton ? (object)self::getShippingDetails($orderId, $shipmentDetails) : '',
'message' => $message,
'displayDraftButton' => $displayDraftButton,
);
}

/**
* Returns order shipment label parameters.
*
* @param \Packlink\BusinessLogic\OrderShipmentDetails\Models\OrderShipmentDetails $shipmentDetails
*
* @return array
*/
private static function getLabelParams(OrderShipmentDetails $shipmentDetails)
{
/** @var OrderService $orderService */
$orderService = ServiceRegister::getService(OrderService::CLASS_NAME);

Expand All @@ -199,17 +281,15 @@ private static function prepareLabelsTemplate(OrderShipmentDetails $shipmentDeta

$isLabelPrinted = !empty($labels) && $labels[0]->isPrinted();

self::$context->smarty->assign(
array(
'orderId' => $shipmentDetails->getOrderId(),
'isLabelPrinted' => $isLabelPrinted,
'date' => !empty($labels) ? $labels[0]->getDateCreated()->format('d/m/Y') : '',
'status' => TranslationUtility::__(
$isLabelPrinted ? 'Printed' : 'Ready'
),
'isLabelAvailable' => !empty($labels) || $orderService->isReadyToFetchShipmentLabels($status),
'number' => '#PLSL1',
)
return array(
'orderId' => $shipmentDetails->getOrderId(),
'isLabelPrinted' => $isLabelPrinted,
'date' => !empty($labels) ? $labels[0]->getDateCreated()->format('d/m/Y') : '',
'status' => Translator::translate(
$isLabelPrinted ? 'orderListAndDetails.printed' : 'orderListAndDetails.ready'
),
'isLabelAvailable' => !empty($labels) || $orderService->isReadyToFetchShipmentLabels($status),
'number' => '#PLSL1',
);
}
}
42 changes: 40 additions & 2 deletions src/classes/Utility/PacklinkInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,22 @@ public function addControllersAndHooks()
return $this->addMenuItem() && $this->addHooks() && $this->addControllers();
}

/**
* Registers additional hooks for versions 1.7.7 and above.
*
* @return bool
*/
public function updateHooks()
{
$result = true;

foreach ($this->getAdditionalHooks() as $hook) {
$result = $result && $this->module->registerHook($hook);
}

return $result;
}

/**
* Adds Packlink menu item to shipping tab group.
*
Expand Down Expand Up @@ -188,8 +204,11 @@ public function addMenuItem()
*/
public function removeHooks()
{
$hooks = self::$hooks;
$hooks = array_merge($hooks, $this->getAdditionalHooks());

$result = true;
foreach (self::$hooks as $hook) {
foreach ($hooks as $hook) {
$result = $result && $this->module->unregisterHook($hook);
}

Expand Down Expand Up @@ -408,14 +427,33 @@ private function addDefaultPluginConfiguration()
*/
private function addHooks()
{
$hooks = self::$hooks;
$hooks = array_merge($hooks, $this->getAdditionalHooks());

$result = true;
foreach (self::$hooks as $hook) {

foreach ($hooks as $hook) {
$result = $result && $this->module->registerHook($hook);
}

return $result;
}

/**
* Returns the list of hooks used for PrestaShop versions 1.7.7 and above.
*
* @return array
*/
private function getAdditionalHooks() {
return array(
'actionAdminControllerSetMedia',
'actionOrderGridDefinitionModifier',
'actionOrderGridPresenterModifier',
'displayAdminOrderTabLink',
'displayAdminOrderTabContent',
);
}

/**
* Registers module controllers.
*
Expand Down
4 changes: 2 additions & 2 deletions src/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "packlink/prestashop",
"description": "Packlink Shipping PrestaShop plugin",
"type": "library",
"version": "3.0.4",
"version": "3.1.0",
"repositories": [
{
"type": "vcs",
Expand All @@ -13,7 +13,7 @@
"minimum-stability": "dev",
"require": {
"php": ">=5.3",
"packlink/integration-core": "3.0.6",
"packlink/integration-core": "3.1.0",
"ext-json": "*",
"ext-curl": "*",
"ext-zip": "*",
Expand Down
Loading

0 comments on commit 1bf9d72

Please sign in to comment.