Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GetStockBySalesChannel.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
16 
21 {
25  private $stockRepository;
26 
30  private $stockIdResolver;
31 
36  public function __construct(
37  StockRepositoryInterface $stockRepositoryInterface,
38  StockIdResolver $stockIdResolver
39  ) {
40  $this->stockRepository = $stockRepositoryInterface;
41  $this->stockIdResolver = $stockIdResolver;
42  }
43 
47  public function execute(SalesChannelInterface $salesChannel): StockInterface
48  {
49  $stockId = $this->stockIdResolver->resolve(
50  $salesChannel->getType(),
51  $salesChannel->getCode()
52  );
53 
54  if (null === $stockId) {
55  throw new NoSuchEntityException(__('No linked stock found'));
56  }
57  return $this->stockRepository->get($stockId);
58  }
59 }
__()
Definition: __.php:13
__construct(StockRepositoryInterface $stockRepositoryInterface, StockIdResolver $stockIdResolver)