Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InventoryGroupedPanel.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
17 
22 {
26  private $isSingleSourceMode;
27 
31  private $locator;
32 
36  private $getQuantityInformationPerSourceBySkus;
37 
43  public function __construct(
44  IsSingleSourceModeInterface $isSingleSourceMode,
45  LocatorInterface $locator,
46  GetQuantityInformationPerSourceBySkus $getQuantityInformationPerSourceBySkus
47  ) {
48  $this->isSingleSourceMode = $isSingleSourceMode;
49  $this->locator = $locator;
50  $this->getQuantityInformationPerSourceBySkus = $getQuantityInformationPerSourceBySkus;
51  }
52 
59  public function modifyData(array $data)
60  {
61  $product = $this->locator->getProduct();
62  $modelId = $product->getId();
63 
64  if ($product->getTypeId() === GroupedProductType::TYPE_CODE
65  && $modelId
66  && isset($data[$modelId]['links'][Grouped::LINK_TYPE])
67  && !$this->isSingleSourceMode->execute()
68  ) {
69  $linkSkus = [];
70 
71  foreach ($data[$modelId]['links'][Grouped::LINK_TYPE] as $linkData) {
72  $linkSkus[] = $linkData['sku'];
73  }
74 
75  $sourceItemsData = $this->getQuantityInformationPerSourceBySkus->execute($linkSkus);
76 
77  foreach ($data[$modelId]['links'][Grouped::LINK_TYPE] as &$productLinkData) {
78  $productLinkData['quantity_per_source'] = $sourceItemsData[$productLinkData['sku']] ?? [];
79  }
80  }
81 
82  return $data;
83  }
84 
91  public function modifyMeta(array $meta): array
92  {
93  if ($this->locator->getProduct()->getTypeId() === GroupedProductType::TYPE_CODE
94  && !$this->isSingleSourceMode->execute()
95  ) {
96  $meta = array_replace_recursive($meta, [
97  'grouped' => [
98  'children' => [
99  'associated' => [
100  'children' => [
101  'record' => [
102  'children' => [
103  'source_code' => [
104  'arguments' => [
105  'data' => [
106  'config' => $this->getQuantityPerSourceConfig()
107  ]
108  ]
109  ]
110  ]
111  ]
112  ],
113  'arguments' => [
114  'data' => [
115  'config' => [
116  'map' => [
117  'quantity_per_source' => 'quantity_per_source'
118  ]
119  ]
120  ]
121  ]
122  ]
123  ]
124  ]
125  ]);
126  }
127 
128  return $meta;
129  }
130 
136  private function getQuantityPerSourceConfig(): array
137  {
138  return [
139  'componentType' => 'text',
140  'component' => 'Magento_InventoryGroupedProductAdminUi/js/form/element/quantity-per-source',
141  'template' => 'ui/form/field',
142  'dataScope' => 'quantity_per_source',
143  'label' => __('Quantity Per Source'),
144  'formElement' => Input::NAME,
145  ];
146  }
147 }
__construct(IsSingleSourceModeInterface $isSingleSourceMode, LocatorInterface $locator, GetQuantityInformationPerSourceBySkus $getQuantityInformationPerSourceBySkus)
__()
Definition: __.php:13