Skip to content

Commit

Permalink
Merge pull request #29 from DPDBeNeLux/feature/16402
Browse files Browse the repository at this point in the history
Updated copyright year and implemented saving labels as file
  • Loading branch information
dpdplugin authored Feb 26, 2019
2 parents 228fc81 + 2ca232e commit c7eae4e
Show file tree
Hide file tree
Showing 83 changed files with 157 additions and 85 deletions.
2 changes: 1 addition & 1 deletion Block/Adminhtml/Order/PrintShippingList.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Magento 2 Shipping module of DPD Nederland B.V.
*
* Copyright (C) 2018 DPD Nederland B.V.
* Copyright (C) 2019 DPD Nederland B.V.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion Block/Adminhtml/Shipment/MenuItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Magento 2 Shipping module of DPD Nederland B.V.
*
* Copyright (C) 2018 DPD Nederland B.V.
* Copyright (C) 2019 DPD Nederland B.V.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion Block/Adminhtml/Shipment/PrintLabelModal.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Magento 2 Shipping module of DPD Nederland B.V.
*
* Copyright (C) 2018 DPD Nederland B.V.
* Copyright (C) 2019 DPD Nederland B.V.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion Block/Adminhtml/Tablerate/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Magento 2 Shipping module of DPD Nederland B.V.
*
* Copyright (C) 2018 DPD Nederland B.V.
* Copyright (C) 2019 DPD Nederland B.V.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion Block/Adminhtml/TablerateExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Magento 2 Shipping module of DPD Nederland B.V.
*
* Copyright (C) 2018 DPD Nederland B.V.
* Copyright (C) 2019 DPD Nederland B.V.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion Block/Adminhtml/TablerateImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Magento 2 Shipping module of DPD Nederland B.V.
*
* Copyright (C) 2018 DPD Nederland B.V.
* Copyright (C) 2019 DPD Nederland B.V.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion Block/GoogleMaps.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Magento 2 Shipping module of DPD Nederland B.V.
*
* Copyright (C) 2018 DPD Nederland B.V.
* Copyright (C) 2019 DPD Nederland B.V.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion Block/ParcelshopInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Magento 2 Shipping module of DPD Nederland B.V.
*
* Copyright (C) 2018 DPD Nederland B.V.
* Copyright (C) 2019 DPD Nederland B.V.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion Config/Source/Settings/AccountType.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Magento 2 Shipping module of DPD Nederland B.V.
*
* Copyright (C) 2018 DPD Nederland B.V.
* Copyright (C) 2019 DPD Nederland B.V.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion Config/Source/Settings/DaysInWeek.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Magento 2 Shipping module of DPD Nederland B.V.
*
* Copyright (C) 2018 DPD Nederland B.V.
* Copyright (C) 2019 DPD Nederland B.V.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion Config/Source/Settings/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Magento 2 Shipping module of DPD Nederland B.V.
*
* Copyright (C) 2018 DPD Nederland B.V.
* Copyright (C) 2019 DPD Nederland B.V.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion Config/Source/Settings/PrintFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Magento 2 Shipping module of DPD Nederland B.V.
*
* Copyright (C) 2018 DPD Nederland B.V.
* Copyright (C) 2019 DPD Nederland B.V.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion Config/Source/Settings/RateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Magento 2 Shipping module of DPD Nederland B.V.
*
* Copyright (C) 2018 DPD Nederland B.V.
* Copyright (C) 2019 DPD Nederland B.V.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion Controller/Adminhtml/Order/CreateShipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Magento 2 Shipping module of DPD Nederland B.V.
*
* Copyright (C) 2018 DPD Nederland B.V.
* Copyright (C) 2019 DPD Nederland B.V.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion Controller/Adminhtml/Order/PrintReturnLabel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Magento 2 Shipping module of DPD Nederland B.V.
*
* Copyright (C) 2018 DPD Nederland B.V.
* Copyright (C) 2019 DPD Nederland B.V.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion Controller/Adminhtml/Order/printShippingList.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Magento 2 Shipping module of DPD Nederland B.V.
*
* Copyright (C) 2018 DPD Nederland B.V.
* Copyright (C) 2019 DPD Nederland B.V.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion Controller/Adminhtml/Shipping/CreateShipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Magento 2 Shipping module of DPD Nederland B.V.
*
* Copyright (C) 2018 DPD Nederland B.V.
* Copyright (C) 2019 DPD Nederland B.V.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion Controller/Adminhtml/Shipping/PrintLabels.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Magento 2 Shipping module of DPD Nederland B.V.
*
* Copyright (C) 2018 DPD Nederland B.V.
* Copyright (C) 2019 DPD Nederland B.V.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion Controller/Adminhtml/Tablerate/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Magento 2 Shipping module of DPD Nederland B.V.
*
* Copyright (C) 2018 DPD Nederland B.V.
* Copyright (C) 2019 DPD Nederland B.V.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion Controller/Parcelshops/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Magento 2 Shipping module of DPD Nederland B.V.
*
* Copyright (C) 2018 DPD Nederland B.V.
* Copyright (C) 2019 DPD Nederland B.V.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion Controller/Parcelshops/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Magento 2 Shipping module of DPD Nederland B.V.
*
* Copyright (C) 2018 DPD Nederland B.V.
* Copyright (C) 2019 DPD Nederland B.V.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
4 changes: 2 additions & 2 deletions Helper/DPDClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Magento 2 Shipping module of DPD Nederland B.V.
*
* Copyright (C) 2018 DPD Nederland B.V.
* Copyright (C) 2019 DPD Nederland B.V.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -109,7 +109,7 @@ public function storeOrders($shipmentData, $delisId, $accessToken)
} elseif (isset($fs->detail->authenticationFault)) {
throw new \Exception('[DPD-Shipment] ' . $fs->detail->authenticationFault->errorMessage);
} else {
$this->_logger->info('[DPD-Shipment] OrderNumber: ' . $shipmentData['order']['parcels']['customerReferenceNumber1'] . " - Exception: " . $fs->getMessage());
$this->_logger->info('[DPD-Shipment] Exception: ' . $fs->getMessage());
throw new \Exception(__('[DPD-Shipment] Unknown error occurred'));
}
}
Expand Down
2 changes: 1 addition & 1 deletion Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Magento 2 Shipping module of DPD Nederland B.V.
*
* Copyright (C) 2018 DPD Nederland B.V.
* Copyright (C) 2019 DPD Nederland B.V.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion Helper/Services/AuthenticationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Magento 2 Shipping module of DPD Nederland B.V.
*
* Copyright (C) 2018 DPD Nederland B.V.
* Copyright (C) 2019 DPD Nederland B.V.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion Helper/Services/DPDPickupService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Magento 2 Shipping module of DPD Nederland B.V.
*
* Copyright (C) 2018 DPD Nederland B.V.
* Copyright (C) 2019 DPD Nederland B.V.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
46 changes: 44 additions & 2 deletions Helper/Services/DPDPredictService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Magento 2 Shipping module of DPD Nederland B.V.
*
* Copyright (C) 2018 DPD Nederland B.V.
* Copyright (C) 2019 DPD Nederland B.V.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -19,6 +19,7 @@
*/
namespace DPDBenelux\Shipping\Helper\Services;

use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\App\Helper\AbstractHelper;
use DPDBenelux\Shipping\Helper\DPDClient;
use Magento\Sales\Model\Order;
Expand All @@ -39,17 +40,33 @@ class DPDPredictService extends AbstractHelper
*/
private $shipmentLabelsFactory;

/**
* @var DPDClient
*/
private $dpdClient;

/**
* @var \Magento\Framework\Filesystem\Io\File
*/
private $filesystem;
/**
* @var \Magento\Framework\Filesystem\DirectoryList
*/
private $directoryList;

public function __construct(
\Magento\Framework\App\Helper\Context $context,
\DPDBenelux\Shipping\Helper\Services\AuthenticationService $authenticationService,
\Magento\Framework\Filesystem\Io\File $filesystem,
DPDClient $DPDClient,
\Magento\Framework\Filesystem\DirectoryList $directoryList,
ShipmentLabelsFactory $shipmentLabelsFactory
) {
$this->authenticationService = $authenticationService;
$this->shipmentLabelsFactory = $shipmentLabelsFactory;
$this->dpdClient = $DPDClient;
$this->filesystem = $filesystem;
$this->directoryList = $directoryList;
parent::__construct($context);
}

Expand Down Expand Up @@ -293,17 +310,42 @@ public function generateLabel(Order $order, $isReturn = false, Order\Shipment $s
}
$labelDataSerialized = serialize($labelData);

$saveLabelAsFile = $this->scopeConfig->isSetFlag('dpdshipping/account_settings/save_label_file');
$labelPath = $this->scopeConfig->getValue('dpdshipping/account_settings/label_path');

if (empty($labelPath)) {
$labelPath = $this->directoryList->getRoot() . '/var/dpd_labels/';
}

$labelPath = rtrim($labelPath, '/') . '/';

$labelName = sprintf('%s-%s.pdf', $order->getIncrementId(), $result->orderResult->shipmentResponses->mpsId);

// Save the label to the database
$shipmentLabels = $this->shipmentLabelsFactory->create();
$shipmentLabels->setLabelNumbers($labelDataSerialized);
$shipmentLabels->setMpsId($result->orderResult->shipmentResponses->mpsId);
$shipmentLabels->setShipmentId($shipment->getId());
$shipmentLabels->setShipmentIncrementId($shipment->getIncrementId());
$shipmentLabels->setOrderId($order->getId());
$shipmentLabels->setLabel($result->orderResult->parcellabelsPDF);

if (!$saveLabelAsFile) {
$shipmentLabels->setLabel($result->orderResult->parcellabelsPDF);
} else {
$shipmentLabels->setLabelPath($labelPath . $labelName);
}

$shipmentLabels->setIsReturn($isReturn ? "1" : "0");
$shipmentLabels->save();

// Write file to a directory
if ($saveLabelAsFile) {
if (!file_exists($labelPath)) {
mkdir($labelPath, 0755, true);
}
$this->filesystem->write($labelPath . $labelName, $result->orderResult->parcellabelsPDF);
}

return [
'senderData' => $senderData,
'parcellabelsPDF' => $result->orderResult->parcellabelsPDF,
Expand Down
2 changes: 1 addition & 1 deletion Helper/TrackingPopup.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Magento 2 Shipping module of DPD Nederland B.V.
*
* Copyright (C) 2018 DPD Nederland B.V.
* Copyright (C) 2019 DPD Nederland B.V.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion Model/Carrier/DpdClassic.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Magento 2 Shipping module of DPD Nederland B.V.
*
* Copyright (C) 2018 DPD Nederland B.V.
* Copyright (C) 2019 DPD Nederland B.V.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion Model/Carrier/DpdClassicSaturday.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Magento 2 Shipping module of DPD Nederland B.V.
*
* Copyright (C) 2018 DPD Nederland B.V.
* Copyright (C) 2019 DPD Nederland B.V.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion Model/Carrier/DpdExpress10.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Magento 2 Shipping module of DPD Nederland B.V.
*
* Copyright (C) 2018 DPD Nederland B.V.
* Copyright (C) 2019 DPD Nederland B.V.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion Model/Carrier/DpdExpress12.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Magento 2 Shipping module of DPD Nederland B.V.
*
* Copyright (C) 2018 DPD Nederland B.V.
* Copyright (C) 2019 DPD Nederland B.V.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion Model/Carrier/DpdGuarantee18.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Magento 2 Shipping module of DPD Nederland B.V.
*
* Copyright (C) 2018 DPD Nederland B.V.
* Copyright (C) 2019 DPD Nederland B.V.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion Model/Carrier/DpdSaturday.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Magento 2 Shipping module of DPD Nederland B.V.
*
* Copyright (C) 2018 DPD Nederland B.V.
* Copyright (C) 2019 DPD Nederland B.V.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
Loading

0 comments on commit c7eae4e

Please sign in to comment.