Skip to content

Commit

Permalink
v1.0.47
Browse files Browse the repository at this point in the history
  • Loading branch information
ShinCode committed May 28, 2024
1 parent 70ce72c commit cea5fb4
Show file tree
Hide file tree
Showing 28 changed files with 435 additions and 504 deletions.
4 changes: 4 additions & 0 deletions Block/Adminhtml/Order/Shipment/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ public function getServiceOptions()
'label' => $this->presetService->getTranslation('BMC'),
'description' => __('We ask for a 4 digit code/QR code on delivery, which is only known to the recipient')
],
'LQ' => [
'label' => $this->presetService->getTranslation('LQ'),
'description' => __('We will deliver Limited Quantities')
],
];
}

Expand Down
15 changes: 8 additions & 7 deletions Controller/Adminhtml/Shipment/UndoShipped.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

use DHLParcel\Shipping\Model\Service\Order;
use DHLParcel\Shipping\Model\Service\Order as OrderService;
use DHLParcel\Shipping\Model\Service\Notification as NotificationService;
use Magento\Framework\Exception\InputException;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
Expand All @@ -28,14 +29,12 @@

class UndoShipped extends \Magento\Backend\App\Action
{
/**
* @var OrderService
*/
/** @var OrderService */
protected $orderService;
/** @var NotificationService */
protected $notificationService;

/**
* @var \Magento\Framework\Controller\Result\JsonFactory
*/
/** @var \Magento\Framework\Controller\Result\JsonFactory */
protected $jsonResultFactory;

/**
Expand All @@ -48,10 +47,12 @@ class UndoShipped extends \Magento\Backend\App\Action
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\Controller\Result\JsonFactory $jsonResultFactory,
OrderService $orderService
OrderService $orderService,
NotificationService $notificationService
) {
$this->jsonResultFactory = $jsonResultFactory;
$this->orderService = $orderService;
$this->notificationService = $notificationService;

parent::__construct($context);
}
Expand Down
27 changes: 23 additions & 4 deletions Model/Carrier.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,31 @@ public function collectRates(\Magento\Quote\Model\Quote\Address\RateRequest $req
if ($blacklist === true) {
return $result;
}

$ratesAdded = false;

foreach ($this->getMethods() as $key => $title) {
if ($key === 'fallback') {
continue;
}
$method = $this->getShippingMethod($request, $key, $blacklist);
if ($method) {
$this->debugLogger->info("CARRIER successfully added method $key to RateRequest");
$result->append($method);
$ratesAdded = true;
} else {
$this->debugLogger->info("CARRIER failed to add method $key to RateRequest");
}
}

if (!$ratesAdded) {
$method = $this->getShippingMethod($request, 'fallback', $blacklist);
if ($method) {
$this->debugLogger->info("Appending fallback shipping method.");
$result->append($method);
}
}

$this->debugLogger->info('CARRIER --- collect rates finished', $result->asArray());
return $result;
}
Expand Down Expand Up @@ -173,10 +189,12 @@ protected function getShippingMethod(
$toBusiness = $this->presetService->defaultToBusiness($this->storeManager->getStore()->getId());
$requestOptions = array_keys($presetOptions);

$sizes = $this->capabilityService->getSizes($this->storeManager->getStore()->getId(), $toCountry, $toPostalCode, $toBusiness, $requestOptions);
if (empty($sizes)) {
$this->debugLogger->info("CARRIER method $methodKey not available due to capabilities", ['options' => $requestOptions, 'response' => $sizes]);
return null;
if ($methodKey !== 'fallback') {
$sizes = $this->capabilityService->getSizes($this->storeManager->getStore()->getId(), $toCountry, $toPostalCode, $toBusiness, $requestOptions);
if (empty($sizes)) {
$this->debugLogger->info("CARRIER method $methodKey not available due to capabilities", ['options' => $requestOptions, 'response' => $sizes]);
return null;
}
}

// Calculate service costs
Expand Down Expand Up @@ -380,6 +398,7 @@ public function getTrackingUrl($trackerCode)
protected function getMethods($key = null)
{
$methods = [
PresetService::SHIPPING_METHOD_STANDARD => __('Standard delivery'),
PresetService::SHIPPING_METHOD_DOOR => __('Standard delivery'),
PresetService::SHIPPING_METHOD_EVENING => __('Evening delivery'),
PresetService::SHIPPING_METHOD_NO_NEIGHBOUR => __('No neighbour delivery'),
Expand Down
17 changes: 17 additions & 0 deletions Model/Config/Source/EventTrigger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace DHLParcel\Shipping\Model\Config\Source;

class EventTrigger implements \Magento\Framework\Option\ArrayInterface
{
const TRIGGER_SAVE_AFTER = 'sales_order_save_after';
const TRIGGER_COMMIT_AFTER = 'sales_order_save_commit_after';

public function toOptionArray()
{
return [
self::TRIGGER_SAVE_AFTER => 'sales_order_save_after',
self::TRIGGER_COMMIT_AFTER => 'sales_order_save_commit_after'
];
}
}
1 change: 1 addition & 0 deletions Model/Data/Api/Request/Shipment/Piece.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ class Piece extends AbstractData
{
public $parcelType;
public $quantity;
public $weight;
}
1 change: 1 addition & 0 deletions Model/Data/Api/Response/Capability/ParcelType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ParcelType extends AbstractData
public $maxWeightGrams;
/** @var \DHLParcel\Shipping\Model\Data\Api\Response\Capability\ParcelType\Dimension */
public $dimensions;
public $productKey;

protected function getClassMap()
{
Expand Down
7 changes: 5 additions & 2 deletions Model/Service/Preset.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

class Preset
{
const SHIPPING_METHOD_STANDARD = 'fallback';
const SHIPPING_METHOD_DOOR = 'door';
const SHIPPING_METHOD_EVENING = 'evening';
const SHIPPING_METHOD_SERVICE_POINT = 'servicepoint';
Expand Down Expand Up @@ -161,7 +162,8 @@ protected function getOptionsCollection()
self::SHIPPING_METHOD_NO_NEIGHBOUR_EVENING => ['DOOR' => '', 'EVE' => '', 'NBB' => ''],
self::SHIPPING_METHOD_SATURDAY => ['DOOR' => '', 'S' => ''],
self::SHIPPING_METHOD_SERVICE_POINT => ['PS' => ''],
self::SHIPPING_METHOD_DOOR => ['DOOR' => '']
self::SHIPPING_METHOD_DOOR => ['DOOR' => ''],
self::SHIPPING_METHOD_STANDARD => ['DOOR' => '']
];
}

Expand Down Expand Up @@ -253,7 +255,8 @@ public function getTranslations()
'SSN' => __('Hide Shipper'),
'SDD' => __('DHL Same-day delivery (6 p.m. to 9.30 p.m.)'),
'AGE_CHECK' => __('Age check (18+)'),
'BMC' => __('Secure delivery by code')
'BMC' => __('Secure delivery by code'),
'LQ' => __('Limited Quantities')
];
}

Expand Down
9 changes: 9 additions & 0 deletions Observer/AutoMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,20 @@ public function __construct(

public function execute(\Magento\Framework\Event\Observer $observer)
{
if (!$this->helper->getConfigData('active')) {
return;
}

// Don't do anything when auto mail is disabled.
if (boolval($this->helper->getConfigData('usability/automation/mail')) === false) {
return;
}

// Only continue if the event trigger name matches
if ($this->helper->getConfigData('usability/automation/event_trigger') !== $observer->getEvent()->getName()) {
return;
}

/* @var \Magento\Sales\Model\Order $order */
$order = $observer->getEvent()->getOrder();

Expand Down
9 changes: 9 additions & 0 deletions Observer/AutoShipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,21 @@ public function __construct(

public function execute(\Magento\Framework\Event\Observer $observer)
{
if (!$this->helper->getConfigData('active')) {
return;
}

// Don't do anything when auto shipment is disabled.
if (!boolval($this->helper->getConfigData('usability/automation/shipment'))
|| strval($this->helper->getConfigData('usability/automation/on_order_status')) === '') {
return;
}

// Only continue if the event trigger name matches
if ($this->helper->getConfigData('usability/automation/event_trigger') !== $observer->getEvent()->getName()) {
return;
}

$observerOrder = $observer->getEvent()->getOrder();
if (!$observerOrder || !$observerOrder->getId()) {
return;
Expand Down
11 changes: 10 additions & 1 deletion Observer/Checkout/DeliveryServices.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,34 @@
namespace DHLParcel\Shipping\Observer\Checkout;

use DHLParcel\Shipping\Model\Service\DeliveryServices as DeliveryServicesService;
use DHLParcel\Shipping\Helper\Data;
use Magento\Framework\Event\Observer as EventObserver;
use Magento\Framework\Event\ObserverInterface;

use Magento\Checkout\Model\Session as CheckoutSession;

class DeliveryServices implements ObserverInterface
{
protected $deliveryServicesService;
protected $checkoutSession;
protected $helper;

public function __construct(
DeliveryServicesService $deliveryServicesService,
CheckoutSession $checkoutSession
CheckoutSession $checkoutSession,
Data $helper
) {
$this->deliveryServicesService = $deliveryServicesService;
$this->checkoutSession = $checkoutSession;
$this->helper = $helper;
}

public function execute(EventObserver $observer)
{
if (!$this->helper->getConfigData('active')) {
return $this;
}

/** @var \Magento\Sales\Api\Data\OrderInterface|\Magento\Sales\Model\Order $order */
$order = $observer->getOrder();

Expand Down
10 changes: 9 additions & 1 deletion Observer/Checkout/DeliveryTimes.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace DHLParcel\Shipping\Observer\Checkout;

use DHLParcel\Shipping\Model\Service\DeliveryTimes as DeliveryTimesService;
use DHLParcel\Shipping\Helper\Data;
use Magento\Framework\Event\Observer as EventObserver;
use Magento\Framework\Event\ObserverInterface;
use Magento\Checkout\Model\Session as CheckoutSession;
Expand All @@ -11,17 +12,24 @@ class DeliveryTimes implements ObserverInterface
{
protected $deliveryTimesService;
protected $checkoutSession;
protected $helper;

public function __construct(
DeliveryTimesService $deliveryTimesService,
CheckoutSession $checkoutSession
CheckoutSession $checkoutSession,
Data $helper
) {
$this->deliveryTimesService = $deliveryTimesService;
$this->checkoutSession = $checkoutSession;
$this->helper = $helper;
}

public function execute(EventObserver $observer)
{
if (!$this->helper->getConfigData('active')) {
return $this;
}

/** @var \Magento\Sales\Api\Data\OrderInterface|\Magento\Sales\Model\Order $order */
$order = $observer->getOrder();

Expand Down
10 changes: 9 additions & 1 deletion Observer/Checkout/Sameday.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,29 @@
namespace DHLParcel\Shipping\Observer\Checkout;

use DHLParcel\Shipping\Model\Service\DeliveryTimes as DeliveryTimesService;
use DHLParcel\Shipping\Helper\Data;
use Magento\Framework\Event\Observer as EventObserver;
use Magento\Framework\Event\ObserverInterface;

class Sameday implements ObserverInterface
{
protected $deliveryTimesService;
protected $helper;

public function __construct(
DeliveryTimesService $deliveryTimesService
DeliveryTimesService $deliveryTimesService,
Data $helper
) {
$this->deliveryTimesService = $deliveryTimesService;
$this->helper = $helper;
}

public function execute(EventObserver $observer)
{
if (!$this->helper->getConfigData('active')) {
return $this;
}

/** @var \Magento\Sales\Api\Data\OrderInterface|\Magento\Sales\Model\Order $order */
$order = $observer->getOrder();

Expand Down
10 changes: 9 additions & 1 deletion Observer/Checkout/ServicePoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,30 @@

namespace DHLParcel\Shipping\Observer\Checkout;

use DHLParcel\Shipping\Helper\Data;
use Magento\Framework\Event\Observer as EventObserver;
use Magento\Framework\Event\ObserverInterface;
use Magento\Checkout\Model\Session as CheckoutSession;

class ServicePoint implements ObserverInterface
{
protected $checkoutSession;
protected $helper;

public function __construct(
CheckoutSession $checkoutSession
CheckoutSession $checkoutSession,
Data $helper
) {
$this->checkoutSession = $checkoutSession;
$this->helper = $helper;
}

public function execute(EventObserver $observer)
{
if (!$this->helper->getConfigData('active')) {
return $this;
}

$order = $observer->getOrder();
if ($order->getShippingMethod() === 'dhlparcel_servicepoint') {
// Save session ServicePoint to order
Expand Down
4 changes: 4 additions & 0 deletions Observer/EmailServicePoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public function __construct(

public function execute(\Magento\Framework\Event\Observer $observer)
{
if (!$this->helper->getConfigData('active')) {
return;
}

/** @var \Magento\Framework\DataObject $transport */
$transport = $observer->getData('transport');
if (is_array($transport)) {
Expand Down
11 changes: 9 additions & 2 deletions Observer/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ public function __construct(
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
if (!$this->helper->getConfigData('active')) {
return;
}

/** @var \Magento\Sales\Model\Order\Shipment $shipment */
$shipment = $observer->getEvent()->getData('shipment');

Expand Down Expand Up @@ -232,7 +236,8 @@ protected function processForm($orderId)

if (isset($shipmentFormData['package'])) {
foreach ($shipmentFormData['package'] as $key => $value) {
$pieces[] = $this->createPiece($value);
$weight = $shipmentFormData['package_weight'][$key] ?? 0;
$pieces[] = $this->createPiece($value, 1, $weight);
}
}

Expand Down Expand Up @@ -307,12 +312,14 @@ protected function createOption($key, $input = '')
* @param int $quantity
* @return Piece
*/
protected function createPiece($parcelType, $quantity = 1)
protected function createPiece($parcelType, $quantity = 1, $weight = 0)
{
/** @var Piece $piece */
$piece = $this->pieceFactory->create();
$piece->parcelType = $parcelType;
$piece->quantity = $quantity;
$piece->weight = $weight;

return $piece;
}
}
Loading

0 comments on commit cea5fb4

Please sign in to comment.