123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Sales\Model\Order\Shipment;
- use Magento\Framework\Api\AttributeValueFactory;
- use Magento\Framework\Exception\LocalizedException;
- use Magento\Sales\Api\Data\ShipmentTrackInterface;
- use Magento\Sales\Model\AbstractModel;
- /**
- * @api
- * @author Magento Core Team <core@magentocommerce.com>
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @since 100.0.2
- */
- class Track extends AbstractModel implements ShipmentTrackInterface
- {
- /**
- * Code of custom carrier
- */
- const CUSTOM_CARRIER_CODE = 'custom';
- /**
- * @var \Magento\Sales\Model\Order\Shipment|null
- */
- protected $_shipment = null;
- /**
- * @var string
- */
- protected $_eventPrefix = 'sales_order_shipment_track';
- /**
- * @var string
- */
- protected $_eventObject = 'track';
- /**
- * @var \Magento\Store\Model\StoreManagerInterface
- */
- protected $_storeManager;
- /**
- * @var \Magento\Sales\Api\ShipmentRepositoryInterface
- */
- protected $shipmentRepository;
- /**
- * @param \Magento\Framework\Model\Context $context
- * @param \Magento\Framework\Registry $registry
- * @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory
- * @param AttributeValueFactory $customAttributeFactory
- * @param \Magento\Store\Model\StoreManagerInterface $storeManager
- * @param \Magento\Sales\Api\ShipmentRepositoryInterface $shipmentRepository
- * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
- * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
- * @param array $data
- * @SuppressWarnings(PHPMD.ExcessiveParameterList)
- */
- public function __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 = []
- ) {
- parent::__construct(
- $context,
- $registry,
- $extensionFactory,
- $customAttributeFactory,
- $resource,
- $resourceCollection,
- $data
- );
- $this->_storeManager = $storeManager;
- $this->shipmentRepository = $shipmentRepository;
- }
- /**
- * Initialize resource model
- *
- * @return void
- */
- protected function _construct()
- {
- $this->_init(\Magento\Sales\Model\ResourceModel\Order\Shipment\Track::class);
- }
- /**
- * Tracking number getter
- *
- * @codeCoverageIgnore
- *
- * @return string
- */
- public function getNumber()
- {
- return $this->getData('track_number');
- }
- /**
- * Tracking number setter
- *
- * @codeCoverageIgnore
- *
- * @param string $number
- * @return \Magento\Framework\DataObject
- */
- public function setNumber($number)
- {
- return $this->setData('track_number', $number);
- }
- /**
- * Declare Shipment instance
- *
- * @codeCoverageIgnore
- *
- * @param \Magento\Sales\Model\Order\Shipment $shipment
- * @return $this
- */
- public function setShipment(\Magento\Sales\Model\Order\Shipment $shipment)
- {
- $this->_shipment = $shipment;
- return $this;
- }
- /**
- * Retrieve Shipment instance
- *
- * @return \Magento\Sales\Model\Order\Shipment
- * @throws \Magento\Framework\Exception\LocalizedException
- */
- public function getShipment()
- {
- if (!$this->_shipment instanceof \Magento\Sales\Model\Order\Shipment) {
- if ($this->getParentId()) {
- $this->_shipment = $this->shipmentRepository->get($this->getParentId());
- } else {
- throw new LocalizedException(__("Parent shipment cannot be loaded for track object."));
- }
- }
- return $this->_shipment;
- }
- /**
- * Check whether custom carrier was used for this track
- *
- * @return bool
- */
- public function isCustom()
- {
- return $this->getCarrierCode() == self::CUSTOM_CARRIER_CODE;
- }
- /**
- * Retrieve hash code of current order
- *
- * @return string
- */
- public function getProtectCode()
- {
- return (string)$this->getShipment()->getProtectCode();
- }
- /**
- * Get store object
- *
- * @return \Magento\Store\Model\Store
- */
- public function getStore()
- {
- if ($this->getShipment()) {
- return $this->getShipment()->getStore();
- }
- return $this->_storeManager->getStore();
- }
- /**
- * Get store id
- *
- * @return int
- */
- public function getStoreId()
- {
- return $this->getStore()->getId();
- }
- /**
- * Add data to the object.
- *
- * Retains previous data in the object.
- *
- * @param array $data
- * @return $this
- */
- public function addData(array $data)
- {
- if (array_key_exists('number', $data)) {
- $this->setNumber($data['number']);
- unset($data['number']);
- }
- return parent::addData($data);
- }
- //@codeCoverageIgnoreStart
- /**
- * Returns track_number
- *
- * @return string
- */
- public function getTrackNumber()
- {
- return $this->getData(ShipmentTrackInterface::TRACK_NUMBER);
- }
- /**
- * Returns carrier_code
- *
- * @return string
- */
- public function getCarrierCode()
- {
- return $this->getData(ShipmentTrackInterface::CARRIER_CODE);
- }
- /**
- * Returns created_at
- *
- * @return string
- */
- public function getCreatedAt()
- {
- return $this->getData(ShipmentTrackInterface::CREATED_AT);
- }
- /**
- * {@inheritdoc}
- */
- public function setCreatedAt($createdAt)
- {
- return $this->setData(ShipmentTrackInterface::CREATED_AT, $createdAt);
- }
- /**
- * Returns description
- *
- * @return string
- */
- public function getDescription()
- {
- return $this->getData(ShipmentTrackInterface::DESCRIPTION);
- }
- /**
- * Returns order_id
- *
- * @return int
- */
- public function getOrderId()
- {
- return $this->getData(ShipmentTrackInterface::ORDER_ID);
- }
- /**
- * Returns parent_id
- *
- * @return int
- */
- public function getParentId()
- {
- return $this->getData(ShipmentTrackInterface::PARENT_ID);
- }
- /**
- * Returns qty
- *
- * @return float
- */
- public function getQty()
- {
- return $this->getData(ShipmentTrackInterface::QTY);
- }
- /**
- * Returns title
- *
- * @return string
- */
- public function getTitle()
- {
- return $this->getData(ShipmentTrackInterface::TITLE);
- }
- /**
- * Returns updated_at
- *
- * @return string
- */
- public function getUpdatedAt()
- {
- return $this->getData(ShipmentTrackInterface::UPDATED_AT);
- }
- /**
- * Returns weight
- *
- * @return float
- */
- public function getWeight()
- {
- return $this->getData(ShipmentTrackInterface::WEIGHT);
- }
- /**
- * {@inheritdoc}
- */
- public function setUpdatedAt($timestamp)
- {
- return $this->setData(ShipmentTrackInterface::UPDATED_AT, $timestamp);
- }
- /**
- * {@inheritdoc}
- */
- public function setParentId($id)
- {
- return $this->setData(ShipmentTrackInterface::PARENT_ID, $id);
- }
- /**
- * {@inheritdoc}
- */
- public function setWeight($weight)
- {
- return $this->setData(ShipmentTrackInterface::WEIGHT, $weight);
- }
- /**
- * {@inheritdoc}
- */
- public function setQty($qty)
- {
- return $this->setData(ShipmentTrackInterface::QTY, $qty);
- }
- /**
- * {@inheritdoc}
- */
- public function setOrderId($id)
- {
- return $this->setData(ShipmentTrackInterface::ORDER_ID, $id);
- }
- /**
- * {@inheritdoc}
- */
- public function setTrackNumber($trackNumber)
- {
- return $this->setData(ShipmentTrackInterface::TRACK_NUMBER, $trackNumber);
- }
- /**
- * {@inheritdoc}
- */
- public function setDescription($description)
- {
- return $this->setData(ShipmentTrackInterface::DESCRIPTION, $description);
- }
- /**
- * {@inheritdoc}
- */
- public function setTitle($title)
- {
- return $this->setData(ShipmentTrackInterface::TITLE, $title);
- }
- /**
- * {@inheritdoc}
- */
- public function setCarrierCode($code)
- {
- return $this->setData(ShipmentTrackInterface::CARRIER_CODE, $code);
- }
- /**
- * {@inheritdoc}
- *
- * @return \Magento\Sales\Api\Data\ShipmentTrackExtensionInterface|null
- */
- public function getExtensionAttributes()
- {
- return $this->_getExtensionAttributes();
- }
- /**
- * {@inheritdoc}
- *
- * @param \Magento\Sales\Api\Data\ShipmentTrackExtensionInterface $extensionAttributes
- * @return $this
- */
- public function setExtensionAttributes(\Magento\Sales\Api\Data\ShipmentTrackExtensionInterface $extensionAttributes)
- {
- return $this->_setExtensionAttributes($extensionAttributes);
- }
- //@codeCoverageIgnoreEnd
- }
|