Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
LoadSourceForShipmentPlugin.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
13 use Magento\Sales\Api\Data\ShipmentExtensionFactory;
14 
16 {
20  private $shipmentExtensionFactory;
21 
25  private $getSourceCodeByShipmentId;
26 
31  public function __construct(
32  ShipmentExtensionFactory $shipmentExtensionFactory,
33  GetSourceCodeByShipmentId $getSourceCodeByShipmentId
34  ) {
35  $this->shipmentExtensionFactory = $shipmentExtensionFactory;
36  $this->getSourceCodeByShipmentId = $getSourceCodeByShipmentId;
37  }
38 
46  public function afterLoad(
47  ShipmentResource $subject,
50  ) {
51  $shipmentExtension = $shipment->getExtensionAttributes();
52  if (empty($shipmentExtension)) {
53  $shipmentExtension = $this->shipmentExtensionFactory->create();
54  }
55  $sourceCode = $this->getSourceCodeByShipmentId->execute((int)$shipment->getId());
56  $shipmentExtension->setSourceCode($sourceCode);
57  $shipment->setExtensionAttributes($shipmentExtension);
58 
59  return $result;
60  }
61 }
$sourceCode
Definition: inventory.phtml:11
afterLoad(ShipmentResource $subject, ShipmentResource $result, AbstractModel $shipment)
__construct(ShipmentExtensionFactory $shipmentExtensionFactory, GetSourceCodeByShipmentId $getSourceCodeByShipmentId)
foreach($order->getItems() as $orderItem) $shipment