@@ -20,9 +20,6 @@ class ConfigurableProductHandler
20
20
/** @var ConfigurableProductsProvider */
21
21
private $ configurableProductsProvider ;
22
22
23
- /** @var array */
24
- private $ subProductsValidationResults = [];
25
-
26
23
/**
27
24
* @param \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable $configurable
28
25
* @param ConfigurableProductsProvider $configurableProductsProvider
@@ -39,45 +36,24 @@ public function __construct(
39
36
* @param \Magento\CatalogRule\Model\Rule $rule
40
37
* @param array $productIds
41
38
* @return array
39
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
42
40
*/
43
41
public function afterGetMatchingProductIds (\Magento \CatalogRule \Model \Rule $ rule , array $ productIds )
44
42
{
45
43
$ configurableProductIds = $ this ->configurableProductsProvider ->getIds (array_keys ($ productIds ));
46
44
foreach ($ configurableProductIds as $ productId ) {
47
- $ subProductsIds = $ this ->configurable ->getChildrenIds ($ productId )[0 ];
48
- $ parentValidationResult = $ productIds [$ productId ];
49
- foreach ($ subProductsIds as $ subProductsId ) {
50
- $ productIds [$ subProductsId ] = $ this ->getSubProductValidationResult (
51
- $ rule ->getId (),
52
- $ subProductsId ,
53
- $ parentValidationResult
54
- );
45
+ $ subProductIds = $ this ->configurable ->getChildrenIds ($ productId )[0 ];
46
+ $ parentValidationResult = isset ($ productIds [$ productId ])
47
+ ? array_filter ($ productIds [$ productId ])
48
+ : [];
49
+ foreach ($ subProductIds as $ subProductId ) {
50
+ $ childValidationResult = isset ($ productIds [$ subProductId ])
51
+ ? array_filter ($ productIds [$ subProductId ])
52
+ : [];
53
+ $ productIds [$ subProductId ] = $ parentValidationResult + $ childValidationResult ;
55
54
}
56
55
unset($ productIds [$ productId ]);
57
56
}
58
57
return $ productIds ;
59
58
}
60
-
61
- /**
62
- * Return validation result for sub-product.
63
- * If any of configurable product is valid for current rule, then their sub-product must be valid too
64
- *
65
- * @param int $urlId
66
- * @param int $subProductsId
67
- * @param array $parentValidationResult
68
- * @return array
69
- */
70
- private function getSubProductValidationResult ($ urlId , $ subProductsId , $ parentValidationResult )
71
- {
72
- if (!isset ($ this ->subProductsValidationResults [$ urlId ][$ subProductsId ])) {
73
- $ this ->subProductsValidationResults [$ urlId ][$ subProductsId ] = array_filter ($ parentValidationResult );
74
- } else {
75
- $ parentValidationResult = array_intersect_key (
76
- $ this ->subProductsValidationResults [$ urlId ][$ subProductsId ] + $ parentValidationResult ,
77
- $ parentValidationResult
78
- );
79
- $ this ->subProductsValidationResults [$ urlId ][$ subProductsId ] = $ parentValidationResult ;
80
- }
81
- return $ parentValidationResult ;
82
- }
83
59
}
0 commit comments