Skip to content

Commit

Permalink
Release V1.0.19
Browse files Browse the repository at this point in the history
  • Loading branch information
ShinCode committed Feb 2, 2021
1 parent 2d76095 commit 869358d
Show file tree
Hide file tree
Showing 12 changed files with 307 additions and 77 deletions.
2 changes: 1 addition & 1 deletion Controller/DeliveryServices/Available.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function execute()
$options = $this->capabilityService->getOptions($this->storeManager->getStore()->getId(), $toCountry, $toPostalCode, $toBusiness, ['DOOR']);
}

$data = $this->deliveryServicesService->getAvailability($options, $subtotal, $selections);
$data = $this->deliveryServicesService->getAvailability($options, $subtotal, $selections, $this->storeManager->getStore()->getId());

return $this->resultFactory
->create(\Magento\Framework\Controller\ResultFactory::TYPE_JSON)
Expand Down
45 changes: 34 additions & 11 deletions Model/Service/DeliveryServices.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class DeliveryServices

protected $assetRepository;
protected $priceHelper;
protected $taxHelper;
protected $helper;
protected $availabilityFactory;
protected $optionFactory;
Expand All @@ -29,12 +30,14 @@ class DeliveryServices
public function __construct(
\Magento\Framework\View\Asset\Repository $assetRepository,
\Magento\Framework\Pricing\Helper\Data $priceHelper,
\Magento\Tax\Helper\Data $taxHelper,
Data $helper,
DeliveryServicesAvailabilityFactory $availabilityFactory,
OptionFactory $optionFactory
) {
$this->assetRepository = $assetRepository;
$this->priceHelper = $priceHelper;
$this->taxHelper = $taxHelper;
$this->helper = $helper;
$this->availabilityFactory = $availabilityFactory;
$this->optionFactory = $optionFactory;
Expand All @@ -51,7 +54,7 @@ public function getToBusiness()
* @param array $selections
* @return \DHLParcel\Shipping\Model\Data\DeliveryServicesAvailability
*/
public function getAvailability($options, $subtotal = 0, $selections = [])
public function getAvailability($options, $subtotal = 0, $selections = [], $store = null)
{
/** @var \DHLParcel\Shipping\Model\Data\DeliveryServicesAvailability $availability */
$availability = $this->availabilityFactory->create();
Expand All @@ -64,7 +67,8 @@ public function getAvailability($options, $subtotal = 0, $selections = [])
self::NO_NEIGHBOUR,
$this->getTitle(self::NO_NEIGHBOUR),
__('Do not drop off at neighbours'),
$subtotal
$subtotal,
$store
);
}
if (array_key_exists(self::EVENING, $options) &&
Expand All @@ -73,7 +77,8 @@ public function getAvailability($options, $subtotal = 0, $selections = [])
self::EVENING,
$this->getTitle(self::EVENING),
__('Delivery in the evening'),
$subtotal
$subtotal,
$store
);
}
if (array_key_exists(self::SATURDAY, $options) &&
Expand All @@ -82,7 +87,8 @@ public function getAvailability($options, $subtotal = 0, $selections = [])
self::SATURDAY,
$this->getTitle(self::SATURDAY),
__('Package will also be delivered on Saturdays'),
$subtotal
$subtotal,
$store
);
}
if (array_key_exists(self::MORNING, $options) &&
Expand All @@ -91,7 +97,8 @@ public function getAvailability($options, $subtotal = 0, $selections = [])
self::MORNING,
$this->getTitle(self::MORNING),
__('Deliver shipment before 11 AM'),
$subtotal
$subtotal,
$store
);
}

Expand Down Expand Up @@ -254,20 +261,36 @@ protected function getTitle($key)
return $titles[$key];
}

protected function getServiceData($code, $title, $description, $subtotal)
protected function getServiceData($code, $title, $description, $subtotal, $store = null)
{
$price = $this->getTaxPrice($this->serviceCost($subtotal, [$code]), $store);

return [
'value' => $code,
'title' => $title,
'description' => $description,
'image' => $this->getImageUrl($code),
'price' => '+ ' . $this->priceHelper->currencyByStore(
$this->serviceCost($subtotal, [$code]),
null,
'price' => $price,
];
}

protected function getTaxPrice($serviceCost, $store = null)
{
if ($this->taxHelper->getShippingPriceDisplayType($store) === \Magento\Tax\Model\Config::DISPLAY_TYPE_EXCLUDING_TAX) {
return '+ ' . $this->priceHelper->currencyByStore(
$serviceCost,
$store,
true,
false
),
];
);
}

return '+ ' . $this->priceHelper->currencyByStore(
$this->taxHelper->getShippingPrice($serviceCost, true, null, null, $store),
$store,
true,
false
);
}

protected function sanitizeData($array)
Expand Down
58 changes: 58 additions & 0 deletions Model/Service/Returns.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace DHLParcel\Shipping\Model\Service;


use DHLParcel\Shipping\Model\Piece;
use DHLParcel\Shipping\Model\PieceFactory;
use DHLParcel\Shipping\Model\ResourceModel\Piece as PieceResource;
use Magento\Store\Model\StoreManagerInterface;

class Returns
{
protected $pieceResource;
protected $pieceFactory;
/** @var StoreManagerInterface */
protected $storeManager;

public function __construct(
StoreManagerInterface $storeManager,
PieceResource $pieceResource,
PieceFactory $pieceFactory
) {

$this->storeManager = $storeManager;
$this->pieceResource = $pieceResource;
$this->pieceFactory = $pieceFactory;
}

public function cleanupReturnTracks($tracks)
{

foreach ($tracks as $key => $track) {
if ($track->getCarrierCode() == 'dhlparcel' || $track->getCarrier() == 'dhlparcel') {
// TODO move this to a service function getPiece($track)
$trackNumber = $track->getTrackNumber();
if (empty($trackNumber)) {
$trackNumber = $track->getTracking();
}

/** @var Piece $piece */
$piece = $this->pieceFactory->create();
$this->pieceResource->load($piece, $trackNumber, 'tracker_code');
$isReturn = $piece->getIsReturn();
if ($isReturn) {
// Remove if it's a return label
if (is_array($tracks)) {
unset($tracks[$key]);
} else {
$tracks->removeItemByKey($key);
}
}
}
}

return $tracks;
}

}
62 changes: 0 additions & 62 deletions Plugin/Email/Shipment/Track.php

This file was deleted.

65 changes: 65 additions & 0 deletions Plugin/Order/HideReturnTrack.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace DHLParcel\Shipping\Plugin\Order;

use DHLParcel\Shipping\Helper\Data;
use DHLParcel\Shipping\Model\Service\Returns as ReturnService;
use Magento\Sales\Model\ResourceModel\Order\Shipment\Track\Collection as TracksCollection;

class HideReturnTrack
{
/** @var Returns */
protected $returnService;

/** @var Data */
protected $helper;

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

/**
* @param \Magento\Sales\Model\Order $subject
* @param TracksCollection $tracks
* @return TracksCollection
*/
public function afterGetTracksCollection(\Magento\Sales\Model\Order $subject, $tracks)
{
if (boolval($this->helper->getConfigData('usability/return_tracks/show_for_customers'))) {
return $tracks;
}

// Expected the template to be at around trace #4, but depending on the amount of interceptors this might differ
// Thus the limit is set higher to offset this
$traces = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 14);

$hideReturnTrack = false;
foreach ($traces as $trace) {
if (is_array($trace) && isset($trace['file'])) {
$searches = [
'email/shipment/track.phtml',
'frontend/templates/items.phtml',
'Block/Order/PrintOrder/Shipment.php'
];
foreach ($searches as $search) {
$templateFile = $trace['file'];

if (substr($templateFile, -strlen($search)) === $search) {
$hideReturnTrack = true;
break 2;
}
}
}
}

if (!$hideReturnTrack) {
return $tracks;
}

return $this->returnService->cleanupReturnTracks($tracks);
}
}
Loading

0 comments on commit 869358d

Please sign in to comment.