Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
ShipOrder Class Reference
Inheritance diagram for ShipOrder:
ShipOrderInterface

Public Member Functions

 __construct (ResourceConnection $resourceConnection, OrderRepositoryInterface $orderRepository, ShipmentDocumentFactory $shipmentDocumentFactory, OrderStateResolverInterface $orderStateResolver, OrderConfig $config, ShipmentRepositoryInterface $shipmentRepository, ShipOrderValidator $shipOrderValidator, NotifierInterface $notifierInterface, OrderRegistrarInterface $orderRegistrar, LoggerInterface $logger)
 
 execute ( $orderId, array $items=[], $notify=false, $appendComment=false, \Magento\Sales\Api\Data\ShipmentCommentCreationInterface $comment=null, array $tracks=[], array $packages=[], \Magento\Sales\Api\Data\ShipmentCreationArgumentsInterface $arguments=null)
 

Detailed Description

Class ShipOrder @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 24 of file ShipOrder.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( ResourceConnection  $resourceConnection,
OrderRepositoryInterface  $orderRepository,
ShipmentDocumentFactory  $shipmentDocumentFactory,
OrderStateResolverInterface  $orderStateResolver,
OrderConfig  $config,
ShipmentRepositoryInterface  $shipmentRepository,
ShipOrderValidator  $shipOrderValidator,
NotifierInterface  $notifierInterface,
OrderRegistrarInterface  $orderRegistrar,
LoggerInterface  $logger 
)
Parameters
ResourceConnection$resourceConnection
OrderRepositoryInterface$orderRepository
ShipmentDocumentFactory$shipmentDocumentFactory
OrderStateResolverInterface$orderStateResolver
OrderConfig$config
ShipmentRepositoryInterface$shipmentRepository
ShipOrderValidator$shipOrderValidator
NotifierInterface$notifierInterface
OrderRegistrarInterface$orderRegistrar
LoggerInterface$logger@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 89 of file ShipOrder.php.

100  {
101  $this->resourceConnection = $resourceConnection;
102  $this->orderRepository = $orderRepository;
103  $this->shipmentDocumentFactory = $shipmentDocumentFactory;
104  $this->orderStateResolver = $orderStateResolver;
105  $this->config = $config;
106  $this->shipmentRepository = $shipmentRepository;
107  $this->shipOrderValidator = $shipOrderValidator;
108  $this->notifierInterface = $notifierInterface;
109  $this->logger = $logger;
110  $this->orderRegistrar = $orderRegistrar;
111  }
$config
Definition: fraud_order.php:17
$orderRepository
Definition: order.php:69
$logger

Member Function Documentation

◆ execute()

execute (   $orderId,
array  $items = [],
  $notify = false,
  $appendComment = false,
\Magento\Sales\Api\Data\ShipmentCommentCreationInterface  $comment = null,
array  $tracks = [],
array  $packages = [],
\Magento\Sales\Api\Data\ShipmentCreationArgumentsInterface  $arguments = null 
)
Parameters
int$orderId

Implements ShipOrderInterface.

Definition at line 129 of file ShipOrder.php.

138  {
139  $connection = $this->resourceConnection->getConnection('sales');
140  $order = $this->orderRepository->get($orderId);
141  $shipment = $this->shipmentDocumentFactory->create(
142  $order,
143  $items,
144  $tracks,
145  $comment,
146  ($appendComment && $notify),
147  $packages,
148  $arguments
149  );
150  $validationMessages = $this->shipOrderValidator->validate(
151  $order,
152  $shipment,
153  $items,
154  $notify,
155  $appendComment,
156  $comment,
157  $tracks,
158  $packages
159  );
160  if ($validationMessages->hasMessages()) {
161  throw new \Magento\Sales\Exception\DocumentValidationException(
162  __("Shipment Document Validation Error(s):\n" . implode("\n", $validationMessages->getMessages()))
163  );
164  }
165  $connection->beginTransaction();
166  try {
167  $this->orderRegistrar->register($order, $shipment);
168  $order->setState(
169  $this->orderStateResolver->getStateForOrder($order, [OrderStateResolverInterface::IN_PROGRESS])
170  );
171  $order->setStatus($this->config->getStateDefaultStatus($order->getState()));
172  $this->shipmentRepository->save($shipment);
173  $this->orderRepository->save($order);
174  $connection->commit();
175  } catch (\Exception $e) {
176  $this->logger->critical($e);
177  $connection->rollBack();
178  throw new \Magento\Sales\Exception\CouldNotShipException(
179  __('Could not save a shipment, see error log for details')
180  );
181  }
182  if ($notify) {
183  if (!$appendComment) {
184  $comment = null;
185  }
186  $this->notifierInterface->notify($order, $shipment, $comment);
187  }
188  return $shipment->getEntityId();
189  }
$order
Definition: order.php:55
__()
Definition: __.php:13
$arguments
$connection
Definition: bulk.php:13
foreach($order->getItems() as $orderItem) $shipment
$items

The documentation for this class was generated from the following file: