/**
  * 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;
 }
Esempio n. 2
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;
 }
Esempio n. 3
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;
 }
 /**
  * @param int|null $id
  * @param int|null $entityId
  * @dataProvider getDataProvider
  */
 public function testGet($id, $entityId)
 {
     if (!$id) {
         $this->setExpectedException('Magento\\Framework\\Exception\\InputException');
         $this->subject->get($id);
     } else {
         $shipment = $this->getMock('Magento\\Sales\\Model\\Order\\Shipment', ['load', 'getEntityId'], [], '', false);
         $shipment->expects($this->once())->method('load')->with($id)->willReturn($shipment);
         $shipment->expects($this->once())->method('getEntityId')->willReturn($entityId);
         $this->metadata->expects($this->once())->method('getNewInstance')->willReturn($shipment);
         if (!$entityId) {
             $this->setExpectedException('Magento\\Framework\\Exception\\NoSuchEntityException');
             $this->subject->get($id);
         } else {
             $this->assertEquals($shipment, $this->subject->get($id));
             $shipment->expects($this->never())->method('load')->with($id)->willReturn($shipment);
             $shipment->expects($this->never())->method('getEntityId')->willReturn($entityId);
             $this->metadata->expects($this->never())->method('getNewInstance')->willReturn($shipment);
             // Retrieve Shipment from registry.
             $this->assertEquals($shipment, $this->subject->get($id));
         }
     }
 }
 /**
  * @param int|null $id
  * @param int|null $entityId
  * @dataProvider getDataProvider
  */
 public function testGet($id, $entityId)
 {
     if (!$id) {
         $this->setExpectedException('Magento\\Framework\\Exception\\InputException');
         $this->subject->get($id);
     } else {
         $shipment = $this->getMock('Magento\\Sales\\Model\\Order\\Shipment', ['getEntityId'], [], '', false);
         $shipment->expects($this->once())->method('getEntityId')->willReturn($entityId);
         $mapper = $this->getMockForAbstractClass('Magento\\Framework\\Model\\ModelResource\\Db\\AbstractDb', [], '', false, true, true, ['load']);
         $mapper->expects($this->once())->method('load')->with($shipment, $id)->willReturnSelf();
         $this->metadata->expects($this->once())->method('getNewInstance')->willReturn($shipment);
         $this->metadata->expects($this->once())->method('getMapper')->willReturn($mapper);
         if (!$entityId) {
             $this->setExpectedException('Magento\\Framework\\Exception\\NoSuchEntityException');
             $this->subject->get($id);
         } else {
             $this->assertEquals($shipment, $this->subject->get($id));
             $mapper->expects($this->never())->method('load');
             $this->metadata->expects($this->never())->method('getNewInstance');
             $this->metadata->expects($this->never())->method('getMapper');
             $this->assertEquals($shipment, $this->subject->get($id));
         }
     }
 }
Esempio n. 6
0
 /**
  * Invoke ShipmentLabelGet service
  *
  * @param int $id
  * @return string
  * @throws \Magento\Framework\Exception\NoSuchEntityException
  */
 public function invoke($id)
 {
     return (string) $this->shipmentRepository->get($id)->getShippingLabel();
 }
Esempio n. 7
0
 /**
  * Invoke notifyUser service
  *
  * @param int $id
  * @return bool
  */
 public function invoke($id)
 {
     /** @var \Magento\Sales\Model\Order\Shipment $shipment */
     $shipment = $this->shipmentRepository->get($id);
     return $this->notifier->notify($shipment);
 }
Esempio n. 8
0
 /**
  * Invoke getShipment service
  *
  * @param int $id
  * @return \Magento\Sales\Service\V1\Data\Shipment
  * @throws \Magento\Framework\Exception\NoSuchEntityException
  */
 public function invoke($id)
 {
     return $this->shipmentMapper->extractDto($this->shipmentRepository->get($id));
 }