Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SalableQuantity.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
16 
20 class SalableQuantity extends Column
21 {
25  private $isSourceItemManagementAllowedForProductType;
26 
30  private $isSingleSourceMode;
31 
35  private $getSalableQuantityDataBySku;
36 
46  public function __construct(
49  IsSourceItemManagementAllowedForProductTypeInterface $isSourceItemManagementAllowedForProductType,
50  IsSingleSourceModeInterface $isSingleSourceMode,
51  GetSalableQuantityDataBySku $getSalableQuantityDataBySku,
52  array $components = [],
53  array $data = []
54  ) {
55  parent::__construct($context, $uiComponentFactory, $components, $data);
56  $this->isSourceItemManagementAllowedForProductType = $isSourceItemManagementAllowedForProductType;
57  $this->isSingleSourceMode = $isSingleSourceMode;
58  $this->getSalableQuantityDataBySku = $getSalableQuantityDataBySku;
59  }
60 
64  public function prepareDataSource(array $dataSource)
65  {
66  if ($dataSource['data']['totalRecords'] > 0) {
67  foreach ($dataSource['data']['items'] as &$row) {
68  $row['salable_quantity'] =
69  $this->isSourceItemManagementAllowedForProductType->execute($row['type_id']) === true
70  ? $this->getSalableQuantityDataBySku->execute($row['sku'])
71  : [];
72  }
73  }
74  unset($row);
75 
76  return $dataSource;
77  }
78 }
__construct(ContextInterface $context, UiComponentFactory $uiComponentFactory, IsSourceItemManagementAllowedForProductTypeInterface $isSourceItemManagementAllowedForProductType, IsSingleSourceModeInterface $isSingleSourceMode, GetSalableQuantityDataBySku $getSalableQuantityDataBySku, array $components=[], array $data=[])