Skip to content

Commit a6fa439

Browse files
authored
Merge pull request #100 from dpdconnect/1.3.5
1.3.5
2 parents 5f60d44 + a8906f2 commit a6fa439

File tree

7 files changed

+51
-41
lines changed

7 files changed

+51
-41
lines changed

Block/Adminhtml/Order/Packaging.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function getLabelTypeOptions()
103103
$order = $this->getOrder();
104104

105105
$availableProducts = [];
106-
$shippingProducts = $this->client->authenticate()->getProduct()->getList();
106+
$shippingProducts = $this->client->authenticate($order->getStoreId())->getProduct()->getList();
107107
foreach ($shippingProducts as $shippingProduct) {
108108
if ('parcelshop' === $shippingProduct['type'] && !$this->isParcelshopOrder($order)) {
109109
continue;

Controller/Adminhtml/Order/Shipment/Save.php

+1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ public function execute()
150150
$packages = $this->getRequest()->getParam('packages');
151151
$packageId = 1;
152152
$rows = [];
153+
153154
foreach($packages as $package) {
154155
$newPackage[$packageId] = $package;
155156

Helper/DPDClient.php

+8-6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use Magento\Framework\Encryption\Encryptor;
2929
use Magento\Framework\App\ProductMetadataInterface;
3030
use Magento\Framework\Module\ModuleListInterface;
31+
use Magento\Store\Model\ScopeInterface;
3132

3233
class DPDClient extends AbstractHelper
3334
{
@@ -80,10 +81,11 @@ public function __construct(
8081
}
8182

8283
/**
83-
* @return \DpdConnect\Sdk\Client
84+
* @param int|null $storeId
85+
* @return Client
8486
* @throws \Exception
8587
*/
86-
public function authenticate()
88+
public function authenticate(?int $storeId = null)
8789
{
8890
$url = $this->dpdSettings->getValue(DpdSettings::API_ENDPOINT);
8991
$pluginVersion = $this->moduleList
@@ -96,17 +98,17 @@ public function authenticate()
9698
]));
9799

98100
$client = $clientBuiler->buildAuthenticatedByPassword(
99-
$this->dpdSettings->getValue(DpdSettings::ACCOUNT_USERNAME),
100-
$this->crypt->decrypt($this->dpdSettings->getValue(DpdSettings::ACCOUNT_PASSWORD))
101+
$this->dpdSettings->getValue(DpdSettings::ACCOUNT_USERNAME,ScopeInterface::SCOPE_STORE, $storeId),
102+
$this->crypt->decrypt($this->dpdSettings->getValue(DpdSettings::ACCOUNT_PASSWORD,ScopeInterface::SCOPE_STORE, $storeId))
101103
);
102104

103105
$client->getAuthentication()->setJwtToken(
104-
$this->dpdCache->getCache('dpdconnect_jwt_token') ?: null
106+
$this->dpdCache->getCache('dpdconnect_jwt_token_' . ($storeId ?? 0)) ?: null
105107
);
106108

107109
// This is where we save the (new) JWT token to the cache
108110
$client->getAuthentication()->setTokenUpdateCallback(function (string $jwtToken) use ($client) {
109-
$this->dpdCache->setCache('dpdconnect_jwt_token', $jwtToken, 7200);
111+
$this->dpdCache->setCache('dpdconnect_jwt_token_' . ($storeId ?? 0), $jwtToken, 7200);
110112
$client->getAuthentication()->setJwtToken($jwtToken);
111113
});
112114

Helper/Data.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use DpdConnect\Shipping\Helper\Services\ShipmentLabelService;
2323
use DpdConnect\Shipping\Services\BatchManager;
2424
use DpdConnect\Shipping\Services\ShipmentManager;
25+
use Magento\Framework\App\Config\ScopeConfigInterface;
2526
use Magento\Framework\App\Helper\AbstractHelper;
2627
use Magento\Framework\App\Helper\Context;
2728
use Magento\Framework\Exception\AlreadyExistsException;
@@ -110,10 +111,10 @@ public function getGoogleServerApiKey()
110111
*/
111112
public function generateShippingLabel(Order $order, Order\Shipment $shipment = null, $parcels = 1, $isReturn = false)
112113
{
113-
$includeReturnLabel = $this->dpdSettings->isSetFlag(DpdSettings::ADVANCED_INCLUDE_RETURN_LABEL);
114+
$includeReturnLabel = $this->dpdSettings->isSetFlag(DpdSettings::ADVANCED_INCLUDE_RETURN_LABEL, ScopeInterface::SCOPE_STORE, $order->getStoreId());
114115

115116
// New way of processing batch requests
116-
if($order->hasData(Constants::ORDER_EXTRA_SHIPPING_DATA)) {
117+
if($order->hasData(Constants::ORDER_EXTRA_SHIPPING_DATA) && !is_array($parcels)) {
117118
$pdfResult = [];
118119
$shipmentRows = $order->getData(Constants::ORDER_EXTRA_SHIPPING_DATA);
119120
foreach ($shipmentRows as $shipmentRow) {
@@ -192,7 +193,7 @@ public function generateShippingLabel(Order $order, Order\Shipment $shipment = n
192193
}
193194
}
194195

195-
$sendConfirmEmail = $this->dpdSettings->isSetFlag(DpdSettings::ADVANCED_SEND_CONFIRM_EMAIL);
196+
$sendConfirmEmail = $this->dpdSettings->isSetFlag(DpdSettings::ADVANCED_SEND_CONFIRM_EMAIL, 'store', $order->getStoreId());
196197
if ($sendConfirmEmail) {
197198
$this->shipmentNotifier->notify($shipment);
198199
}

Helper/Services/OrderConvertService.php

+26-25
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Magento\Framework\App\Helper\Context;
2828
use Magento\Sales\Api\Data\OrderAddressInterface;
2929
use Magento\Sales\Model\Order;
30+
use Magento\Store\Model\ScopeInterface;
3031

3132
class OrderConvertService extends AbstractHelper
3233
{
@@ -89,7 +90,7 @@ private function getProductCode(Order $order, ?Order\Shipment $shipment = null,
8990
}
9091

9192
// Fetch the code from the shipment, if any, else default to the order code
92-
if ($shipment && $shipment->hasData(Constants::SHIPMENT_EXTRA_DATA)) {
93+
if ($shipment && !empty($shipment->hasData(Constants::SHIPMENT_EXTRA_DATA)['code'])) {
9394
return $shipment->getData(Constants::SHIPMENT_EXTRA_DATA)['code'];
9495
}
9596

@@ -164,7 +165,7 @@ public function addParcels(Order $order, ?Order\Shipment $shipment = null, bool
164165
$parcel = [
165166
'customerReferences' => [
166167
$order->getIncrementId() ?? '',
167-
($this->dpdSettings->isSetFlag(DpdSettings::ADVANCED_PRINT_ORDER_ID) ? $order->getEntityId() : ''),
168+
($this->dpdSettings->isSetFlag(DpdSettings::ADVANCED_PRINT_ORDER_ID, ScopeInterface::SCOPE_STORE, $order->getStoreId()) ? $order->getEntityId() : ''),
168169
$order->getDpdParcelshopId() ?? '',
169170
$shipment->getEntityId() ?? '',
170171
],
@@ -208,7 +209,7 @@ public function addParcelsFromPackages(Order $order, ?Order\Shipment $shipment =
208209
$parcel = [
209210
'customerReferences' => [
210211
$order->getIncrementId() ?? '',
211-
($this->dpdSettings->isSetFlag(DpdSettings::ADVANCED_PRINT_ORDER_ID) ? $order->getIncrementId() : ''),
212+
($this->dpdSettings->isSetFlag(DpdSettings::ADVANCED_PRINT_ORDER_ID, ScopeInterface::SCOPE_STORE, $order->getStoreId()) ? $order->getIncrementId() : ''),
212213
$order->getDpdParcelshopId() ?? '',
213214
$shipment->getEntityId(),
214215
],
@@ -242,20 +243,20 @@ public function convert(Order $order, ?Order\Shipment $orderShipment = null, boo
242243

243244
$shipment = [
244245
'orderId' => $order->getIncrementId(),
245-
'sendingDepot' => $this->dpdSettings->getValue(DpdSettings::ACCOUNT_DEPOT),
246+
'sendingDepot' => $this->dpdSettings->getValue(DpdSettings::ACCOUNT_DEPOT, ScopeInterface::SCOPE_STORE, $order->getStoreId()),
246247
'sender' => [
247-
'name1' => $this->dpdSettings->getValue(DpdSettings::SHIPPING_ORIGIN_NAME1),
248-
'street' => $this->dpdSettings->getValue(DpdSettings::SHIPPING_ORIGIN_STREET),
249-
'housenumber' => $this->dpdSettings->getValue(DpdSettings::SHIPPING_ORIGIN_HOUSE_NUMBER),
250-
'country' => $this->dpdSettings->getValue(DpdSettings::SHIPPING_ORIGIN_COUNTRY),
251-
'postalcode' => $this->dpdSettings->getValue(DpdSettings::SHIPPING_ORIGIN_ZIP_CODE),
252-
'city' => $this->dpdSettings->getValue(DpdSettings::SHIPPING_ORIGIN_CITY),
253-
'phoneNumber' => $this->dpdSettings->getValue(DpdSettings::STORE_INFORMATION_PHONE),
254-
'email' => $this->dpdSettings->getValue(DpdSettings::STORE_INFORMATION_EMAIL),
248+
'name1' => $this->dpdSettings->getValue(DpdSettings::SHIPPING_ORIGIN_NAME1, ScopeInterface::SCOPE_STORE, $order->getStoreId()),
249+
'street' => $this->dpdSettings->getValue(DpdSettings::SHIPPING_ORIGIN_STREET, ScopeInterface::SCOPE_STORE, $order->getStoreId()),
250+
'housenumber' => $this->dpdSettings->getValue(DpdSettings::SHIPPING_ORIGIN_HOUSE_NUMBER, ScopeInterface::SCOPE_STORE, $order->getStoreId()),
251+
'country' => $this->dpdSettings->getValue(DpdSettings::SHIPPING_ORIGIN_COUNTRY, ScopeInterface::SCOPE_STORE, $order->getStoreId()),
252+
'postalcode' => $this->dpdSettings->getValue(DpdSettings::SHIPPING_ORIGIN_ZIP_CODE, ScopeInterface::SCOPE_STORE, $order->getStoreId()),
253+
'city' => $this->dpdSettings->getValue(DpdSettings::SHIPPING_ORIGIN_CITY, ScopeInterface::SCOPE_STORE, $order->getStoreId()),
254+
'phoneNumber' => $this->dpdSettings->getValue(DpdSettings::STORE_INFORMATION_PHONE, ScopeInterface::SCOPE_STORE, $order->getStoreId()),
255+
'email' => $this->dpdSettings->getValue(DpdSettings::STORE_INFORMATION_EMAIL, ScopeInterface::SCOPE_STORE, $order->getStoreId()),
255256
'commercialAddress' => true,
256-
'vatnumber' => $this->dpdSettings->getValue(DpdSettings::STORE_INFORMATION_VAT_NUMBER),
257-
'eorinumber' => $this->dpdSettings->getValue(DpdSettings::STORE_INFORMATION_EORI),
258-
'sprn' => $this->dpdSettings->getValue(DpdSettings::STORE_INFORMATION_SPRN),
257+
'vatnumber' => $this->dpdSettings->getValue(DpdSettings::STORE_INFORMATION_VAT_NUMBER, ScopeInterface::SCOPE_STORE, $order->getStoreId()),
258+
'eorinumber' => $this->dpdSettings->getValue(DpdSettings::STORE_INFORMATION_EORI, ScopeInterface::SCOPE_STORE, $order->getStoreId()),
259+
'sprn' => $this->dpdSettings->getValue(DpdSettings::STORE_INFORMATION_SPRN, ScopeInterface::SCOPE_STORE, $order->getStoreId()),
259260
],
260261
'receiver' => $this->getReceiverData($order),
261262
'product' => [
@@ -272,16 +273,16 @@ public function convert(Order $order, ?Order\Shipment $orderShipment = null, boo
272273
'totalAmount' => (float) $order->getBaseGrandTotal(),
273274
'customsLines' => $this->addCustomsLines($order),
274275
'consignor' => [
275-
'name1' => $this->dpdSettings->getValue(DpdSettings::STORE_INFORMATION_NAME),
276-
'street' => $this->dpdSettings->getValue(DpdSettings::STORE_INFORMATION_STREET),
277-
'housenumber' => $this->dpdSettings->getValue(DpdSettings::STORE_INFORMATION_HOUSE_NUMBER),
278-
'postalcode' => $this->dpdSettings->getValue(DpdSettings::STORE_INFORMATION_ZIP_CODE),
279-
'city' => $this->dpdSettings->getValue(DpdSettings::STORE_INFORMATION_CITY),
280-
'country' => $this->dpdSettings->getValue(DpdSettings::STORE_INFORMATION_COUNTRY),
276+
'name1' => $this->dpdSettings->getValue(DpdSettings::STORE_INFORMATION_NAME, ScopeInterface::SCOPE_STORE, $order->getStoreId()),
277+
'street' => $this->dpdSettings->getValue(DpdSettings::STORE_INFORMATION_STREET, ScopeInterface::SCOPE_STORE, $order->getStoreId()),
278+
'housenumber' => $this->dpdSettings->getValue(DpdSettings::STORE_INFORMATION_HOUSE_NUMBER, ScopeInterface::SCOPE_STORE, $order->getStoreId()),
279+
'postalcode' => $this->dpdSettings->getValue(DpdSettings::STORE_INFORMATION_ZIP_CODE, ScopeInterface::SCOPE_STORE, $order->getStoreId()),
280+
'city' => $this->dpdSettings->getValue(DpdSettings::STORE_INFORMATION_CITY, ScopeInterface::SCOPE_STORE, $order->getStoreId()),
281+
'country' => $this->dpdSettings->getValue(DpdSettings::STORE_INFORMATION_COUNTRY, ScopeInterface::SCOPE_STORE, $order->getStoreId()),
281282
'commercialAddress' => true,
282-
'vatnumber' => $this->dpdSettings->getValue(DpdSettings::STORE_INFORMATION_VAT_NUMBER),
283-
'eorinumber' => $this->dpdSettings->getValue(DpdSettings::STORE_INFORMATION_EORI),
284-
'sprn' => $this->dpdSettings->getValue(DpdSettings::STORE_INFORMATION_SPRN),
283+
'vatnumber' => $this->dpdSettings->getValue(DpdSettings::STORE_INFORMATION_VAT_NUMBER, ScopeInterface::SCOPE_STORE, $order->getStoreId()),
284+
'eorinumber' => $this->dpdSettings->getValue(DpdSettings::STORE_INFORMATION_EORI, ScopeInterface::SCOPE_STORE, $order->getStoreId()),
285+
'sprn' => $this->dpdSettings->getValue(DpdSettings::STORE_INFORMATION_SPRN, ScopeInterface::SCOPE_STORE, $order->getStoreId()),
285286
],
286287
'consignee' => $this->getReceiverData($order)
287288
];
@@ -331,7 +332,7 @@ private function addCustomsLines(Order $order)
331332
foreach ($order->getItems() as $item) {
332333
/** @var \Magento\Catalog\Model\Product $product */
333334
$product = $item->getProduct();
334-
$originCountry = $this->dpdSettings->getValue(DpdSettings::SHIPPING_ORIGIN_COUNTRY);
335+
$originCountry = $this->dpdSettings->getValue(DpdSettings::SHIPPING_ORIGIN_COUNTRY, ScopeInterface::SCOPE_STORE, $order->getStoreId());
335336
$hsCode = '';
336337

337338
if ($product !== null) {

Helper/Services/ShipmentLabelService.php

+8-6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use Magento\Framework\Filesystem\Io\File;
3232
use Magento\Framework\Url;
3333
use Magento\Sales\Model\Order;
34+
use Magento\Store\Model\ScopeInterface;
3435

3536
class ShipmentLabelService extends AbstractHelper
3637
{
@@ -172,7 +173,7 @@ public function generateLabelMultiPackage(Order $order, $isReturn = false, Order
172173
$shipmentData[] = $this->orderConvertService->convert($order, $shipment, $includeReturn, $parcels);
173174
}
174175

175-
$result = $this->createShipment($shipmentData);
176+
$result = $this->createShipment($shipmentData, $order);
176177
$labels = $result->getContent()['labelResponses'];
177178

178179
foreach ($labels as $label) {
@@ -224,7 +225,7 @@ public function generateLabel(Order $order, $isReturn = false, Order\Shipment $s
224225

225226
$weight = $this->orderConvertService->getOrderWeight($order);
226227

227-
$result = $this->createShipment($shipmentData);
228+
$result = $this->createShipment($shipmentData, $order);
228229
$labels = $result->getContent()['labelResponses'];
229230

230231

@@ -308,17 +309,18 @@ private function createShipmentAsync(array $shipmentData)
308309

309310
/**
310311
* @param array $shipmentData
311-
* @return mixed
312+
* @param Order $order
313+
* @return \DpdConnect\Sdk\Common\ResourceClient|int
312314
* @throws RequestException
313315
*/
314-
private function createShipment(array $shipmentData)
316+
private function createShipment(array $shipmentData, Order $order)
315317
{
316-
$dpdClient = $this->dpdClient->authenticate();
318+
$dpdClient = $this->dpdClient->authenticate($order->getStoreId());
317319

318320
$request = [
319321
'printOptions' => [
320322
'printerLanguage' => 'PDF',
321-
'paperFormat' => $this->dpdSettings->getValue(DpdSettings::ACCOUNT_PRINT_FORMAT),
323+
'paperFormat' => $this->dpdSettings->getValue(DpdSettings::ACCOUNT_PRINT_FORMAT, ScopeInterface::SCOPE_STORE, $order->getStoreId()),
322324
'verticalOffset' => 0,
323325
'horizontalOffset' => 0,
324326
],

view/frontend/web/js/view/checkout/shipping/parcelshop.js

+3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ define([
8282

8383

8484
showMap: function () {
85+
$('#dpd-connect-selected-container').html('');
86+
$('#dpd-connect-selected-container').hide();
87+
8588
const shippingAddress = quote.shippingAddress();
8689

8790
if (!shippingAddress.postcode || !shippingAddress.countryId) {

0 commit comments

Comments
 (0)