Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Track.php
Go to the documentation of this file.
1 <?php
7 
12 
19 class Track extends AbstractModel implements ShipmentTrackInterface
20 {
24  const CUSTOM_CARRIER_CODE = 'custom';
25 
29  protected $_shipment = null;
30 
34  protected $_eventPrefix = 'sales_order_shipment_track';
35 
39  protected $_eventObject = 'track';
40 
44  protected $_storeManager;
45 
50 
63  public function __construct(
64  \Magento\Framework\Model\Context $context,
65  \Magento\Framework\Registry $registry,
66  \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
70  \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
71  \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
72  array $data = []
73  ) {
74  parent::__construct(
75  $context,
76  $registry,
77  $extensionFactory,
79  $resource,
80  $resourceCollection,
81  $data
82  );
83  $this->_storeManager = $storeManager;
84  $this->shipmentRepository = $shipmentRepository;
85  }
86 
92  protected function _construct()
93  {
94  $this->_init(\Magento\Sales\Model\ResourceModel\Order\Shipment\Track::class);
95  }
96 
104  public function getNumber()
105  {
106  return $this->getData('track_number');
107  }
108 
117  public function setNumber($number)
118  {
119  return $this->setData('track_number', $number);
120  }
121 
130  public function setShipment(\Magento\Sales\Model\Order\Shipment $shipment)
131  {
132  $this->_shipment = $shipment;
133  return $this;
134  }
135 
142  public function getShipment()
143  {
144  if (!$this->_shipment instanceof \Magento\Sales\Model\Order\Shipment) {
145  if ($this->getParentId()) {
146  $this->_shipment = $this->shipmentRepository->get($this->getParentId());
147  } else {
148  throw new LocalizedException(__("Parent shipment cannot be loaded for track object."));
149  }
150  }
151 
152  return $this->_shipment;
153  }
154 
160  public function isCustom()
161  {
162  return $this->getCarrierCode() == self::CUSTOM_CARRIER_CODE;
163  }
164 
170  public function getProtectCode()
171  {
172  return (string)$this->getShipment()->getProtectCode();
173  }
174 
180  public function getStore()
181  {
182  if ($this->getShipment()) {
183  return $this->getShipment()->getStore();
184  }
185  return $this->_storeManager->getStore();
186  }
187 
193  public function getStoreId()
194  {
195  return $this->getStore()->getId();
196  }
197 
206  public function addData(array $data)
207  {
208  if (array_key_exists('number', $data)) {
209  $this->setNumber($data['number']);
210  unset($data['number']);
211  }
212  return parent::addData($data);
213  }
214 
215  //@codeCoverageIgnoreStart
216 
222  public function getTrackNumber()
223  {
225  }
226 
232  public function getCarrierCode()
233  {
235  }
236 
242  public function getCreatedAt()
243  {
245  }
246 
250  public function setCreatedAt($createdAt)
251  {
252  return $this->setData(ShipmentTrackInterface::CREATED_AT, $createdAt);
253  }
254 
260  public function getDescription()
261  {
263  }
264 
270  public function getOrderId()
271  {
273  }
274 
280  public function getParentId()
281  {
283  }
284 
290  public function getQty()
291  {
292  return $this->getData(ShipmentTrackInterface::QTY);
293  }
294 
300  public function getTitle()
301  {
302  return $this->getData(ShipmentTrackInterface::TITLE);
303  }
304 
310  public function getUpdatedAt()
311  {
313  }
314 
320  public function getWeight()
321  {
323  }
324 
328  public function setUpdatedAt($timestamp)
329  {
330  return $this->setData(ShipmentTrackInterface::UPDATED_AT, $timestamp);
331  }
332 
336  public function setParentId($id)
337  {
339  }
340 
344  public function setWeight($weight)
345  {
346  return $this->setData(ShipmentTrackInterface::WEIGHT, $weight);
347  }
348 
352  public function setQty($qty)
353  {
354  return $this->setData(ShipmentTrackInterface::QTY, $qty);
355  }
356 
360  public function setOrderId($id)
361  {
363  }
364 
368  public function setTrackNumber($trackNumber)
369  {
370  return $this->setData(ShipmentTrackInterface::TRACK_NUMBER, $trackNumber);
371  }
372 
376  public function setDescription($description)
377  {
379  }
380 
384  public function setTitle($title)
385  {
387  }
388 
392  public function setCarrierCode($code)
393  {
395  }
396 
402  public function getExtensionAttributes()
403  {
404  return $this->_getExtensionAttributes();
405  }
406 
413  public function setExtensionAttributes(\Magento\Sales\Api\Data\ShipmentTrackExtensionInterface $extensionAttributes)
414  {
415  return $this->_setExtensionAttributes($extensionAttributes);
416  }
417 
418  //@codeCoverageIgnoreEnd
419 }
$title
Definition: default.phtml:14
setExtensionAttributes(\Magento\Sales\Api\Data\ShipmentTrackExtensionInterface $extensionAttributes)
Definition: Track.php:413
$number
Definition: details.phtml:22
$id
Definition: fieldset.phtml:14
setShipment(\Magento\Sales\Model\Order\Shipment $shipment)
Definition: Track.php:130
_setExtensionAttributes(\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)
$storeManager
__()
Definition: __.php:13
$resource
Definition: bulk.php:12
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Sales\Api\ShipmentRepositoryInterface $shipmentRepository, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
Definition: Track.php:63
foreach($order->getItems() as $orderItem) $shipment
$code
Definition: info.phtml:12