/**
  * 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;
 }
Beispiel #2
0
 /**
  * Convert order object to Shipment
  *
  * @param   \Magento\Sales\Model\Order $order
  * @return  \Magento\Sales\Model\Order\Shipment
  */
 public function toShipment(\Magento\Sales\Model\Order $order)
 {
     $shipment = $this->shipmentRepository->create();
     $shipment->setOrder($order)->setStoreId($order->getStoreId())->setCustomerId($order->getCustomerId())->setBillingAddressId($order->getBillingAddressId())->setShippingAddressId($order->getShippingAddressId());
     $this->_objectCopyService->copyFieldsetToTarget('sales_convert_order', 'to_shipment', $order, $shipment);
     return $shipment;
 }
Beispiel #3
0
 /**
  * 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;
 }
Beispiel #4
0
 /**
  * Run test notify method
  */
 public function testNotify()
 {
     $id = 123;
     $returnValue = 'return-value';
     $modelMock = $this->getMockForAbstractClass('Magento\\Sales\\Model\\AbstractModel', [], '', false);
     $this->repositoryMock->expects($this->once())->method('get')->with($id)->will($this->returnValue($modelMock));
     $this->notifierMock->expects($this->once())->method('notify')->with($modelMock)->will($this->returnValue($returnValue));
     $this->assertEquals($returnValue, $this->shipmentService->notify($id));
 }
Beispiel #5
0
 /**
  * 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;
 }
Beispiel #6
0
 /**
  * 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);
 }