Skip to content

Commit

Permalink
Merge pull request #528 from tig-nl/sprint201_release_1_12_5
Browse files Browse the repository at this point in the history
Sprint201 release 1.12.5
  • Loading branch information
tig-luuksmal authored Nov 16, 2022
2 parents d662551 + 1a3b8db commit 76958c1
Show file tree
Hide file tree
Showing 91 changed files with 2,982 additions and 634 deletions.
34 changes: 34 additions & 0 deletions Api/Data/ShipmentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,42 @@ public function setReturnBarcode($value);
*/
public function getReturnBarcodes();

/**
* @param $value
*
* @return TIG\PostNL\Api\Data\ShipmentInterface
*/
public function setIsSmartReturn($value);

/**
* @return boolean
*/
public function getIsSmartReturn();

/**
* @return \TIG\PostNL\Api\Data\OrderInterface
*/
public function getPostNLOrder();

/**
* @param string $value
* @return \TIG\PostNL\Api\Data\ShipmentInterface
*/
public function setSmartReturnBarcode($value);

/**
* @return string
*/
public function getSmartReturnBarcode();

/**
* @param $value
* @return boolean
*/
public function setSmartReturnEmailSent($value);

/**
* @return boolean
*/
public function getSmartReturnEmailSent();
}
6 changes: 3 additions & 3 deletions Api/MatrixrateRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ interface MatrixrateRepositoryInterface
/**
* Save a Matrixrate rule
* @param MatrixrateInterface $matrixrate
* @return MatrixrateInterface
* @return \TIG\PostNL\Api\Data\MatrixrateInterface
* @api
*
*/
Expand All @@ -51,7 +51,7 @@ public function save(MatrixrateInterface $matrixrate);
* Retrieve a list of Matrixrates.
* @api
* @param SearchCriteriaInterface $criteria
* @return SearchResultsInterface
* @return \Magento\Framework\Api\SearchResultsInterface
*/
public function getList(SearchCriteriaInterface $criteria);

Expand All @@ -66,7 +66,7 @@ public function delete(MatrixrateInterface $matrixrate);

/**
* Create a Matrixrate rule.
* @return MatrixrateInterface
* @return \TIG\PostNL\Api\Data\MatrixrateInterface
* @api
*/
public function create();
Expand Down
3 changes: 2 additions & 1 deletion Api/ShipmentManagementInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ public function cancelConfirm($shipmentId);
* Generate a label for a PostNL shipment.
*
* @param int $shipmentId
* @param bool $smartReturns
*
* @api
* @return string
*/
public function generateLabel($shipmentId);
public function generateLabel($shipmentId, $smartReturns);

/**
* Create a PostNL shipment
Expand Down
2 changes: 1 addition & 1 deletion Block/Adminhtml/Config/Support/SupportTab.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

class SupportTab extends Template implements RendererInterface
{
const POSTNL_VERSION = '1.12.4';
const POSTNL_VERSION = '1.12.5';

const XPATH_SUPPORTED_MAGENTO_VERSION = 'tig_postnl/supported_magento_version';

Expand Down
202 changes: 202 additions & 0 deletions Block/Adminhtml/Grid/Order/SmartReturnEmail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
<?php
/**
*
* ..::..
* ..::::::::::::..
* ::'''''':''::'''''::
* ::.. ..: : ....::
* :::: ::: : : ::
* :::: ::: : ''' ::
* ::::..:::..::.....::
* ''::::::::::::''
* ''::''
*
*
* NOTICE OF LICENSE
*
* This source file is subject to the Creative Commons License.
* It is available through the world-wide-web at this URL:
* http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
* If you are unable to obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please contact [email protected] for more information.
*
* @copyright Copyright (c) Total Internet Group B.V. https://tig.nl/copyright
* @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
*/
namespace TIG\PostNL\Block\Adminhtml\Grid\Order;

use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\UiComponentFactory;
use TIG\PostNL\Api\OrderRepositoryInterface;
use TIG\PostNL\Api\ShipmentRepositoryInterface;
use TIG\PostNL\Block\Adminhtml\Grid\AbstractGrid;
use TIG\PostNL\Block\Adminhtml\Renderer\SmartReturnEmail as Renderer;

class SmartReturnEmail extends AbstractGrid
{
/**
* @var Renderer
*/
private $smartReturnEmail;

/**
* @var array
*/
private $shipments = [];

/**
* @var $orders
*/
private $orders;

/**
* @var ShipmentRepositoryInterface
*/
private $shipmentRepository;

/**
* @var OrderRepositoryInterface
*/
private $orderRepository;

/**
* @var SearchCriteriaBuilder
*/
private $searchCriteriaBuilder;

/**
* @param ContextInterface $context
* @param UiComponentFactory $uiComponentFactory
* @param Renderer $smartReturnEmail
* @param ShipmentRepositoryInterface $shipmentRepository
* @param OrderRepositoryInterface $orderRepository
* @param SearchCriteriaBuilder $searchCriteriaBuilder
* @param array $components
* @param array $data
*/
public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
Renderer $smartReturnEmail,
ShipmentRepositoryInterface $shipmentRepository,
OrderRepositoryInterface $orderRepository,
SearchCriteriaBuilder $searchCriteriaBuilder,
array $components = [],
array $data = []
) {
parent::__construct($context, $uiComponentFactory, $components, $data);
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
$this->shipmentRepository = $shipmentRepository;
$this->orderRepository = $orderRepository;
$this->smartReturnEmail = $smartReturnEmail;
}

/**
* Preload all the needed models in 1 query.
*/
// @codingStandardsIgnoreLine
protected function prepareData()
{
$orderIds = $this->collectIds();
if (!$orderIds) {
return null;
}

$searchCriteria = $this->createIdInSearchCriteria($orderIds);
$models = $this->loadShipments($searchCriteria);
foreach ($models as $model) {
$this->shipments[$model->getOrderId()][] = $model;
}

$models = $this->loadOrders($searchCriteria);
foreach ($models as $model) {
$this->orders[$model->getOrderId()] = $model;
}
}

/**
* @param object $item
*
* @return null|string
*/
//@codingStandardsIgnoreLine
protected function getCellContents($item)
{
$entityId = $item['entity_id'];
$output = '';

if (array_key_exists($entityId, $this->shipments)) {
/** @var \TIG\PostNL\Model\Shipment $model */
foreach ($this->shipments[$entityId] as $model) {
$output .= $this->smartReturnEmail->render($model) . '<br>';
}
return $output;
}

if (isset($this->orders[$entityId])) {
$postnlOrder = $this->orders[$entityId];
return $this->smartReturnEmail->render($postnlOrder->getShipmentId());
}

return $output;
}

/**
* @return array
*/
private function collectIds()
{
$orderIds = [];

foreach ($this->items as $item) {
$orderIds[] = $item['entity_id'];
}

return $orderIds;
}

/**
* @param \Magento\Framework\Api\SearchCriteria
*
* @return \TIG\PostNL\Model\Shipment[]
*/
private function loadShipments($searchCriteria)
{
/** @var \Magento\Framework\Api\SearchResults $list */
$list = $this->shipmentRepository->getList($searchCriteria);

return $list->getItems();
}

/**
* @param \Magento\Framework\Api\SearchCriteria
*
* @return \TIG\PostNL\Model\Order[]
*/
private function loadOrders($searchCriteria)
{
/** @var \Magento\Framework\Api\SearchResults $list */
$list = $this->orderRepository->getList($searchCriteria);

return $list->getItems();
}

/**
* @param $orderIds
*
* @return \Magento\Framework\Api\SearchCriteria
*/
private function createIdInSearchCriteria($orderIds = [])
{
$searchCriteria = $this->searchCriteriaBuilder->addFilter('order_id', $orderIds, 'IN');

return $searchCriteria->create();
}
}
2 changes: 1 addition & 1 deletion Block/Adminhtml/Grid/Shipment/DeepLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function __construct(
}

/**
* @param object $item
* @param array $item
*
* @return string
*/
Expand Down
83 changes: 83 additions & 0 deletions Block/Adminhtml/Grid/Shipment/SmartReturnEmail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/**
*
* ..::..
* ..::::::::::::..
* ::'''''':''::'''''::
* ::.. ..: : ....::
* :::: ::: : : ::
* :::: ::: : ''' ::
* ::::..:::..::.....::
* ''::::::::::::''
* ''::''
*
*
* NOTICE OF LICENSE
*
* This source file is subject to the Creative Commons License.
* It is available through the world-wide-web at this URL:
* http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
* If you are unable to obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please contact [email protected] for more information.
*
* @copyright Copyright (c) Total Internet Group B.V. https://tig.nl/copyright
* @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
*/
namespace TIG\PostNL\Block\Adminhtml\Grid\Shipment;

use Magento\Framework\Phrase;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\UiComponentFactory;
use TIG\PostNL\Block\Adminhtml\Grid\AbstractGrid;
use TIG\PostNL\Block\Adminhtml\Renderer\SmartReturnEmail as Renderer;

class SmartReturnEmail extends AbstractGrid
{
/**
* @var Renderer
*/
private $smartReturnEmail;

/**
* SmartReturnEmail constructor.
*
* @param ContextInterface $context
* @param UiComponentFactory $uiComponentFactory
* @param Renderer $smartReturnEmail
* @param array $components
* @param array $data
*/
public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
Renderer $smartReturnEmail,
array $components = [],
array $data = []
)
{
parent::__construct($context, $uiComponentFactory, $components, $data);

$this->smartReturnEmail = $smartReturnEmail;
}

/**
* @param array $item
*
* @return string
*/
// @codingStandardsIgnoreLine
protected function getCellContents($item)
{
if (!isset($item['entity_id'])) {
return '';
}

return $this->smartReturnEmail->render($item['entity_id']);
}
}
Loading

0 comments on commit 76958c1

Please sign in to comment.