Skip to content

Commit

Permalink
Fixing the tracking information.
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagosampaio committed Jan 21, 2020
1 parent f4b783c commit 825f357
Showing 1 changed file with 35 additions and 22 deletions.
57 changes: 35 additions & 22 deletions app/code/community/Frenet/Shipping/Model/Carrier/Frenet.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,51 +204,60 @@ public function getAllowedMethods()
return [self::CARRIER_CODE => $this->config->getCarrierConfig('name')];
}

/**
* @return bool
*/
public function isTrackingAvailable()
{
return true;
}

/**
* @param $trackingNumbers
*
* @return Mage_Shipping_Model_Rate_Result
* @return Mage_Shipping_Model_Tracking_Result_Status
*/
public function getTracking($trackingNumbers)
public function getTrackingInfo($trackingNumbers)
{
if (!is_array($trackingNumbers)) {
$trackingNumbers = [$trackingNumbers];
}

$this->prepareTracking($trackingNumbers);

return $this->result;
return $this->prepareTracking($trackingNumbers);
}

/**
* @param array $trackingNumbers
*
* @return Mage_Shipping_Model_Tracking_Result
* @return Mage_Shipping_Model_Tracking_Result_Status
*/
private function prepareTracking(array $trackingNumbers)
{
/** @var Mage_Shipping_Model_Tracking_Result $result */
$result = Mage::getModel('shipping/tracking_result');
/** @var Mage_Shipping_Model_Tracking_Result_Status $status */
$status = Mage::getModel('shipping/tracking_result_status');

/** @var string $trackingNumber */
/**
* @var string $trackingNumber
* @todo It's currently appending only one tracking per time. Find a solution to append more than one.
*/
foreach ($trackingNumbers as $trackingNumber) {
/** @var \Frenet\ObjectType\Entity\Shipping\Info\ServiceInterface $service */
$service = $this->serviceFinder->findByTrackingNumber($trackingNumber);
$serviceCode = $service ? $service->getServiceCode() : null;

/** @var Mage_Shipping_Model_Tracking_Result_Status $status */
$status = $this->_trackStatusFactory->create();
$status->setCarrier(self::CARRIER_CODE);
$status->setCarrierTitle($this->getConfigData('title'));
$status->setTracking($trackingNumber);
$status->setPopup(1);
$status->setTrackSummary($this->prepareTrackingInformation($status, $trackingNumber, $serviceCode));
$result->append($status);
}
$status->setData([
'carrier' => self::CARRIER_CODE,
'carrier_title' => $this->getConfigData('title'),
'tracking' => $trackingNumber,
'popup' => 1,
]);

$this->result = $result;
/** @todo track_summary needs to be filled here. */
$this->prepareTrackingInformation($status, $trackingNumber, $serviceCode);
break;
}

return $result;
return $status;
}

/**
Expand All @@ -258,8 +267,11 @@ private function prepareTracking(array $trackingNumbers)
*
* @return void
*/
private function prepareTrackingInformation($status, $trackingNumber, $shippingServiceCode)
{
private function prepareTrackingInformation(
Mage_Shipping_Model_Tracking_Result_Status $status,
$trackingNumber,
$shippingServiceCode
) {
/** @var \Frenet\ObjectType\Entity\Tracking\TrackingInfoInterface $trackingInfo */
$trackingInfo = $this->trackingService->track($trackingNumber, $shippingServiceCode);

Expand All @@ -276,6 +288,7 @@ private function prepareTrackingInformation($status, $trackingNumber, $shippingS
$status->setDeliveryLocation($event->getEventLocation());
$status->setShippedDate($event->getEventDatetime());
$status->setService($event->getTrackingInfo()->getServiceDescription());
$status->setTrackSummary($event->getTrackingInfo()->getServiceDescription());
}

/**
Expand Down

0 comments on commit 825f357

Please sign in to comment.