Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
GetSalableQuantityDataBySku Class Reference

Public Member Functions

 __construct (GetProductSalableQtyInterface $getProductSalableQty, StockRepositoryInterface $stockRepository, GetAssignedStockIdsBySku $getAssignedStockIdsBySku, GetStockItemConfigurationInterface $getStockItemConfiguration)
 
 execute (string $sku)
 

Detailed Description

Get salable quantity data by sku

Definition at line 18 of file GetSalableQuantityDataBySku.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( GetProductSalableQtyInterface  $getProductSalableQty,
StockRepositoryInterface  $stockRepository,
GetAssignedStockIdsBySku  $getAssignedStockIdsBySku,
GetStockItemConfigurationInterface  $getStockItemConfiguration 
)
Parameters
GetProductSalableQtyInterface$getProductSalableQty
StockRepositoryInterface$stockRepository
GetAssignedStockIdsBySku$getAssignedStockIdsBySku
GetStockItemConfigurationInterface$getStockItemConfiguration

Definition at line 46 of file GetSalableQuantityDataBySku.php.

51  {
52  $this->getProductSalableQty = $getProductSalableQty;
53  $this->stockRepository = $stockRepository;
54  $this->getAssignedStockIdsBySku = $getAssignedStockIdsBySku;
55  $this->getStockItemConfiguration = $getStockItemConfiguration;
56  }
$stockRepository
Definition: stock.php:19

Member Function Documentation

◆ execute()

execute ( string  $sku)
Parameters
string$sku
Returns
array

Definition at line 62 of file GetSalableQuantityDataBySku.php.

62  : array
63  {
64  $stockInfo = [];
65  $stockIds = $this->getAssignedStockIdsBySku->execute($sku);
66  if (count($stockIds)) {
67  foreach ($stockIds as $stockId) {
68  $stockId = (int)$stockId;
69  $stock = $this->stockRepository->get($stockId);
70  $stockItemConfiguration = $this->getStockItemConfiguration->execute($sku, $stockId);
71  $isManageStock = $stockItemConfiguration->isManageStock();
72  $stockInfo[] = [
73  'stock_name' => $stock->getName(),
74  'qty' => $isManageStock ? $this->getProductSalableQty->execute($sku, $stockId) : null,
75  'manage_stock' => $isManageStock,
76  ];
77  }
78  }
79  return $stockInfo;
80  }
$stock

The documentation for this class was generated from the following file: