100 private $tracksCollection;
105 private $commentsCollection;
125 \
Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
136 $this->_shipmentItemCollectionFactory = $shipmentItemCollectionFactory;
137 $this->_trackCollectionFactory = $trackCollectionFactory;
138 $this->_commentFactory = $commentFactory;
139 $this->_commentCollectionFactory = $commentCollectionFactory;
170 $ids = $this->
getCollection()->addAttributeToFilter(
'increment_id', $incrementId)->getAllIds();
174 $this->
load(current($ids));
199 return (
string)$this->
getOrder()->getProtectCode();
209 if (!$this->_order instanceof \
Magento\Sales\Model\
Order) {
210 $this->_order = $this->orderRepository->get($this->
getOrderId());
212 return $this->_order->setHistoryEntityName($this->entityType);
234 return $this->
getOrder()->getBillingAddress();
244 return $this->
getOrder()->getShippingAddress();
253 public function register()
255 if ($this->
getId()) {
256 throw new \Magento\Framework\Exception\LocalizedException(
257 __(
'We cannot register an existing shipment')
265 if (
$item->getQty() > 0) {
268 if (!
$item->getOrderItem()->isDummy(
true)) {
269 $totalQty +=
$item->getQty();
287 $this->
setItems($this->_shipmentItemCollectionFactory->create()->setShipmentFilter($this->
getId()));
289 if ($this->
getId()) {
291 $item->setShipment($this);
308 if (!
$item->isDeleted()) {
324 if (
$item->getId() == $itemId) {
340 if (!$item->getId()) {
356 if ($this->tracksCollection ===
null) {
357 $this->tracksCollection = $this->_trackCollectionFactory->create()->setShipmentFilter($this->
getId());
360 return $this->tracksCollection;
372 if (!
$track->isDeleted()) {
388 if (
$track->getId() == $trackId) {
412 if (!$track->getId()) {
420 $this->_hasDataChanges =
true;
433 public function addComment($comment, $notify =
false, $visibleOnFront =
false)
436 $comment = $this->_commentFactory->create()
437 ->setComment($comment)
438 ->setIsCustomerNotified($notify)
439 ->setIsVisibleOnFront($visibleOnFront);
441 $comment->setShipment($this)
442 ->setParentId($this->
getId())
444 if (!$comment->getId()) {
450 $this->_hasDataChanges =
true;
462 if ($this->commentsCollection ===
null || $reload) {
463 $this->commentsCollection = $this->_commentCollectionFactory->create();
464 if ($this->
getId()) {
465 $this->commentsCollection->setShipmentFilter($this->
getId())
466 ->setCreatedAtOrder();
468 foreach ($this->commentsCollection as $comment) {
469 $comment->setShipment($this);
474 return $this->commentsCollection;
484 return $this->
getOrder()->getStore();
522 return $this->
getData(
'increment_id');
554 $collection = $this->_shipmentItemCollectionFactory->create()->setShipmentFilter($this->
getId());
555 if ($this->
getId()) {
557 $item->setShipment($this);
563 if ($shipmentItems !==
null && !is_array($shipmentItems)) {
564 $shipmentItems = $shipmentItems->getItems();
566 return $shipmentItems;
591 $item->setShipment($this);
736 if (!$this->
getId()) {
741 $collection = $this->_commentCollectionFactory->create()
742 ->setShipmentFilter($this->
getId());
745 $item->setShipment($this);
setShippingAddressId($id)
addComment($comment, $notify=false, $visibleOnFront=false)
loadByIncrementId($incrementId)
setComments($comments=null)
_getExtensionAttributes()
setOrder(\Magento\Sales\Model\Order $order)
setTotalWeight($totalWeight)
_setExtensionAttributes(\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)
load($modelId, $field=null)
addItem(\Magento\Sales\Model\Order\Shipment\Item $item)
const XML_PATH_STORE_COUNTRY_ID
$_commentCollectionFactory
const XML_PATH_STORE_REGION_ID
const SHIPPING_ADDRESS_ID
__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=[])
getCommentsCollection($reload=false)
const REPORT_DATE_TYPE_ORDER_CREATED
const XML_PATH_STORE_CITY
setShipmentStatus($shipmentStatus)
setExtensionAttributes(\Magento\Sales\Api\Data\ShipmentExtensionInterface $extensionAttributes)
getData($key='', $index=null)
addTrack(\Magento\Sales\Model\Order\Shipment\Track $track)
setPackages(array $packages=null)
const XML_PATH_STORE_ADDRESS1
setData($key, $value=null)
const XML_PATH_STORE_ADDRESS2
const REPORT_DATE_TYPE_SHIPMENT_CREATED
$_shipmentItemCollectionFactory