Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Get.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
13 use Magento\InventoryApi\Api\Data\StockInterfaceFactory;
14 
18 class Get implements GetInterface
19 {
23  private $stockResource;
24 
28  private $stockFactory;
29 
34  public function __construct(
35  StockResourceModel $stockResource,
36  StockInterfaceFactory $stockFactory
37  ) {
38  $this->stockResource = $stockResource;
39  $this->stockFactory = $stockFactory;
40  }
41 
45  public function execute(int $stockId): StockInterface
46  {
48  $stock = $this->stockFactory->create();
49  $this->stockResource->load($stock, $stockId, StockInterface::STOCK_ID);
50 
51  if (null === $stock->getStockId()) {
52  throw new NoSuchEntityException(__('Stock with id "%value" does not exist.', ['value' => $stockId]));
53  }
54  return $stock;
55  }
56 }
__()
Definition: __.php:13
$stockFactory
Definition: stock.php:15
$stock
__construct(StockResourceModel $stockResource, StockInterfaceFactory $stockFactory)
Definition: Get.php:34