Skip to content
Snippets Groups Projects
Commit 2c15955c authored by Gundo Sifhufhi's avatar Gundo Sifhufhi
Browse files

carrier model refactoring

parent c6f8cc1c
Branches
Tags
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PhpProjectSharedConfiguration" php_language_level="7.0" />
</project>
\ No newline at end of file
......@@ -115,37 +115,6 @@ class Customshipping extends AbstractCarrier implements CarrierInterface
return true;
}
// /**
// * Obtain Tracking Information from uAfrica/Bobgo
// * @param string $trackings
// */
// public function getTrackingInfo($trackings)
// {
// // $result = $this->_trackFactory->create();
// // $tracking = explode(',', $trackings);
// // Get Tracking Results From uafrica API
// $this->curl->get("https://api.dev.ship.uafrica.com/tracking?channel=localhost&tracking_reference=UADPCTGF");
//
// $result = $this->curl->getBody();
//
// $bobGo = \Safe\json_decode($result, true);
//// $result->setUrl('https://api.dev.ship.uafrica.com/tracking?channel=localhost&tracking_reference=UADPCTGF');
//// $result->setTracking($trackings);
//// $result->setCarrierTitle($this->getConfigData('title'));
// $track = $this->jsonFactory->create()->setData($bobGo);
//
// return $track;
// }
// /**
// * Get tracking information
// *
// */
//
// public function getTracking()
// {
// return $this->getTrackingInfo();
// }
/**
* Collect and get rates for storefront
*
......
<?php
namespace uafrica\Customshipping\Plugin\Block\Tracking;
use Magento\Shipping\Block\Tracking\Popup;
use Magento\Shipping\Model\Tracking\Result\Status;
use Magento\Shiiping\Model\Carrier;
/*
* Plugin to update delivery date value in case if UAfrica is a carrier used
*/
class PopupDeliveryDate
{
/**
* Show only date for expected delivery in case if UAfrica is a carrier
*
* @param Popup $subject
* @param string $result
* @param string $date
* @param string $time
* @return string
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterFormatDeliveryDateTime(Popup $subject, $result, $date, $time)
{
if ($this->getCarrier($subject) === Carrier::CODE) {
$result = $subject->formatDeliveryDate($date);
}
return $result;
}
/**
* Retrieve carrier name from tracking info
*
* @param Popup $subject
* @return string
*/
private function getCarrier(Popup $subject): string
{
foreach ($subject->getTrackingInfo() as $trackingData) {
foreach ($trackingData as $trackingInfo) {
if ($trackingInfo instanceof Status) {
$carrier = $trackingInfo->getCarrier();
return $carrier;
}
}
}
return '';
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment