Track.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Shipping\Model\Order;
  7. use Magento\Framework\Api\AttributeValueFactory;
  8. /**
  9. * @method int getParentId()
  10. * @method float getWeight()
  11. * @method float getQty()
  12. * @method int getOrderId()
  13. * @method string getDescription()
  14. * @method string getTitle()
  15. * @method string getCarrierCode()
  16. * @method string getCreatedAt()
  17. * @method string getUpdatedAt()
  18. * @method \Magento\Sales\Api\Data\ShipmentTrackExtensionInterface getExtensionAttributes()
  19. */
  20. class Track extends \Magento\Sales\Model\Order\Shipment\Track
  21. {
  22. /**
  23. * @var \Magento\Shipping\Model\CarrierFactory
  24. */
  25. protected $_carrierFactory;
  26. /**
  27. * @param \Magento\Framework\Model\Context $context
  28. * @param \Magento\Framework\Registry $registry
  29. * @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory
  30. * @param AttributeValueFactory $customAttributeFactory
  31. * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  32. * @param \Magento\Sales\Api\ShipmentRepositoryInterface $shipmentRepository
  33. * @param \Magento\Shipping\Model\CarrierFactory $carrierFactory
  34. * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
  35. * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
  36. * @param array $data
  37. *
  38. * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  39. */
  40. public function __construct(
  41. \Magento\Framework\Model\Context $context,
  42. \Magento\Framework\Registry $registry,
  43. \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
  44. AttributeValueFactory $customAttributeFactory,
  45. \Magento\Store\Model\StoreManagerInterface $storeManager,
  46. \Magento\Sales\Api\ShipmentRepositoryInterface $shipmentRepository,
  47. \Magento\Shipping\Model\CarrierFactory $carrierFactory,
  48. \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
  49. \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
  50. array $data = []
  51. ) {
  52. parent::__construct(
  53. $context,
  54. $registry,
  55. $extensionFactory,
  56. $customAttributeFactory,
  57. $storeManager,
  58. $shipmentRepository,
  59. $resource,
  60. $resourceCollection,
  61. $data
  62. );
  63. $this->_carrierFactory = $carrierFactory;
  64. }
  65. /**
  66. * Retrieve detail for shipment track
  67. *
  68. * @return \Magento\Framework\Phrase|string
  69. */
  70. public function getNumberDetail()
  71. {
  72. $carrierInstance = $this->_carrierFactory->create($this->getCarrierCode());
  73. if (!$carrierInstance) {
  74. $custom = [];
  75. $custom['title'] = $this->getTitle();
  76. $custom['number'] = $this->getTrackNumber();
  77. return $custom;
  78. } else {
  79. $carrierInstance->setStore($this->getStore());
  80. }
  81. $trackingInfo = $carrierInstance->getTrackingInfo($this->getNumber());
  82. if (!$trackingInfo) {
  83. return __('No detail for number "%1"', $this->getNumber());
  84. }
  85. return $trackingInfo;
  86. }
  87. }