Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Shipment Class Reference
Inheritance diagram for Shipment:
AbstractModel EntityInterface ShipmentInterface AbstractExtensibleModel ExtensibleDataInterface AbstractModel CustomAttributesDataInterface DataObject ExtensibleDataInterface

Public Member Functions

 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, \Magento\Sales\Model\ResourceModel\Order\Shipment\Item\CollectionFactory $shipmentItemCollectionFactory, \Magento\Sales\Model\ResourceModel\Order\Shipment\Track\CollectionFactory $trackCollectionFactory, \Magento\Sales\Model\Order\Shipment\CommentFactory $commentFactory, \Magento\Sales\Model\ResourceModel\Order\Shipment\Comment\CollectionFactory $commentCollectionFactory, \Magento\Sales\Api\OrderRepositoryInterface $orderRepository, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 loadByIncrementId ($incrementId)
 
 setOrder (\Magento\Sales\Model\Order $order)
 
 getProtectCode ()
 
 getOrder ()
 
 getEntityType ()
 
 getBillingAddress ()
 
 getShippingAddress ()
 
 getItemsCollection ()
 
 getAllItems ()
 
 getItemById ($itemId)
 
 addItem (\Magento\Sales\Model\Order\Shipment\Item $item)
 
 getTracksCollection ()
 
 getAllTracks ()
 
 getTrackById ($trackId)
 
 addTrack (\Magento\Sales\Model\Order\Shipment\Track $track)
 
 addComment ($comment, $notify=false, $visibleOnFront=false)
 
 getCommentsCollection ($reload=false)
 
 getStore ()
 
 setShippingLabel ($label)
 
 getShippingLabel ()
 
 getIncrementId ()
 
 getPackages ()
 
 setPackages (array $packages=null)
 
 getItems ()
 
 setItems ($items)
 
 getTracks ()
 
 setTracks ($tracks)
 
 getBillingAddressId ()
 
 getCreatedAt ()
 
 setCreatedAt ($createdAt)
 
 getCustomerId ()
 
 getEmailSent ()
 
 getOrderId ()
 
 getShipmentStatus ()
 
 getShippingAddressId ()
 
 getStoreId ()
 
 getTotalQty ()
 
 getTotalWeight ()
 
 getUpdatedAt ()
 
 getComments ()
 
 setComments ($comments=null)
 
 setStoreId ($id)
 
 setTotalWeight ($totalWeight)
 
 setTotalQty ($qty)
 
 setEmailSent ($emailSent)
 
 setOrderId ($id)
 
 setCustomerId ($id)
 
 setShippingAddressId ($id)
 
 setBillingAddressId ($id)
 
 setShipmentStatus ($shipmentStatus)
 
 setIncrementId ($id)
 
 setUpdatedAt ($timestamp)
 
 getExtensionAttributes ()
 
 setExtensionAttributes (\Magento\Sales\Api\Data\ShipmentExtensionInterface $extensionAttributes)
 
- Public Member Functions inherited from AbstractModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 getEventObject ()
 
- Public Member Functions inherited from AbstractExtensibleModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 getCustomAttributes ()
 
 getCustomAttribute ($attributeCode)
 
 setCustomAttributes (array $attributes)
 
 setCustomAttribute ($attributeCode, $attributeValue)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 setId ($value)
 
 __sleep ()
 
 __wakeup ()
 
- Public Member Functions inherited from AbstractModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 __sleep ()
 
 __wakeup ()
 
 setIdFieldName ($name)
 
 getIdFieldName ()
 
 getId ()
 
 setId ($value)
 
 isDeleted ($isDeleted=null)
 
 hasDataChanges ()
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 setDataChanges ($value)
 
 getOrigData ($key=null)
 
 setOrigData ($key=null, $data=null)
 
 dataHasChangedFor ($field)
 
 getResourceName ()
 
 getResourceCollection ()
 
 getCollection ()
 
 load ($modelId, $field=null)
 
 beforeLoad ($identifier, $field=null)
 
 afterLoad ()
 
 isSaveAllowed ()
 
 setHasDataChanges ($flag)
 
 save ()
 
 afterCommitCallback ()
 
 isObjectNew ($flag=null)
 
 beforeSave ()
 
 validateBeforeSave ()
 
 getCacheTags ()
 
 cleanModelCache ()
 
 afterSave ()
 
 delete ()
 
 beforeDelete ()
 
 afterDelete ()
 
 afterDeleteCommit ()
 
 getResource ()
 
 getEntityId ()
 
 setEntityId ($entityId)
 
 clearInstance ()
 
 getStoredData ()
 
 getEventPrefix ()
 
- 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)
 
- Public Member Functions inherited from ShipmentInterface
 getEntityId ()
 
 setEntityId ($entityId)
 
 setExtensionAttributes (\Magento\Sales\Api\Data\ShipmentExtensionInterface $extensionAttributes)
 

Data Fields

const STATUS_NEW = 1
 
const REPORT_DATE_TYPE_ORDER_CREATED = 'order_created'
 
const REPORT_DATE_TYPE_SHIPMENT_CREATED = 'shipment_created'
 
const XML_PATH_STORE_ADDRESS1 = 'shipping/origin/street_line1'
 
const XML_PATH_STORE_ADDRESS2 = 'shipping/origin/street_line2'
 
const XML_PATH_STORE_CITY = 'shipping/origin/city'
 
const XML_PATH_STORE_REGION_ID = 'shipping/origin/region_id'
 
const XML_PATH_STORE_ZIP = 'shipping/origin/postcode'
 
const XML_PATH_STORE_COUNTRY_ID = 'shipping/origin/country_id'
 
- Data Fields inherited from CustomAttributesDataInterface
const CUSTOM_ATTRIBUTES = 'custom_attributes'
 
- Data Fields inherited from ExtensibleDataInterface
const EXTENSION_ATTRIBUTES_KEY = 'extension_attributes'
 
- Data Fields inherited from ShipmentInterface
const ENTITY_ID = 'entity_id'
 
const STORE_ID = 'store_id'
 
const TOTAL_WEIGHT = 'total_weight'
 
const TOTAL_QTY = 'total_qty'
 
const EMAIL_SENT = 'email_sent'
 
const ORDER_ID = 'order_id'
 
const CUSTOMER_ID = 'customer_id'
 
const SHIPPING_ADDRESS_ID = 'shipping_address_id'
 
const BILLING_ADDRESS_ID = 'billing_address_id'
 
const SHIPMENT_STATUS = 'shipment_status'
 
const INCREMENT_ID = 'increment_id'
 
const CREATED_AT = 'created_at'
 
const UPDATED_AT = 'updated_at'
 
const PACKAGES = 'packages'
 
const SHIPPING_LABEL = 'shipping_label'
 
const ITEMS = 'items'
 
const TRACKS = 'tracks'
 
const COMMENTS = 'comments'
 

Protected Member Functions

 _construct ()
 
- Protected Member Functions inherited from AbstractExtensibleModel
 filterCustomAttributes ($data)
 
 initializeCustomAttributes ()
 
 convertCustomAttributeValues (array &$customAttributes)
 
 getCustomAttributesCodes ()
 
 _setExtensionAttributes (\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)
 
 _getExtensionAttributes ()
 
- Protected Member Functions inherited from AbstractModel
 _construct ()
 
 _init ($resourceModel)
 
 _setResourceModel ($resourceName, $collectionName=null)
 
 _getResource ()
 
 _getEventData ()
 
 _beforeLoad ($modelId, $field=null)
 
 _afterLoad ()
 
 _hasModelChanged ()
 
 _getValidatorBeforeSave ()
 
 _createValidatorBeforeSave ()
 
 _getValidationRulesBeforeSave ()
 
 _clearReferences ()
 
 _clearData ()
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $entityType = 'shipment'
 
 $_order
 
 $_eventPrefix = 'sales_order_shipment'
 
 $_eventObject = 'shipment'
 
 $_shipmentItemCollectionFactory
 
 $_trackCollectionFactory
 
 $_commentFactory
 
 $_commentCollectionFactory
 
 $orderRepository
 
- Protected Attributes inherited from AbstractExtensibleModel
 $extensionAttributesFactory
 
 $extensionAttributes
 
 $customAttributeFactory
 
 $customAttributesCodes = null
 
 $customAttributesChanged = false
 
- Protected Attributes inherited from AbstractModel
 $_eventPrefix = 'core_abstract'
 
 $_eventObject = 'object'
 
 $_idFieldName = 'id'
 
 $_hasDataChanges = false
 
 $_origData
 
 $_isDeleted = false
 
 $_resource
 
 $_resourceCollection
 
 $_resourceName
 
 $_collectionName
 
 $_cacheTag = false
 
 $_dataSaveAllowed = true
 
 $_isObjectNew = null
 
 $_validatorBeforeSave = null
 
 $_eventManager
 
 $_cacheManager
 
 $_registry
 
 $_logger
 
 $_appState
 
 $_actionValidator
 
 $storedData = []
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

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

Detailed Description

Sales order shipment model

@api @method \Magento\Sales\Model\Order\Invoice setSendEmail(bool $value) @method \Magento\Sales\Model\Order\Invoice setCustomerNote(string $value) @method string getCustomerNote() @method \Magento\Sales\Model\Order\Invoice setCustomerNoteNotify(bool $value) @method bool getCustomerNoteNotify() @SuppressWarnings(PHPMD.CouplingBetweenObjects) @SuppressWarnings(PHPMD.ExcessivePublicCount)

Since
100.0.2

Definition at line 27 of file Shipment.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\Model\Context  $context,
\Magento\Framework\Registry  $registry,
\Magento\Framework\Api\ExtensionAttributesFactory  $extensionFactory,
AttributeValueFactory  $customAttributeFactory,
\Magento\Sales\Model\ResourceModel\Order\Shipment\Item\CollectionFactory  $shipmentItemCollectionFactory,
\Magento\Sales\Model\ResourceModel\Order\Shipment\Track\CollectionFactory  $trackCollectionFactory,
\Magento\Sales\Model\Order\Shipment\CommentFactory  $commentFactory,
\Magento\Sales\Model\ResourceModel\Order\Shipment\Comment\CollectionFactory  $commentCollectionFactory,
\Magento\Sales\Api\OrderRepositoryInterface  $orderRepository,
\Magento\Framework\Model\ResourceModel\AbstractResource  $resource = null,
\Magento\Framework\Data\Collection\AbstractDb  $resourceCollection = null,
array  $data = [] 
)
Parameters
\Magento\Framework\Model\Context$context
\Magento\Framework\Registry$registry
\Magento\Framework\Api\ExtensionAttributesFactory$extensionFactory
AttributeValueFactory$customAttributeFactory
\Magento\Sales\Model\ResourceModel\Order\Shipment\Item\CollectionFactory$shipmentItemCollectionFactory
\Magento\Sales\Model\ResourceModel\Order\Shipment\Track\CollectionFactory$trackCollectionFactory
Shipment\CommentFactory$commentFactory
\Magento\Sales\Model\ResourceModel\Order\Shipment\Comment\CollectionFactory$commentCollectionFactory
\Magento\Sales\Api\OrderRepositoryInterface$orderRepository
\Magento\Framework\Model\ResourceModel\AbstractResource$resource
\Magento\Framework\Data\Collection\AbstractDb$resourceCollection
array$data@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 122 of file Shipment.php.

135  {
136  $this->_shipmentItemCollectionFactory = $shipmentItemCollectionFactory;
137  $this->_trackCollectionFactory = $trackCollectionFactory;
138  $this->_commentFactory = $commentFactory;
139  $this->_commentCollectionFactory = $commentCollectionFactory;
140  $this->orderRepository = $orderRepository;
141  parent::__construct(
142  $context,
143  $registry,
144  $extensionFactory,
146  $resource,
147  $resourceCollection,
148  $data
149  );
150  }
$resource
Definition: bulk.php:12

Member Function Documentation

◆ _construct()

_construct ( )
protected

Initialize shipment resource model

Returns
void

Definition at line 157 of file Shipment.php.

158  {
159  $this->_init(\Magento\Sales\Model\ResourceModel\Order\Shipment::class);
160  }

◆ addComment()

addComment (   $comment,
  $notify = false,
  $visibleOnFront = false 
)

Adds comment to shipment with option to send it to customer via email and show it in customer account

Parameters
\Magento\Sales\Model\Order\Shipment\Comment | string$comment
bool$notify
bool$visibleOnFront
Returns
$this

Definition at line 433 of file Shipment.php.

434  {
435  if (!$comment instanceof \Magento\Sales\Model\Order\Shipment\Comment) {
436  $comment = $this->_commentFactory->create()
437  ->setComment($comment)
438  ->setIsCustomerNotified($notify)
439  ->setIsVisibleOnFront($visibleOnFront);
440  }
441  $comment->setShipment($this)
442  ->setParentId($this->getId())
443  ->setStoreId($this->getStoreId());
444  if (!$comment->getId()) {
445  $this->getCommentsCollection()->addItem($comment);
446  }
447  $comments = $this->getComments();
448  $comments[] = $comment;
449  $this->setComments($comments);
450  $this->_hasDataChanges = true;
451  return $this;
452  }
getCommentsCollection($reload=false)
Definition: Shipment.php:460

◆ addItem()

Adds an item to the shipment

Parameters
\Magento\Sales\Model\Order\Shipment\Item$item
Returns
$this

Definition at line 337 of file Shipment.php.

338  {
339  $item->setShipment($this)->setParentId($this->getId())->setStoreId($this->getStoreId());
340  if (!$item->getId()) {
341  $this->setItems(array_merge(
342  $this->getItems() ?? [],
343  [$item]
344  ));
345  }
346  return $this;
347  }

◆ addTrack()

Addes a track to the collection and associates the shipment to the track

Parameters
\Magento\Sales\Model\Order\Shipment\Track$track
Returns
$this

Track saving is implemented in _afterSave() This enforces \Magento\Framework\Model\AbstractModel::save() not to skip _afterSave()

Definition at line 401 of file Shipment.php.

402  {
403  $track->setShipment(
404  $this
405  )->setParentId(
406  $this->getId()
407  )->setOrderId(
408  $this->getOrderId()
409  )->setStoreId(
410  $this->getStoreId()
411  );
412  if (!$track->getId()) {
413  $this->getTracksCollection()->addItem($track);
414  }
415 
420  $this->_hasDataChanges = true;
421 
422  return $this;
423  }
$track
Definition: details.phtml:12

◆ getAllItems()

getAllItems ( )

Retrieves all non-deleted items from the shipment

Returns
array

Definition at line 304 of file Shipment.php.

305  {
306  $items = [];
307  foreach ($this->getItemsCollection() as $item) {
308  if (!$item->isDeleted()) {
309  $items[] = $item;
310  }
311  }
312  return $items;
313  }
$items

◆ getAllTracks()

getAllTracks ( )

Retrieves all available tracks in the collection that aren't deleted

Returns
array

Definition at line 368 of file Shipment.php.

369  {
370  $tracks = [];
371  foreach ($this->getTracksCollection() as $track) {
372  if (!$track->isDeleted()) {
373  $tracks[] = $track;
374  }
375  }
376  return $tracks;
377  }
$track
Definition: details.phtml:12

◆ getBillingAddress()

getBillingAddress ( )

Retrieve billing address

Returns
Address

Definition at line 232 of file Shipment.php.

233  {
234  return $this->getOrder()->getBillingAddress();
235  }

◆ getBillingAddressId()

getBillingAddressId ( )

Returns billing_address_id

Returns
int

Implements ShipmentInterface.

Definition at line 616 of file Shipment.php.

◆ getComments()

getComments ( )

Returns comments

Returns
\Magento\Sales\Api\Data\ShipmentCommentInterface[]

Implements ShipmentInterface.

Definition at line 734 of file Shipment.php.

735  {
736  if (!$this->getId()) {
737  return $this->getData(ShipmentInterface::COMMENTS);
738  }
739 
740  if ($this->getData(ShipmentInterface::COMMENTS) == null) {
741  $collection = $this->_commentCollectionFactory->create()
742  ->setShipmentFilter($this->getId());
743 
744  foreach ($collection as $item) {
745  $item->setShipment($this);
746  }
747  $this->setData(ShipmentInterface::COMMENTS, $collection->getItems());
748  }
749  return $this->getData(ShipmentInterface::COMMENTS);
750  }

◆ getCommentsCollection()

getCommentsCollection (   $reload = false)

Retrieves comments collection.

Parameters
bool$reload
Returns
CommentsCollection

Definition at line 460 of file Shipment.php.

461  {
462  if ($this->commentsCollection === null || $reload) {
463  $this->commentsCollection = $this->_commentCollectionFactory->create();
464  if ($this->getId()) {
465  $this->commentsCollection->setShipmentFilter($this->getId())
466  ->setCreatedAtOrder();
467 
468  foreach ($this->commentsCollection as $comment) {
469  $comment->setShipment($this);
470  }
471  }
472  }
473 
474  return $this->commentsCollection;
475  }

◆ getCreatedAt()

getCreatedAt ( )

Returns created_at

Returns
string

Implements ShipmentInterface.

Definition at line 626 of file Shipment.php.

◆ getCustomerId()

getCustomerId ( )

Returns customer_id

Returns
int

Implements ShipmentInterface.

Definition at line 644 of file Shipment.php.

◆ getEmailSent()

getEmailSent ( )

Returns email_sent

Returns
int

Implements ShipmentInterface.

Definition at line 654 of file Shipment.php.

◆ getEntityType()

getEntityType ( )

Return order history item identifier

@codeCoverageIgnore

Returns
string

Definition at line 222 of file Shipment.php.

223  {
224  return $this->entityType;
225  }

◆ getExtensionAttributes()

getExtensionAttributes ( )

Retrieve existing extension attributes object or create a new one.

Returns
\Magento\Sales\Api\Data\ShipmentExtensionInterface|null

Returns
\Magento\Sales\Api\Data\ShipmentExtensionInterface|null

Implements ShipmentInterface.

Definition at line 856 of file Shipment.php.

◆ getIncrementId()

getIncrementId ( )

Returns increment id

@codeCoverageIgnore

Returns
string

Implements ShipmentInterface.

Definition at line 520 of file Shipment.php.

521  {
522  return $this->getData('increment_id');
523  }

◆ getItemById()

getItemById (   $itemId)

Retrieves an item from the shipment using its ID

Parameters
string | int$itemId
Returns
bool|\Magento\Sales\Model\Order\Shipment\Item

Definition at line 321 of file Shipment.php.

322  {
323  foreach ($this->getItemsCollection() as $item) {
324  if ($item->getId() == $itemId) {
325  return $item;
326  }
327  }
328  return false;
329  }

◆ getItems()

getItems ( )

Returns items

Returns
\Magento\Sales\Api\Data\ShipmentItemInterface[]

Implements ShipmentInterface.

Definition at line 551 of file Shipment.php.

552  {
553  if ($this->getData(ShipmentInterface::ITEMS) === null) {
554  $collection = $this->_shipmentItemCollectionFactory->create()->setShipmentFilter($this->getId());
555  if ($this->getId()) {
556  foreach ($collection as $item) {
557  $item->setShipment($this);
558  }
559  $this->setData(ShipmentInterface::ITEMS, $collection->getItems());
560  }
561  }
562  $shipmentItems = $this->getData(ShipmentInterface::ITEMS);
563  if ($shipmentItems !== null && !is_array($shipmentItems)) {
564  $shipmentItems = $shipmentItems->getItems();
565  }
566  return $shipmentItems;
567  }

◆ getItemsCollection()

getItemsCollection ( )

Retrieves the collection used to track the shipment's items

Returns
mixed

Definition at line 284 of file Shipment.php.

285  {
286  if (!$this->hasData(ShipmentInterface::ITEMS)) {
287  $this->setItems($this->_shipmentItemCollectionFactory->create()->setShipmentFilter($this->getId()));
288 
289  if ($this->getId()) {
290  foreach ($this->getItems() as $item) {
291  $item->setShipment($this);
292  }
293  }
294  }
295 
296  return $this->getItems();
297  }

◆ getOrder()

getOrder ( )

Retrieve the order the shipment for created for

Returns
\Magento\Sales\Model\Order

Definition at line 207 of file Shipment.php.

208  {
209  if (!$this->_order instanceof \Magento\Sales\Model\Order) {
210  $this->_order = $this->orderRepository->get($this->getOrderId());
211  }
212  return $this->_order->setHistoryEntityName($this->entityType);
213  }

◆ getOrderId()

getOrderId ( )

Returns order_id

Returns
int

Implements ShipmentInterface.

Definition at line 664 of file Shipment.php.

◆ getPackages()

getPackages ( )

Returns packages

@codeCoverageIgnore

Returns
string

Implements ShipmentInterface.

Definition at line 532 of file Shipment.php.

◆ getProtectCode()

getProtectCode ( )

Retrieve hash code of current order

Returns
string

Definition at line 197 of file Shipment.php.

198  {
199  return (string)$this->getOrder()->getProtectCode();
200  }

◆ getShipmentStatus()

getShipmentStatus ( )

Returns shipment_status

Returns
int

Implements ShipmentInterface.

Definition at line 674 of file Shipment.php.

◆ getShippingAddress()

getShippingAddress ( )

Retrieve shipping address

Returns
Address

Definition at line 242 of file Shipment.php.

243  {
244  return $this->getOrder()->getShippingAddress();
245  }

◆ getShippingAddressId()

getShippingAddressId ( )

Returns shipping_address_id

Returns
int

Implements ShipmentInterface.

Definition at line 684 of file Shipment.php.

◆ getShippingLabel()

getShippingLabel ( )

Get shipping label and decode by db adapter

Returns
mixed

Implements ShipmentInterface.

Definition at line 504 of file Shipment.php.

505  {
506  $label = $this->getData('shipping_label');
507  if ($label) {
508  return $this->getResource()->getConnection()->decodeVarbinary($label);
509  }
510  return $label;
511  }
$label
Definition: details.phtml:21

◆ getStore()

getStore ( )

Retrieve store model instance

Returns
\Magento\Store\Model\Store

Definition at line 482 of file Shipment.php.

483  {
484  return $this->getOrder()->getStore();
485  }

◆ getStoreId()

getStoreId ( )

Returns store_id

Returns
int

Implements ShipmentInterface.

Definition at line 694 of file Shipment.php.

◆ getTotalQty()

getTotalQty ( )

Returns total_qty

Returns
float

Implements ShipmentInterface.

Definition at line 704 of file Shipment.php.

◆ getTotalWeight()

getTotalWeight ( )

Returns total_weight

Returns
float

Implements ShipmentInterface.

Definition at line 714 of file Shipment.php.

◆ getTrackById()

getTrackById (   $trackId)

Retrieves a track using its ID

Parameters
string | int$trackId
Returns
bool|\Magento\Sales\Model\Order\Shipment\Track

Definition at line 385 of file Shipment.php.

386  {
387  foreach ($this->getTracksCollection() as $track) {
388  if ($track->getId() == $trackId) {
389  return $track;
390  }
391  }
392  return false;
393  }
$track
Definition: details.phtml:12

◆ getTracks()

getTracks ( )

Returns tracks

Returns
\Magento\Sales\Api\Data\ShipmentTrackInterface[]

Implements ShipmentInterface.

Definition at line 587 of file Shipment.php.

◆ getTracksCollection()

getTracksCollection ( )

Retrieve tracks collection.

Returns
\Magento\Sales\Model\ResourceModel\Order\Shipment\Track\Collection

Definition at line 354 of file Shipment.php.

355  {
356  if ($this->tracksCollection === null) {
357  $this->tracksCollection = $this->_trackCollectionFactory->create()->setShipmentFilter($this->getId());
358  }
359 
360  return $this->tracksCollection;
361  }

◆ getUpdatedAt()

getUpdatedAt ( )

Returns updated_at

Returns
string

Implements ShipmentInterface.

Definition at line 724 of file Shipment.php.

◆ loadByIncrementId()

loadByIncrementId (   $incrementId)

Load shipment by increment id

Parameters
string$incrementId
Returns
$this

Definition at line 168 of file Shipment.php.

169  {
170  $ids = $this->getCollection()->addAttributeToFilter('increment_id', $incrementId)->getAllIds();
171 
172  if (!empty($ids)) {
173  reset($ids);
174  $this->load(current($ids));
175  }
176  return $this;
177  }

◆ setBillingAddressId()

setBillingAddressId (   $id)

Sets the billing address ID for the shipment.

Parameters
int$id
Returns
$this

Implements ShipmentInterface.

Definition at line 822 of file Shipment.php.

◆ setComments()

setComments (   $comments = null)

Sets comments

Parameters

Implements ShipmentInterface.

Definition at line 758 of file Shipment.php.

◆ setCreatedAt()

setCreatedAt (   $createdAt)

Sets the created-at timestamp for the shipment.

Parameters
string$createdAttimestamp
Returns
$this

Implements ShipmentInterface.

Definition at line 634 of file Shipment.php.

◆ setCustomerId()

setCustomerId (   $id)

Sets the customer ID for the shipment.

Parameters
int$id
Returns
$this

Implements ShipmentInterface.

Definition at line 806 of file Shipment.php.

◆ setEmailSent()

setEmailSent (   $emailSent)

Sets the email-sent flag value for the shipment.

Parameters
int$emailSent
Returns
$this

Implements ShipmentInterface.

Definition at line 790 of file Shipment.php.

◆ setExtensionAttributes()

setExtensionAttributes ( \Magento\Sales\Api\Data\ShipmentExtensionInterface  $extensionAttributes)
Parameters
\Magento\Sales\Api\Data\ShipmentExtensionInterface$extensionAttributes
Returns
$this

Definition at line 867 of file Shipment.php.

868  {
870  }
_setExtensionAttributes(\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)

◆ setIncrementId()

setIncrementId (   $id)

Sets the increment ID for the shipment.

Parameters
string$id
Returns
$this

Implements ShipmentInterface.

Definition at line 838 of file Shipment.php.

◆ setItems()

setItems (   $items)

Sets items

@codeCoverageIgnore

Parameters
mixed$items
Returns
$this

Implements ShipmentInterface.

Definition at line 577 of file Shipment.php.

◆ setOrder()

setOrder ( \Magento\Sales\Model\Order  $order)

Declare order for shipment

Parameters
\Magento\Sales\Model\Order$order
Returns
$this

Definition at line 185 of file Shipment.php.

186  {
187  $this->_order = $order;
188  $this->setOrderId($order->getId())->setStoreId($order->getStoreId());
189  return $this;
190  }
$order
Definition: order.php:55

◆ setOrderId()

setOrderId (   $id)

Sets the order ID for the shipment.

Parameters
int$id
Returns
$this

Implements ShipmentInterface.

Definition at line 798 of file Shipment.php.

◆ setPackages()

setPackages ( array  $packages = null)

Sets any packages for the shipment.

Parameters
@codeCoverageIgnore

Implements ShipmentInterface.

Definition at line 541 of file Shipment.php.

◆ setShipmentStatus()

setShipmentStatus (   $shipmentStatus)

Sets the shipment status.

Parameters
int$shipmentStatus
Returns
$this

Implements ShipmentInterface.

Definition at line 830 of file Shipment.php.

◆ setShippingAddressId()

setShippingAddressId (   $id)

Sets the shipping address ID for the shipment.

Parameters
int$id
Returns
$this

Implements ShipmentInterface.

Definition at line 814 of file Shipment.php.

◆ setShippingLabel()

setShippingLabel (   $label)

Set shipping label

Parameters
string$labellabel representation (image or pdf file)
Returns
$this

Implements ShipmentInterface.

Definition at line 493 of file Shipment.php.

494  {
495  $this->setData('shipping_label', $label);
496  return $this;
497  }
$label
Definition: details.phtml:21

◆ setStoreId()

setStoreId (   $id)

Sets the store ID for the shipment.

Parameters
int$id
Returns
$this

Implements ShipmentInterface.

Definition at line 766 of file Shipment.php.

◆ setTotalQty()

setTotalQty (   $qty)

Sets the total quantity for the shipment.

Parameters
float$qty
Returns
$this

Implements ShipmentInterface.

Definition at line 782 of file Shipment.php.

◆ setTotalWeight()

setTotalWeight (   $totalWeight)

Sets the total weight for the shipment.

Parameters
float$totalWeight
Returns
$this

Implements ShipmentInterface.

Definition at line 774 of file Shipment.php.

◆ setTracks()

setTracks (   $tracks)

Returns tracks

Parameters

Implements ShipmentInterface.

Definition at line 606 of file Shipment.php.

◆ setUpdatedAt()

setUpdatedAt (   $timestamp)

Sets the updated-at timestamp for the shipment.

Parameters
string$timestamp
Returns
$this

Implements ShipmentInterface.

Definition at line 846 of file Shipment.php.

Field Documentation

◆ $_commentCollectionFactory

$_commentCollectionFactory
protected

Definition at line 90 of file Shipment.php.

◆ $_commentFactory

$_commentFactory
protected

Definition at line 85 of file Shipment.php.

◆ $_eventObject

$_eventObject = 'shipment'
protected

Definition at line 70 of file Shipment.php.

◆ $_eventPrefix

$_eventPrefix = 'sales_order_shipment'
protected

Definition at line 65 of file Shipment.php.

◆ $_order

$_order
protected

Definition at line 60 of file Shipment.php.

◆ $_shipmentItemCollectionFactory

$_shipmentItemCollectionFactory
protected

Definition at line 75 of file Shipment.php.

◆ $_trackCollectionFactory

$_trackCollectionFactory
protected

Definition at line 80 of file Shipment.php.

◆ $entityType

$entityType = 'shipment'
protected

Definition at line 55 of file Shipment.php.

◆ $orderRepository

$orderRepository
protected

Definition at line 95 of file Shipment.php.

◆ REPORT_DATE_TYPE_ORDER_CREATED

const REPORT_DATE_TYPE_ORDER_CREATED = 'order_created'

Definition at line 31 of file Shipment.php.

◆ REPORT_DATE_TYPE_SHIPMENT_CREATED

const REPORT_DATE_TYPE_SHIPMENT_CREATED = 'shipment_created'

Definition at line 33 of file Shipment.php.

◆ STATUS_NEW

const STATUS_NEW = 1

Definition at line 29 of file Shipment.php.

◆ XML_PATH_STORE_ADDRESS1

const XML_PATH_STORE_ADDRESS1 = 'shipping/origin/street_line1'

Store address

Definition at line 38 of file Shipment.php.

◆ XML_PATH_STORE_ADDRESS2

const XML_PATH_STORE_ADDRESS2 = 'shipping/origin/street_line2'

Definition at line 40 of file Shipment.php.

◆ XML_PATH_STORE_CITY

const XML_PATH_STORE_CITY = 'shipping/origin/city'

Definition at line 42 of file Shipment.php.

◆ XML_PATH_STORE_COUNTRY_ID

const XML_PATH_STORE_COUNTRY_ID = 'shipping/origin/country_id'

Definition at line 48 of file Shipment.php.

◆ XML_PATH_STORE_REGION_ID

const XML_PATH_STORE_REGION_ID = 'shipping/origin/region_id'

Definition at line 44 of file Shipment.php.

◆ XML_PATH_STORE_ZIP

const XML_PATH_STORE_ZIP = 'shipping/origin/postcode'

Definition at line 46 of file Shipment.php.


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