Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ProductRuleReindex.php
Go to the documentation of this file.
1 <?php
8 
11 
16 {
20  private $configurable;
21 
25  private $configurableProductsProvider;
26 
31  public function __construct(
32  Configurable $configurable,
33  ConfigurableProductsProvider $configurableProductsProvider
34  ) {
35  $this->configurable = $configurable;
36  $this->configurableProductsProvider = $configurableProductsProvider;
37  }
38 
46  public function aroundExecuteRow(
47  \Magento\CatalogRule\Model\Indexer\Product\ProductRuleIndexer $subject,
48  \Closure $proceed,
49  $id
50  ) {
51  $configurableProductIds = $this->configurableProductsProvider->getIds([$id]);
52  $this->reindexSubProducts($configurableProductIds, $subject);
53  if (!$configurableProductIds) {
54  $proceed($id);
55  }
56  }
57 
65  public function aroundExecuteList(
66  \Magento\CatalogRule\Model\Indexer\Product\ProductRuleIndexer $subject,
67  \Closure $proceed,
68  array $ids
69  ) {
70  $configurableProductIds = $this->configurableProductsProvider->getIds($ids);
71  $subProducts = $this->reindexSubProducts($configurableProductIds, $subject);
72  $ids = array_diff($ids, $configurableProductIds, $subProducts);
73  if ($ids) {
74  $proceed($ids);
75  }
76  }
77 
84  private function reindexSubProducts(
85  array $configurableIds,
86  \Magento\CatalogRule\Model\Indexer\Product\ProductRuleIndexer $subject
87  ) {
88  $subProducts = [];
89  if ($configurableIds) {
90  $subProducts = array_values($this->configurable->getChildrenIds($configurableIds)[0]);
91  if ($subProducts) {
92  $subject->executeList($subProducts);
93  }
94  }
95  return $subProducts;
96  }
97 }
aroundExecuteList(\Magento\CatalogRule\Model\Indexer\Product\ProductRuleIndexer $subject, \Closure $proceed, array $ids)
$id
Definition: fieldset.phtml:14
__construct(Configurable $configurable, ConfigurableProductsProvider $configurableProductsProvider)
aroundExecuteRow(\Magento\CatalogRule\Model\Indexer\Product\ProductRuleIndexer $subject, \Closure $proceed, $id)