Skip to content
This repository has been archived by the owner on Dec 11, 2022. It is now read-only.

fixed tracking for australia_post carrier #15

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions Model/Shipping/Carrier/AustraliaPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
use Magento\Shipping\Model\Rate\ResultFactory;
use Magento\Store\Model\ScopeInterface;
use Psr\Log\LoggerInterface;
use Magento\Shipping\Model\Tracking\ResultFactory as TrackingResultFactory;
use Magento\Shipping\Model\Tracking\Result as TrackingResult;
use Magento\Shipping\Model\Tracking\Result\StatusFactory;

class AustraliaPost extends AbstractCarrier implements CarrierInterface
{
Expand All @@ -67,12 +70,21 @@ class AustraliaPost extends AbstractCarrier implements CarrierInterface
/** @var DataHelper */
protected $dataHelper;

/** @var TrackingResultFactory */
protected $trackingResultFactory;

/** @var StatusFactory */
protected $statusFactory;

/**
* AustraliaPost constructor.
* @param CheckoutSession $checkoutSession
* @param ClickAndSend $clickandsendHelper
* @param ErrorFactory $rateErrorFactory
* @param LoggerInterface $logger
* @param MethodFactory $rateMethodFactory
* @param TrackingResultFactory $trackingResultFactory
* @param StatusFactory $statusFactory
* @param ResultFactory $rateResultFactory
* @param ScopeConfigInterface $scopeConfig
* @param DataHelper $dataHelper
Expand All @@ -84,16 +96,20 @@ public function __construct(
ErrorFactory $rateErrorFactory,
LoggerInterface $logger,
MethodFactory $rateMethodFactory,
TrackingResultFactory $trackingResultFactory,
StatusFactory $statusFactory,
ResultFactory $rateResultFactory,
ScopeConfigInterface $scopeConfig,
DataHelper $dataHelper,
array $data = []
) {
$this->trackingResultFactory = $trackingResultFactory;
$this->_clickandsendHelper = $clickandsendHelper;
$this->_rateResultFactory = $rateResultFactory;
$this->_rateMethodFactory = $rateMethodFactory;
$this->checkoutSession = $checkoutSession;
$this->dataHelper = $dataHelper;
$this->statusFactory = $statusFactory;
parent::__construct($scopeConfig, $rateErrorFactory, $logger, $data);
}

Expand Down Expand Up @@ -681,4 +697,62 @@ public function getAttribute($request, $attribute)
return $this->getConfigData('default_' . $attribute);
}
}

/**
* Get info from tracking number
*
* @param string $tracking
* @return string|TrackingResult
*/
public function getTrackingInfo($tracking)
{
$result = $this->getTracking($tracking);

if ($result instanceof TrackingResult) {
if ($trackings = $result->getAllTrackings()) {
return $trackings[0];
}
} elseif (is_string($result) && !empty($result)) {
return $result;
}

return false;
}

/**
* Get tracking
*
* @param array|string $trackings
* @return TrackingResultFactory
*/
public function getTracking($trackings)
{
if (!is_array($trackings)) {
$trackings = array($trackings);
}

return $this->privGetTracking($trackings);
}

/**
* Get tracking info detail
*
* @param array $trackings
* @return TrackingResultFactory
*/
protected function privGetTracking($trackings)
{
$result = $this->trackingResultFactory->create();

foreach ($trackings as $t) {
$tracking = $this->statusFactory->create();
$tracking->setCarrier($this->_code);
$tracking->setCarrierTitle($this->getConfigData('title'));
$tracking->setTracking($t);
$tracking->setUrl('https://auspost.com.au/track/');
$result->append($tracking);
}

return $result;
}
}
4 changes: 4 additions & 0 deletions Model/Shipping/Carrier/Eparcel.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ class Eparcel extends AbstractCarrier implements CarrierInterface
/** @var EparcelResource */
protected $eparcelResource;

/** @var TrackingResultFactory */
protected $trackingResultFactory;

public function __construct(
ScopeConfigInterface $scopeConfig,
ErrorFactory $rateErrorFactory,
Expand All @@ -88,6 +91,7 @@ public function __construct(
$this->rateMethodFactory = $rateMethodFactory;
$this->customerSession = $customerSession;
$this->eparcelResource = $eparcelResource;
$this->trackingResultFactory = $trackingResultFactory;
$this->statusFactory = $statusFactory;
parent::__construct($scopeConfig, $rateErrorFactory, $logger);

Expand Down