示例#1
0
 public function testLoadShipmentId()
 {
     $shipmentModelMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Shipment')->disableOriginalConstructor()->setMethods([])->getMock();
     $this->shipmentRepositoryMock->expects($this->once())->method('get')->with($this->loader->getShipmentId())->willReturn($shipmentModelMock);
     $this->registryMock->expects($this->once())->method('register')->with('current_shipment', $shipmentModelMock);
     $this->assertEquals($shipmentModelMock, $this->loader->load());
 }
示例#2
0
 /**
  * Invoke ShipmentList service
  *
  * @param SearchCriteria $searchCriteria
  * @return \Magento\Framework\Service\V1\Data\SearchResults
  */
 public function invoke(SearchCriteria $searchCriteria)
 {
     $shipments = [];
     foreach ($this->shipmentRepository->find($searchCriteria) as $shipment) {
         $shipments[] = $this->shipmentMapper->extractDto($shipment);
     }
     return $this->searchResultsBuilder->setItems($shipments)->setTotalCount(count($shipments))->setSearchCriteria($searchCriteria)->create();
 }
示例#3
0
 /**
  * test shipment list service
  */
 public function testInvoke()
 {
     $this->shipmentRepositoryMock->expects($this->once())->method('find')->with($this->equalTo($this->searchCriteriaMock))->will($this->returnValue([$this->shipmentMock]));
     $this->shipmentMapperMock->expects($this->once())->method('extractDto')->with($this->equalTo($this->shipmentMock))->will($this->returnValue($this->dataObjectMock));
     $this->searchResultsBuilderMock->expects($this->once())->method('setItems')->with($this->equalTo([$this->dataObjectMock]))->will($this->returnSelf());
     $this->searchResultsBuilderMock->expects($this->once())->method('setTotalCount')->with($this->equalTo(count($this->shipmentMock)))->will($this->returnSelf());
     $this->searchResultsBuilderMock->expects($this->once())->method('setSearchCriteria')->with($this->equalTo($this->searchCriteriaMock))->will($this->returnSelf());
     $this->searchResultsBuilderMock->expects($this->once())->method('create')->will($this->returnValue('expected-result'));
     $this->assertEquals('expected-result', $this->shipmentList->invoke($this->searchCriteriaMock));
 }
 /**
  * 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;
 }
示例#5
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;
 }
示例#6
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;
 }
示例#7
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;
 }
 public function testCreate()
 {
     $shipment = $this->getMock('Magento\\Sales\\Model\\Order\\Shipment', [], [], '', false);
     $this->metadata->expects($this->once())->method('getNewInstance')->willReturn($shipment);
     $this->assertEquals($shipment, $this->subject->create());
 }
示例#9
0
 /**
  * test shipment get service
  */
 public function testInvoke()
 {
     $this->shipmentRepositoryMock->expects($this->once())->method('get')->with($this->equalTo(1))->will($this->returnValue($this->shipmentMock));
     $this->shipmentMapperMock->expects($this->once())->method('extractDto')->with($this->equalTo($this->shipmentMock))->will($this->returnValue($this->dataObjectMock));
     $this->assertEquals($this->dataObjectMock, $this->shipmentGet->invoke(1));
 }
示例#10
0
 /**
  * test shipment label get service
  */
 public function testInvoke()
 {
     $this->shipmentRepositoryMock->expects($this->once())->method('get')->with($this->equalTo(1))->will($this->returnValue($this->shipmentMock));
     $this->shipmentMock->expects($this->once())->method('getShippingLabel')->will($this->returnValue('shipping_label'));
     $this->assertEquals('shipping_label', $this->shipmentLabelGet->invoke(1));
 }
示例#11
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();
 }
示例#12
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);
 }
示例#13
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));
 }