Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Info Class Reference
Inheritance diagram for Info:
DataObject

Public Member Functions

 __construct (\Magento\Shipping\Helper\Data $shippingData, \Magento\Sales\Model\OrderFactory $orderFactory, \Magento\Sales\Api\ShipmentRepositoryInterface $shipmentRepository, \Magento\Shipping\Model\Order\TrackFactory $trackFactory, \Magento\Shipping\Model\ResourceModel\Order\Track\CollectionFactory $trackCollectionFactory, array $data=[])
 
 loadByHash ($hash)
 
 getTrackingInfo ()
 
 getTrackingInfoByOrder ()
 
 getTrackingInfoByShip ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 

Protected Member Functions

 _initShipment ()
 
 _getTracksCollection (Shipment $shipment)
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $_trackingInfo = []
 
 $_shippingData
 
 $_orderFactory
 
 $shipmentRepository
 
 $_trackFactory
 
 $_trackCollectionFactory
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Definition at line 11 of file Info.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Shipping\Helper\Data  $shippingData,
\Magento\Sales\Model\OrderFactory  $orderFactory,
\Magento\Sales\Api\ShipmentRepositoryInterface  $shipmentRepository,
\Magento\Shipping\Model\Order\TrackFactory  $trackFactory,
\Magento\Shipping\Model\ResourceModel\Order\Track\CollectionFactory  $trackCollectionFactory,
array  $data = [] 
)
Parameters
\Magento\Shipping\Helper\Data$shippingData
\Magento\Sales\Model\OrderFactory$orderFactory
\Magento\Sales\Api\ShipmentRepositoryInterface$shipmentRepository
\Magento\Shipping\Model\Order\TrackFactory$trackFactory
\Magento\Shipping\Model\ResourceModel\Order\Track\CollectionFactory$trackCollectionFactory
array$data

Definition at line 55 of file Info.php.

62  {
63  $this->_shippingData = $shippingData;
64  $this->_orderFactory = $orderFactory;
65  $this->shipmentRepository = $shipmentRepository;
66  $this->_trackFactory = $trackFactory;
67  $this->_trackCollectionFactory = $trackCollectionFactory;
68  parent::__construct($data);
69  }

Member Function Documentation

◆ _getTracksCollection()

_getTracksCollection ( Shipment  $shipment)
protected
Parameters
Shipment$shipment
Returns
\Magento\Shipping\Model\ResourceModel\Order\Track\Collection

Definition at line 208 of file Info.php.

209  {
210  $tracks = $this->_trackCollectionFactory->create()->setShipmentFilter($shipment->getId());
211 
212  if ($shipment->getId()) {
213  foreach ($tracks as $track) {
214  $track->setShipment($shipment);
215  }
216  }
217  return $tracks;
218  }
$track
Definition: details.phtml:12
foreach($order->getItems() as $orderItem) $shipment

◆ _initShipment()

_initShipment ( )
protected

Instantiate ship model

Returns
Shipment|bool

Definition at line 129 of file Info.php.

130  {
131  /* @var $model Shipment */
132  $ship = $this->shipmentRepository->get($this->getShipId());
133  if (!$ship->getEntityId() || $this->getProtectCode() !== $ship->getProtectCode()) {
134  return false;
135  }
136 
137  return $ship;
138  }

◆ getTrackingInfo()

getTrackingInfo ( )

Retrieve tracking info

Returns
array

Definition at line 102 of file Info.php.

103  {
104  return $this->_trackingInfo;
105  }

◆ getTrackingInfoByOrder()

getTrackingInfoByOrder ( )

Retrieve all tracking by order id

Returns
array

Definition at line 145 of file Info.php.

146  {
147  $shipTrack = [];
148  $order = $this->_initOrder();
149  if ($order) {
150  $shipments = $order->getShipmentsCollection();
151  foreach ($shipments as $shipment) {
152  $increment_id = $shipment->getIncrementId();
153  $tracks = $this->_getTracksCollection($shipment);
154 
155  $trackingInfos = [];
156  foreach ($tracks as $track) {
157  $trackingInfos[] = $track->getNumberDetail();
158  }
159  $shipTrack[$increment_id] = $trackingInfos;
160  }
161  }
162  $this->_trackingInfo = $shipTrack;
163  return $this->_trackingInfo;
164  }
$track
Definition: details.phtml:12
$order
Definition: order.php:55
_getTracksCollection(Shipment $shipment)
Definition: Info.php:208
$shipments
foreach($order->getItems() as $orderItem) $shipment

◆ getTrackingInfoByShip()

getTrackingInfoByShip ( )

Retrieve all tracking by ship id

Returns
array

Definition at line 171 of file Info.php.

172  {
173  $shipTrack = [];
174  $shipment = $this->_initShipment();
175  if ($shipment) {
176  $increment_id = $shipment->getIncrementId();
178 
179  $trackingInfos = [];
180  foreach ($tracks as $track) {
181  $trackingInfos[] = $track->getNumberDetail();
182  }
183  $shipTrack[$increment_id] = $trackingInfos;
184  }
185  $this->_trackingInfo = $shipTrack;
186  return $this->_trackingInfo;
187  }
$track
Definition: details.phtml:12
_getTracksCollection(Shipment $shipment)
Definition: Info.php:208
foreach($order->getItems() as $orderItem) $shipment

◆ loadByHash()

loadByHash (   $hash)

Generating tracking info

Parameters
array$hash
Returns
$this

Definition at line 77 of file Info.php.

78  {
79  /* @var $helper \Magento\Shipping\Helper\Data */
81  $data = $helper->decodeTrackingHash($hash);
82  if (!empty($data)) {
83  $this->setData($data['key'], $data['id']);
84  $this->setProtectCode($data['hash']);
85 
86  if ($this->getOrderId() > 0) {
87  $this->getTrackingInfoByOrder();
88  } elseif ($this->getShipId() > 0) {
89  $this->getTrackingInfoByShip();
90  } else {
91  $this->getTrackingInfoByTrackId();
92  }
93  }
94  return $this;
95  }
$helper
Definition: iframe.phtml:13
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
setData($key, $value=null)
Definition: DataObject.php:72

Field Documentation

◆ $_orderFactory

$_orderFactory
protected

Definition at line 30 of file Info.php.

◆ $_shippingData

$_shippingData
protected

Definition at line 25 of file Info.php.

◆ $_trackCollectionFactory

$_trackCollectionFactory
protected

Definition at line 45 of file Info.php.

◆ $_trackFactory

$_trackFactory
protected

Definition at line 40 of file Info.php.

◆ $_trackingInfo

$_trackingInfo = []
protected

Definition at line 18 of file Info.php.

◆ $shipmentRepository

$shipmentRepository
protected

Definition at line 35 of file Info.php.


The documentation for this class was generated from the following file: