-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
307 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.