Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConfigurableProductHandler.php
Go to the documentation of this file.
1 <?php
8 
11 
16 {
20  private $configurable;
21 
25  private $configurableProductsProvider;
26 
30  private $childrenProducts = [];
31 
36  public function __construct(
38  ConfigurableProductsProvider $configurableProductsProvider
39  ) {
40  $this->configurable = $configurable;
41  $this->configurableProductsProvider = $configurableProductsProvider;
42  }
43 
50  public function afterGetMatchingProductIds(\Magento\CatalogRule\Model\Rule $rule, array $productIds)
51  {
52  $configurableProductIds = $this->configurableProductsProvider->getIds(array_keys($productIds));
53  foreach ($configurableProductIds as $productId) {
54  if (!isset($this->childrenProducts[$productId])) {
55  $this->childrenProducts[$productId] = $this->configurable->getChildrenIds($productId)[0];
56  }
57  $subProductIds = $this->childrenProducts[$productId];
58  $parentValidationResult = isset($productIds[$productId])
59  ? array_filter($productIds[$productId])
60  : [];
61  foreach ($subProductIds as $subProductId) {
62  $childValidationResult = isset($productIds[$subProductId])
63  ? array_filter($productIds[$subProductId])
64  : [];
65  $productIds[$subProductId] = $parentValidationResult + $childValidationResult;
66  }
67  unset($productIds[$productId]);
68  }
69  return $productIds;
70  }
71 }
__construct(\Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable $configurable, ConfigurableProductsProvider $configurableProductsProvider)