Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Inventory.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
15 
21 class Inventory extends Template
22 {
26  private $registry;
27 
31  private $sourceRepository;
32 
40  public function __construct(
41  Context $context,
42  Registry $registry,
43  SourceRepositoryInterface $sourceRepository,
44  array $data = []
45  ) {
46  parent::__construct($context, $data);
47  $this->registry = $registry;
48  $this->sourceRepository = $sourceRepository;
49  }
50 
56  public function getShipment()
57  {
58  return $this->registry->registry('current_shipment');
59  }
60 
66  public function getSourceCode()
67  {
68  $shipment = $this->getShipment();
69  $extensionAttributes = $shipment->getExtensionAttributes();
70  if ($sourceCode = $extensionAttributes->getSourceCode()) {
71  return $sourceCode;
72  }
73  return null;
74  }
75 
83  public function getSourceName(string $sourceCode): string
84  {
85  return $this->sourceRepository->get($sourceCode)->getName();
86  }
87 }
__construct(Context $context, Registry $registry, SourceRepositoryInterface $sourceRepository, array $data=[])
Definition: Inventory.php:40
$sourceCode
Definition: inventory.phtml:11
$extensionAttributes
Definition: payment.php:22
$sourceRepository
Definition: source.php:20
foreach($order->getItems() as $orderItem) $shipment