Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SourceItems.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
15 
20 {
24  private $isSourceItemManagementAllowedForProductType;
25 
29  private $isSingleSourceMode;
30 
34  private $locator;
35 
39  private $getSourceItemsDataBySku;
40 
47  public function __construct(
48  IsSourceItemManagementAllowedForProductTypeInterface $isSourceItemManagementAllowedForProductType,
49  IsSingleSourceModeInterface $isSingleSourceMode,
50  LocatorInterface $locator,
51  GetSourceItemsDataBySku $getSourceItemsDataBySku
52  ) {
53  $this->isSourceItemManagementAllowedForProductType = $isSourceItemManagementAllowedForProductType;
54  $this->isSingleSourceMode = $isSingleSourceMode;
55  $this->locator = $locator;
56  $this->getSourceItemsDataBySku = $getSourceItemsDataBySku;
57  }
58 
62  public function modifyData(array $data)
63  {
64  $product = $this->locator->getProduct();
65 
66  if ($this->isSingleSourceMode->execute() === true
67  || $this->isSourceItemManagementAllowedForProductType->execute($product->getTypeId()) === false
68  || null === $product->getId()
69  ) {
70  return $data;
71  }
72 
73  $data[$product->getId()]['sources']['assigned_sources'] = $this->getSourceItemsDataBySku->execute(
74  $product->getSku()
75  );
76 
77  return $data;
78  }
79 
83  public function modifyMeta(array $meta)
84  {
85  $product = $this->locator->getProduct();
86 
87  $meta['sources'] = [
88  'arguments' => [
89  'data' => [
90  'config' => [
91  'visible' => !$this->isSingleSourceMode->execute() &&
92  $this->isSourceItemManagementAllowedForProductType->execute($product->getTypeId()),
93  ],
94  ],
95  ]
96  ];
97 
98  return $meta;
99  }
100 }
__construct(IsSourceItemManagementAllowedForProductTypeInterface $isSourceItemManagementAllowedForProductType, IsSingleSourceModeInterface $isSingleSourceMode, LocatorInterface $locator, GetSourceItemsDataBySku $getSourceItemsDataBySku)
Definition: SourceItems.php:47