6
6
*/
7
7
namespace Magento \CatalogRuleConfigurable \Plugin \CatalogRule \Model \Indexer ;
8
8
9
+ use Magento \CatalogRule \Model \Indexer \Product \ProductRuleIndexer ;
9
10
use Magento \ConfigurableProduct \Model \Product \Type \Configurable ;
10
11
use Magento \CatalogRuleConfigurable \Plugin \CatalogRule \Model \ConfigurableProductsProvider ;
11
12
12
13
/**
13
- * Class ReindexProduct. Add configurable sub-products to reindex
14
+ * Add configurable sub-products to reindex
14
15
*/
15
16
class ProductRuleReindex
16
17
{
17
18
/**
18
- * @var \Magento\ConfigurableProduct\Model\Product\Type\ Configurable
19
+ * @var Configurable
19
20
*/
20
21
private $ configurable ;
21
22
22
23
/**
23
- * @var \Magento\CatalogRuleConfigurable\Plugin\CatalogRule\Model\ ConfigurableProductsProvider
24
+ * @var ConfigurableProductsProvider
24
25
*/
25
26
private $ configurableProductsProvider ;
26
27
@@ -37,61 +38,47 @@ public function __construct(
37
38
}
38
39
39
40
/**
40
- * @param \Magento\CatalogRule\Model\Indexer\Product\ProductRuleIndexer $subject
41
+ * Reindex configurable product with sub-products
42
+ *
43
+ * @param ProductRuleIndexer $subject
41
44
* @param \Closure $proceed
42
45
* @param int $id
43
- *
44
46
* @return void
45
47
*/
46
- public function aroundExecuteRow (
47
- \Magento \CatalogRule \Model \Indexer \Product \ProductRuleIndexer $ subject ,
48
- \Closure $ proceed ,
49
- $ id
50
- ) {
48
+ public function aroundExecuteRow (ProductRuleIndexer $ subject , \Closure $ proceed , $ id )
49
+ {
50
+ $ isReindexed = false ;
51
+
51
52
$ configurableProductIds = $ this ->configurableProductsProvider ->getIds ([$ id ]);
52
- $ this ->reindexSubProducts ($ configurableProductIds , $ subject );
53
- if (!$ configurableProductIds ) {
54
- $ proceed ($ id );
53
+ if ($ configurableProductIds ) {
54
+ $ subProducts = array_values ($ this ->configurable ->getChildrenIds ($ id )[0 ]);
55
+ if ($ subProducts ) {
56
+ $ subject ->executeList (array_merge ([$ id ], $ subProducts ));
57
+ $ isReindexed = true ;
58
+ }
55
59
}
56
- }
57
60
58
- /**
59
- * @param \Magento\CatalogRule\Model\Indexer\Product\ProductRuleIndexer $subject
60
- * @param \Closure $proceed
61
- * @param array $ids
62
- *
63
- * @return void
64
- */
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 );
61
+ if (!$ isReindexed ) {
62
+ $ proceed ($ id );
75
63
}
76
64
}
77
65
78
66
/**
79
- * @param array $configurableIds
80
- * @param \Magento\CatalogRule\Model\Indexer\Product\ProductRuleIndexer $subject
67
+ * Add sub-products to reindex
81
68
*
69
+ * @param ProductRuleIndexer $subject
70
+ * @param array $ids
82
71
* @return array
72
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
83
73
*/
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
- }
74
+ public function beforeExecuteList (ProductRuleIndexer $ subject , array $ ids ): array
75
+ {
76
+ $ configurableProductIds = $ this ->configurableProductsProvider ->getIds ($ ids );
77
+ if ($ configurableProductIds ) {
78
+ $ subProducts = array_values ($ this ->configurable ->getChildrenIds ($ configurableProductIds )[0 ]);
79
+ $ ids = array_unique (array_merge ($ ids , $ subProducts ));
94
80
}
95
- return $ subProducts ;
81
+
82
+ return [$ ids ];
96
83
}
97
84
}
0 commit comments