Skip to content

Commit

Permalink
Release V1.0.24
Browse files Browse the repository at this point in the history
  • Loading branch information
roerlemans committed Aug 20, 2021
1 parent cb25a8b commit 318cd2b
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 63 deletions.
63 changes: 32 additions & 31 deletions Controller/Adminhtml/Bulk/Download.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,33 @@
use DHLParcel\Shipping\Model\Exception\ShipmentNoLabelsException;
use DHLParcel\Shipping\Model\Service\Label as LabelService;
use DHLParcel\Shipping\Model\Service\Notification as NotificationService;

use Magento\Framework\Exception\LocalizedException;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\Order\Shipment;

use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Api\ShipmentRepositoryInterface;
use setasign\Fpdi\FpdiException;

class Download extends \Magento\Backend\App\Action
{
protected $helper;
protected $labelService;
protected $orderRepository;
protected $shipmentRepository;
protected $notificationService;
protected $orderCollectionFactory;
protected $massActionFilter;
protected $shipmentCollectionFactory;

public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Ui\Component\MassAction\Filter $massActionFilter,
\Magento\Sales\Model\ResourceModel\Order\CollectionFactoryInterface $orderCollectionFactory,
\Magento\Sales\Model\ResourceModel\Order\Shipment\CollectionFactory $shipmentCollectionFactory,
Data $helper,
LabelService $labelService,
NotificationService $notificationService,
OrderRepositoryInterface $orderRepository,
ShipmentRepositoryInterface $shipmentRepository
NotificationService $notificationService
) {
$this->helper = $helper;
$this->notificationService = $notificationService;
$this->labelService = $labelService;
$this->orderRepository = $orderRepository;
$this->shipmentRepository = $shipmentRepository;
$this->massActionFilter = $massActionFilter;
$this->orderCollectionFactory = $orderCollectionFactory;
$this->shipmentCollectionFactory = $shipmentCollectionFactory;
parent::__construct($context);
}

Expand All @@ -50,15 +47,13 @@ public function execute()
if ($this->_request->getParam('create_and_download')) {
$redirectPath = 'sales/order/';
$orderIds = json_decode(base64_decode($this->_request->getParam('create_and_download')));
$labels = $this->processOrderIds($orderIds, $success, $errors);
$labels = $this->getSelectedOrderLabels($success, $errors, $orderIds);
} elseif ($this->_request->getParam('namespace') === 'sales_order_grid') {
$redirectPath = 'sales/order/';
$orderIds = $this->_request->getParam('selected');
$labels = $this->processOrderIds($orderIds, $success, $errors);
$labels = $this->getSelectedOrderLabels($success, $errors);
} elseif ($this->_request->getParam('namespace') === 'sales_order_shipment_grid') {
$redirectPath = 'sales/shipment/';
$shipmentIds = $this->_request->getParam('selected');
$labels = $this->processShipmentIds($shipmentIds, $success, $errors);
$labels = $this->getSelectedShipmentLabels($success, $errors);
} else {
$this->notificationService->error(__('DHL Parcel bulk action called from an invalid page'));
return $this->resultRedirectFactory->create()->setPath('sales/order/');
Expand Down Expand Up @@ -159,16 +154,22 @@ public function execute()
return $pdfResponse;
}

protected function processOrderIds($orderIds, &$successStorage = null, &$errorStorage = null)
protected function getSelectedOrderLabels(&$successStorage = null, &$errorStorage = null, $orderIds = [])
{
if (!is_array($orderIds)) {
return [];
$labels = [];

if (!$orderIds) {
$collection = $this->massActionFilter->getCollection($this->orderCollectionFactory->create());
$selected = $this->_request->getParam(\Magento\Ui\Component\MassAction\Filter::SELECTED_PARAM);
if (!empty($selected) && is_array($selected)) {
$collection->getSelect()->order(new Zend_Db_Expr('FIELD(entity_id,' . implode(',', $selected) . ')'));
}
} else {
$collection = $this->orderCollectionFactory->create()
->addFieldToFilter('entity_id', [ 'in' => $orderIds ]);
}

$labels = [];
foreach ($orderIds as $orderId) {
/** @var Order $order */
$order = $this->orderRepository->get($orderId);
foreach ($collection as $order) {
$exceptions = [];
foreach ($order->getShipmentsCollection() as $shipment) {
$retrievedLabels = $this->getLabels($shipment, $exceptions);
Expand All @@ -184,16 +185,16 @@ protected function processOrderIds($orderIds, &$successStorage = null, &$errorSt
return $labels;
}

protected function processShipmentIds($shipmentIds, &$successStorage = null, &$errorStorage = null)
protected function getSelectedShipmentLabels(&$successStorage = null, &$errorStorage = null)
{
if (!is_array($shipmentIds)) {
return [];
$collection = $this->massActionFilter->getCollection($this->shipmentCollectionFactory->create());
$selected = $this->_request->getParam(\Magento\Ui\Component\MassAction\Filter::SELECTED_PARAM);
if (!empty($selected) && is_array($selected)) {
$collection->getSelect()->order(new Zend_Db_Expr('FIELD(entity_id,' . implode(',', $selected) . ')'));
}

$labels = [];
foreach ($shipmentIds as $shipmentId) {
/** @var Shipment $shipment */
$shipment = $this->shipmentRepository->get($shipmentId);
foreach ($collection as $shipment) {
$exceptions = [];
$retrievedLabels = $this->getLabels($shipment, $exceptions);
$labels = array_merge($labels, $retrievedLabels);
Expand Down
61 changes: 31 additions & 30 deletions Controller/Adminhtml/Bulk/PrintAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,43 @@
namespace DHLParcel\Shipping\Controller\Adminhtml\Bulk;

use DHLParcel\Shipping\Helper\Data;
use DHLParcel\Shipping\Model\Config\Source\BulkNotification;
use DHLParcel\Shipping\Model\Exception\LabelNotFoundException;
use DHLParcel\Shipping\Model\Exception\NoPrinterException;
use DHLParcel\Shipping\Model\Exception\NoTrackException;
use DHLParcel\Shipping\Model\Exception\ShipmentNoLabelsException;
use DHLParcel\Shipping\Model\Service\Label as LabelService;
use DHLParcel\Shipping\Model\Service\Notification as NotificationService;
use Magento\Framework\Exception\LocalizedException;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\Order\Shipment;
use DHLParcel\Shipping\Model\Config\Source\BulkNotification;
use DHLParcel\Shipping\Model\Service\Printing as PrintingService;

use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Api\ShipmentRepositoryInterface;
use Magento\Framework\Exception\LocalizedException;

class PrintAction extends \Magento\Backend\App\Action
{
protected $helper;
protected $labelService;
protected $orderRepository;
protected $shipmentRepository;
protected $notificationService;
protected $printingService;
protected $orderCollectionFactory;
protected $massActionFilter;
protected $shipmentCollectionFactory;

public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Ui\Component\MassAction\Filter $massActionFilter,
\Magento\Sales\Model\ResourceModel\Order\CollectionFactoryInterface $orderCollectionFactory,
\Magento\Sales\Model\ResourceModel\Order\Shipment\CollectionFactory $shipmentCollectionFactory,
Data $helper,
LabelService $labelService,
NotificationService $notificationService,
OrderRepositoryInterface $orderRepository,
ShipmentRepositoryInterface $shipmentRepository,
PrintingService $printingService
) {
$this->helper = $helper;
$this->notificationService = $notificationService;
$this->labelService = $labelService;
$this->orderRepository = $orderRepository;
$this->shipmentRepository = $shipmentRepository;
$this->printingService = $printingService;
$this->massActionFilter = $massActionFilter;
$this->orderCollectionFactory = $orderCollectionFactory;
$this->shipmentCollectionFactory = $shipmentCollectionFactory;
parent::__construct($context);
}

Expand All @@ -53,15 +51,13 @@ public function execute()
if ($this->_request->getParam('create_and_print')) {
$redirectPath = 'sales/order/';
$orderIds = json_decode(base64_decode($this->_request->getParam('create_and_print')));
$labelCount = $this->processOrderIds($orderIds, $success, $errors);
$labelCount = $this->processOrders($success, $errors, $orderIds);
} elseif ($this->_request->getParam('namespace') === 'sales_order_grid') {
$redirectPath = 'sales/order/';
$orderIds = $this->_request->getParam('selected');
$labelCount = $this->processOrderIds($orderIds, $success, $errors);
$labelCount = $this->processOrders($success, $errors);
} elseif ($this->_request->getParam('namespace') === 'sales_order_shipment_grid') {
$redirectPath = 'sales/shipment/';
$shipmentIds = $this->_request->getParam('selected');
$labelCount = $this->processShipmentIds($shipmentIds, $success, $errors);
$labelCount = $this->processShipments($success, $errors);
} else {
$this->notificationService->error(__('DHL Parcel bulk action called from an invalid page'));
return $this->resultRedirectFactory->create()->setPath('sales/order/');
Expand Down Expand Up @@ -160,16 +156,21 @@ public function execute()
return $this->resultRedirectFactory->create()->setPath($redirectPath);
}

protected function processOrderIds($orderIds, &$successStorage = null, &$errorStorage = null)
protected function processOrders(&$successStorage = null, &$errorStorage = null, $orderIds = [])
{
if (!is_array($orderIds)) {
return 0;
if (!$orderIds) {
$collection = $this->massActionFilter->getCollection($this->orderCollectionFactory->create());
$selected = $this->_request->getParam(\Magento\Ui\Component\MassAction\Filter::SELECTED_PARAM);
if (!empty($selected) && is_array($selected)) {
$collection->getSelect()->order(new Zend_Db_Expr('FIELD(entity_id,' . implode(',', $selected) . ')'));
}
} else {
$collection = $this->orderCollectionFactory->create()
->addFieldToFilter('entity_id', [ 'in' => $orderIds ]);
}

$labelCount = 0;
foreach ($orderIds as $orderId) {
/** @var Order $order */
$order = $this->orderRepository->get($orderId);
foreach ($collection as $order) {
$exceptions = [];
foreach ($order->getShipmentsCollection() as $shipment) {
$labelCount += $this->printLabels($shipment, $exceptions);
Expand All @@ -184,16 +185,16 @@ protected function processOrderIds($orderIds, &$successStorage = null, &$errorSt
return $labelCount;
}

protected function processShipmentIds($shipmentIds, &$successStorage = null, &$errorStorage = null)
protected function processShipments(&$successStorage = null, &$errorStorage = null)
{
if (!is_array($shipmentIds)) {
return 0;
$collection = $this->massActionFilter->getCollection($this->shipmentCollectionFactory->create());
$selected = $this->_request->getParam(\Magento\Ui\Component\MassAction\Filter::SELECTED_PARAM);
if (!empty($selected) && is_array($selected)) {
$collection->getSelect()->order(new Zend_Db_Expr('FIELD(entity_id,' . implode(',', $selected) . ')'));
}

$labelCount = 0;
foreach ($shipmentIds as $shipmentId) {
/** @var Shipment $shipment */
$shipment = $this->shipmentRepository->get($shipmentId);
foreach ($collection as $shipment) {
$exceptions = [];
$labelCount += $this->printLabels($shipment, $exceptions);
if (is_array($successStorage) && count($exceptions) === 0) {
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "dhlparcel/magento2-plugin",
"description": "DHL Parcel plugin for Magento 2",
"type": "magento2-module",
"version": "1.0.23",
"version": "1.0.24",
"license": [
"OSL-3.0"
],
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="DHLParcel_Shipping" setup_version="1.0.23">
<module name="DHLParcel_Shipping" setup_version="1.0.24">
<sequence>
<module name="Magento_Shipping"/>
<module name="Magento_Checkout"/>
Expand Down
8 changes: 8 additions & 0 deletions view/frontend/web/css/servicepoint.modal.css
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,11 @@
#dhlparcel_shipping_locator_real_reset {
all: initial;
}

.dhlparcel-shipping-modal .modal-inner-wrap {
display: none;
}

.dhlparcel-shipping-modal._show .modal-inner-wrap {
display: block;
}

0 comments on commit 318cd2b

Please sign in to comment.