Skip to content

Commit cea5fb4

Browse files
committed
v1.0.47
1 parent 70ce72c commit cea5fb4

28 files changed

Lines changed: 435 additions & 504 deletions

File tree

Block/Adminhtml/Order/Shipment/Create.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ public function getServiceOptions()
258258
'label' => $this->presetService->getTranslation('BMC'),
259259
'description' => __('We ask for a 4 digit code/QR code on delivery, which is only known to the recipient')
260260
],
261+
'LQ' => [
262+
'label' => $this->presetService->getTranslation('LQ'),
263+
'description' => __('We will deliver Limited Quantities')
264+
],
261265
];
262266
}
263267

Controller/Adminhtml/Shipment/UndoShipped.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
use DHLParcel\Shipping\Model\Service\Order;
2222
use DHLParcel\Shipping\Model\Service\Order as OrderService;
23+
use DHLParcel\Shipping\Model\Service\Notification as NotificationService;
2324
use Magento\Framework\Exception\InputException;
2425
use Magento\Framework\Exception\LocalizedException;
2526
use Magento\Framework\Exception\NoSuchEntityException;
@@ -28,14 +29,12 @@
2829

2930
class UndoShipped extends \Magento\Backend\App\Action
3031
{
31-
/**
32-
* @var OrderService
33-
*/
32+
/** @var OrderService */
3433
protected $orderService;
34+
/** @var NotificationService */
35+
protected $notificationService;
3536

36-
/**
37-
* @var \Magento\Framework\Controller\Result\JsonFactory
38-
*/
37+
/** @var \Magento\Framework\Controller\Result\JsonFactory */
3938
protected $jsonResultFactory;
4039

4140
/**
@@ -48,10 +47,12 @@ class UndoShipped extends \Magento\Backend\App\Action
4847
public function __construct(
4948
\Magento\Backend\App\Action\Context $context,
5049
\Magento\Framework\Controller\Result\JsonFactory $jsonResultFactory,
51-
OrderService $orderService
50+
OrderService $orderService,
51+
NotificationService $notificationService
5252
) {
5353
$this->jsonResultFactory = $jsonResultFactory;
5454
$this->orderService = $orderService;
55+
$this->notificationService = $notificationService;
5556

5657
parent::__construct($context);
5758
}

Model/Carrier.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,31 @@ public function collectRates(\Magento\Quote\Model\Quote\Address\RateRequest $req
120120
if ($blacklist === true) {
121121
return $result;
122122
}
123+
124+
$ratesAdded = false;
125+
123126
foreach ($this->getMethods() as $key => $title) {
127+
if ($key === 'fallback') {
128+
continue;
129+
}
124130
$method = $this->getShippingMethod($request, $key, $blacklist);
125131
if ($method) {
126132
$this->debugLogger->info("CARRIER successfully added method $key to RateRequest");
127133
$result->append($method);
134+
$ratesAdded = true;
128135
} else {
129136
$this->debugLogger->info("CARRIER failed to add method $key to RateRequest");
130137
}
131138
}
139+
140+
if (!$ratesAdded) {
141+
$method = $this->getShippingMethod($request, 'fallback', $blacklist);
142+
if ($method) {
143+
$this->debugLogger->info("Appending fallback shipping method.");
144+
$result->append($method);
145+
}
146+
}
147+
132148
$this->debugLogger->info('CARRIER --- collect rates finished', $result->asArray());
133149
return $result;
134150
}
@@ -173,10 +189,12 @@ protected function getShippingMethod(
173189
$toBusiness = $this->presetService->defaultToBusiness($this->storeManager->getStore()->getId());
174190
$requestOptions = array_keys($presetOptions);
175191

176-
$sizes = $this->capabilityService->getSizes($this->storeManager->getStore()->getId(), $toCountry, $toPostalCode, $toBusiness, $requestOptions);
177-
if (empty($sizes)) {
178-
$this->debugLogger->info("CARRIER method $methodKey not available due to capabilities", ['options' => $requestOptions, 'response' => $sizes]);
179-
return null;
192+
if ($methodKey !== 'fallback') {
193+
$sizes = $this->capabilityService->getSizes($this->storeManager->getStore()->getId(), $toCountry, $toPostalCode, $toBusiness, $requestOptions);
194+
if (empty($sizes)) {
195+
$this->debugLogger->info("CARRIER method $methodKey not available due to capabilities", ['options' => $requestOptions, 'response' => $sizes]);
196+
return null;
197+
}
180198
}
181199

182200
// Calculate service costs
@@ -380,6 +398,7 @@ public function getTrackingUrl($trackerCode)
380398
protected function getMethods($key = null)
381399
{
382400
$methods = [
401+
PresetService::SHIPPING_METHOD_STANDARD => __('Standard delivery'),
383402
PresetService::SHIPPING_METHOD_DOOR => __('Standard delivery'),
384403
PresetService::SHIPPING_METHOD_EVENING => __('Evening delivery'),
385404
PresetService::SHIPPING_METHOD_NO_NEIGHBOUR => __('No neighbour delivery'),
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace DHLParcel\Shipping\Model\Config\Source;
4+
5+
class EventTrigger implements \Magento\Framework\Option\ArrayInterface
6+
{
7+
const TRIGGER_SAVE_AFTER = 'sales_order_save_after';
8+
const TRIGGER_COMMIT_AFTER = 'sales_order_save_commit_after';
9+
10+
public function toOptionArray()
11+
{
12+
return [
13+
self::TRIGGER_SAVE_AFTER => 'sales_order_save_after',
14+
self::TRIGGER_COMMIT_AFTER => 'sales_order_save_commit_after'
15+
];
16+
}
17+
}

Model/Data/Api/Request/Shipment/Piece.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ class Piece extends AbstractData
88
{
99
public $parcelType;
1010
public $quantity;
11+
public $weight;
1112
}

Model/Data/Api/Response/Capability/ParcelType.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class ParcelType extends AbstractData
1313
public $maxWeightGrams;
1414
/** @var \DHLParcel\Shipping\Model\Data\Api\Response\Capability\ParcelType\Dimension */
1515
public $dimensions;
16+
public $productKey;
1617

1718
protected function getClassMap()
1819
{

Model/Service/Preset.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
class Preset
1212
{
13+
const SHIPPING_METHOD_STANDARD = 'fallback';
1314
const SHIPPING_METHOD_DOOR = 'door';
1415
const SHIPPING_METHOD_EVENING = 'evening';
1516
const SHIPPING_METHOD_SERVICE_POINT = 'servicepoint';
@@ -161,7 +162,8 @@ protected function getOptionsCollection()
161162
self::SHIPPING_METHOD_NO_NEIGHBOUR_EVENING => ['DOOR' => '', 'EVE' => '', 'NBB' => ''],
162163
self::SHIPPING_METHOD_SATURDAY => ['DOOR' => '', 'S' => ''],
163164
self::SHIPPING_METHOD_SERVICE_POINT => ['PS' => ''],
164-
self::SHIPPING_METHOD_DOOR => ['DOOR' => '']
165+
self::SHIPPING_METHOD_DOOR => ['DOOR' => ''],
166+
self::SHIPPING_METHOD_STANDARD => ['DOOR' => '']
165167
];
166168
}
167169

@@ -253,7 +255,8 @@ public function getTranslations()
253255
'SSN' => __('Hide Shipper'),
254256
'SDD' => __('DHL Same-day delivery (6 p.m. to 9.30 p.m.)'),
255257
'AGE_CHECK' => __('Age check (18+)'),
256-
'BMC' => __('Secure delivery by code')
258+
'BMC' => __('Secure delivery by code'),
259+
'LQ' => __('Limited Quantities')
257260
];
258261
}
259262

Observer/AutoMail.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,20 @@ public function __construct(
3030

3131
public function execute(\Magento\Framework\Event\Observer $observer)
3232
{
33+
if (!$this->helper->getConfigData('active')) {
34+
return;
35+
}
36+
3337
// Don't do anything when auto mail is disabled.
3438
if (boolval($this->helper->getConfigData('usability/automation/mail')) === false) {
3539
return;
3640
}
3741

42+
// Only continue if the event trigger name matches
43+
if ($this->helper->getConfigData('usability/automation/event_trigger') !== $observer->getEvent()->getName()) {
44+
return;
45+
}
46+
3847
/* @var \Magento\Sales\Model\Order $order */
3948
$order = $observer->getEvent()->getOrder();
4049

Observer/AutoShipment.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,21 @@ public function __construct(
5353

5454
public function execute(\Magento\Framework\Event\Observer $observer)
5555
{
56+
if (!$this->helper->getConfigData('active')) {
57+
return;
58+
}
59+
5660
// Don't do anything when auto shipment is disabled.
5761
if (!boolval($this->helper->getConfigData('usability/automation/shipment'))
5862
|| strval($this->helper->getConfigData('usability/automation/on_order_status')) === '') {
5963
return;
6064
}
6165

66+
// Only continue if the event trigger name matches
67+
if ($this->helper->getConfigData('usability/automation/event_trigger') !== $observer->getEvent()->getName()) {
68+
return;
69+
}
70+
6271
$observerOrder = $observer->getEvent()->getOrder();
6372
if (!$observerOrder || !$observerOrder->getId()) {
6473
return;

Observer/Checkout/DeliveryServices.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,34 @@
33
namespace DHLParcel\Shipping\Observer\Checkout;
44

55
use DHLParcel\Shipping\Model\Service\DeliveryServices as DeliveryServicesService;
6+
use DHLParcel\Shipping\Helper\Data;
67
use Magento\Framework\Event\Observer as EventObserver;
78
use Magento\Framework\Event\ObserverInterface;
9+
810
use Magento\Checkout\Model\Session as CheckoutSession;
911

1012
class DeliveryServices implements ObserverInterface
1113
{
1214
protected $deliveryServicesService;
1315
protected $checkoutSession;
16+
protected $helper;
1417

1518
public function __construct(
1619
DeliveryServicesService $deliveryServicesService,
17-
CheckoutSession $checkoutSession
20+
CheckoutSession $checkoutSession,
21+
Data $helper
1822
) {
1923
$this->deliveryServicesService = $deliveryServicesService;
2024
$this->checkoutSession = $checkoutSession;
25+
$this->helper = $helper;
2126
}
2227

2328
public function execute(EventObserver $observer)
2429
{
30+
if (!$this->helper->getConfigData('active')) {
31+
return $this;
32+
}
33+
2534
/** @var \Magento\Sales\Api\Data\OrderInterface|\Magento\Sales\Model\Order $order */
2635
$order = $observer->getOrder();
2736

0 commit comments

Comments
 (0)