Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GetStockItemConfiguration.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
16 
21 {
25  private $getLegacyStockItem;
26 
30  private $stockItemConfigurationFactory;
31 
35  private $isProductAssignedToStock;
36 
40  private $defaultStockProvider;
41 
45  private $isSourceItemManagementAllowedForSku;
46 
54  public function __construct(
55  GetLegacyStockItem $getLegacyStockItem,
56  StockItemConfigurationFactory $stockItemConfigurationFactory,
57  IsProductAssignedToStockInterface $isProductAssignedToStock,
58  DefaultStockProviderInterface $defaultStockProvider,
59  IsSourceItemManagementAllowedForSkuInterface $isSourceItemManagementAllowedForSku
60  ) {
61  $this->getLegacyStockItem = $getLegacyStockItem;
62  $this->stockItemConfigurationFactory = $stockItemConfigurationFactory;
63  $this->isProductAssignedToStock = $isProductAssignedToStock;
64  $this->defaultStockProvider = $defaultStockProvider;
65  $this->isSourceItemManagementAllowedForSku = $isSourceItemManagementAllowedForSku;
66  }
67 
71  public function execute(string $sku, int $stockId): StockItemConfigurationInterface
72  {
73  if ($this->defaultStockProvider->getId() !== $stockId
74  && true === $this->isSourceItemManagementAllowedForSku->execute($sku)
75  && false === $this->isProductAssignedToStock->execute($sku, $stockId)) {
77  __('The requested sku is not assigned to given stock.')
78  );
79  }
80 
81  return $this->stockItemConfigurationFactory->create(
82  [
83  'stockItem' => $this->getLegacyStockItem->execute($sku)
84  ]
85  );
86  }
87 }
__construct(GetLegacyStockItem $getLegacyStockItem, StockItemConfigurationFactory $stockItemConfigurationFactory, IsProductAssignedToStockInterface $isProductAssignedToStock, DefaultStockProviderInterface $defaultStockProvider, IsSourceItemManagementAllowedForSkuInterface $isSourceItemManagementAllowedForSku)
__()
Definition: __.php:13