Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InventoryConfigurablePanel.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
17 
22 {
26  private $getQuantityInformationPerSource;
27 
31  private $isSingleSourceMode;
32 
36  private $locator;
37 
43  public function __construct(
44  GetQuantityInformationPerSource $getQuantityInformationPerSource,
45  IsSingleSourceModeInterface $isSingleSourceMode,
46  LocatorInterface $locator
47  ) {
48  $this->getQuantityInformationPerSource = $getQuantityInformationPerSource;
49  $this->isSingleSourceMode = $isSingleSourceMode;
50  $this->locator = $locator;
51  }
52 
56  public function modifyData(array $data)
57  {
58  if ($this->isSingleSourceMode->execute() === false) {
59  $productId = $this->locator->getProduct()->getId();
60 
62  foreach ($data[$productId][ConfigurablePanel::CONFIGURABLE_MATRIX] as $key => $productArray) {
63  $quantityPerSource
64  = $this->getQuantityInformationPerSource->execute($productArray[ProductInterface::SKU]);
65  $data[$productId][ConfigurablePanel::CONFIGURABLE_MATRIX][$key]['quantity_per_source']
66  = $quantityPerSource;
67  }
68  }
69  }
70 
71  return $data;
72  }
73 
79  private function getQuantityContainerConfig(): array
80  {
81  return [
82  'arguments' => [
83  'data' => [
84  'config' => [
85  'componentType' => 'text',
86  'component' =>
87  'Magento_InventoryConfigurableProductAdminUi/js/form/element/quantity-per-source',
88  'template' => 'ui/form/field',
89  'dataScope' => 'quantity_per_source',
90  'label' => __('Quantity Per Source'),
91  'formElement' => Form\Element\Input::NAME,
92  ],
93  ],
94  ],
95  ];
96  }
97 
101  public function modifyMeta(array $meta)
102  {
103  if ($this->isSingleSourceMode->execute() === false) {
104  $meta[ConfigurablePanel::GROUP_CONFIGURABLE]['children']
106  ['record']['children']['quantity_per_source_container'] = $this->getQuantityContainerConfig();
107 
108  unset($meta[ConfigurablePanel::GROUP_CONFIGURABLE]['children']
110  ['record']['children']['quantity_container']);
111 
112  $meta[ConfigurablePanel::GROUP_CONFIGURABLE]['children']
113  [ConfigurablePanel::CONFIGURABLE_MATRIX]['arguments']['data']['config']['component']
114  = 'Magento_InventoryConfigurableProductAdminUi/js/components/dynamic-rows-configurable';
115  }
116 
117  return $meta;
118  }
119 }
__()
Definition: __.php:13
__construct(GetQuantityInformationPerSource $getQuantityInformationPerSource, IsSingleSourceModeInterface $isSingleSourceMode, LocatorInterface $locator)