/** * Initialize shipment model instance * * @return bool|\Magento\Sales\Model\Order\Shipment * @throws \Magento\Framework\Exception\LocalizedException */ public function load() { $shipment = false; $orderId = $this->getOrderId(); $shipmentId = $this->getShipmentId(); if ($shipmentId) { $shipment = $this->shipmentRepository->get($shipmentId); } elseif ($orderId) { $order = $this->orderRepository->get($orderId); /** * Check order existing */ if (!$order->getId()) { $this->messageManager->addError(__('The order no longer exists.')); return false; } /** * Check shipment is available to create separate from invoice */ if ($order->getForcedShipmentWithInvoice()) { $this->messageManager->addError(__('Cannot do shipment for the order separately from invoice.')); return false; } /** * Check shipment create availability */ if (!$order->canShip()) { $this->messageManager->addError(__('Cannot do shipment for the order.')); return false; } $shipment = $this->shipmentFactory->create($order, $this->getItemQtys(), $this->getTracking()); } $this->registry->register('current_shipment', $shipment); return $shipment; }
/** * Retrieve Shipment instance * * @return \Magento\Sales\Model\Order\Shipment */ public function getShipment() { if (!$this->_shipment instanceof \Magento\Sales\Model\Order\Shipment) { $this->_shipment = $this->shipmentRepository->get($this->getParentId()); } return $this->_shipment; }
/** * Instantiate ship model * * @return Shipment|bool */ protected function _initShipment() { /* @var $model Shipment */ $ship = $this->shipmentRepository->get($this->getShipId()); if (!$ship->getEntityId() || $this->getProtectCode() != $ship->getProtectCode()) { return false; } return $ship; }
/** * 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; }
/** * Notify user * * @param int $id * @return bool */ public function notify($id) { $shipment = $this->repository->get($id); return $this->notifier->notify($shipment); }