Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AdaptStockResolverToAdminWebsitePlugin.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
17 
22 {
26  private $stockRepository;
27 
31  private $defaultStockProviderInterface;
32 
37  public function __construct(
38  DefaultStockProviderInterface $defaultStockProviderInterface,
39  StockRepositoryInterface $stockRepositoryInterface
40  ) {
41  $this->defaultStockProviderInterface = $defaultStockProviderInterface;
42  $this->stockRepository = $stockRepositoryInterface;
43  }
44 
52  public function aroundExecute(
53  GetStockBySalesChannelInterface $getStockBySalesChannel,
54  callable $proceed,
55  SalesChannelInterface $salesChannel
56  ): StockInterface {
57  if (SalesChannelInterface::TYPE_WEBSITE === $salesChannel->getType()
58  && WebsiteInterface::ADMIN_CODE === $salesChannel->getCode()) {
59  return $this->stockRepository->get($this->defaultStockProviderInterface->getId());
60  }
61  return $proceed($salesChannel);
62  }
63 }
__construct(DefaultStockProviderInterface $defaultStockProviderInterface, StockRepositoryInterface $stockRepositoryInterface)
aroundExecute(GetStockBySalesChannelInterface $getStockBySalesChannel, callable $proceed, SalesChannelInterface $salesChannel)