Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AddQuantityPerSourceToVariationsMatrix.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
13 
19 {
23  private $getQuantityInformationPerSource;
24 
28  private $isSingleSourceMode;
29 
34  public function __construct(
35  GetQuantityInformationPerSource $getQuantityInformationPerSource,
36  IsSingleSourceModeInterface $isSingleSourceMode
37  ) {
38  $this->getQuantityInformationPerSource = $getQuantityInformationPerSource;
39  $this->isSingleSourceMode = $isSingleSourceMode;
40  }
41 
50  public function afterGetProductMatrix(
51  Matrix $subject,
52  $result
53  ) {
54  if ($this->isSingleSourceMode->execute() === false && is_array($result)) {
55  foreach ($result as $key => $variation) {
56  $result[$key]['quantityPerSource'] = $this->getQuantityInformationPerSource->execute($variation['sku']);
57  }
58  }
59 
60  return $result;
61  }
62 }
__construct(GetQuantityInformationPerSource $getQuantityInformationPerSource, IsSingleSourceModeInterface $isSingleSourceMode)