Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GetAssignedStockIdsBySku.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
12 
17 {
21  private $getSourceItemsBySku;
22 
26  private $getStockSourceLinksBySourceCode;
27 
32  public function __construct(
33  GetSourceItemsBySkuInterface $getSourceItemsBySku,
34  GetStockSourceLinksBySourceCode $getStockSourceLinksBySourceCode
35  ) {
36  $this->getSourceItemsBySku = $getSourceItemsBySku;
37  $this->getStockSourceLinksBySourceCode = $getStockSourceLinksBySourceCode;
38  }
39 
44  public function execute(string $sku): array
45  {
46  $sourceItems = $this->getSourceItemsBySku->execute($sku);
47 
48  $stocksIds = [];
49  foreach ($sourceItems as $sourceItem) {
50  $stockSourceLinks = $this->getStockSourceLinksBySourceCode->execute($sourceItem->getSourceCode());
51  foreach ($stockSourceLinks as $stockSourceLink) {
52  $stocksIds[] = (int)$stockSourceLink->getStockId();
53  }
54  }
55 
56  return array_unique($stocksIds);
57  }
58 }
__construct(GetSourceItemsBySkuInterface $getSourceItemsBySku, GetStockSourceLinksBySourceCode $getStockSourceLinksBySourceCode)
$sourceItems