@@ -20,9 +20,6 @@ class ConfigurableProductHandler
2020 /** @var ConfigurableProductsProvider */
2121 private $ configurableProductsProvider ;
2222
23- /** @var array */
24- private $ subProductsValidationResults = [];
25-
2623 /**
2724 * @param \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable $configurable
2825 * @param ConfigurableProductsProvider $configurableProductsProvider
@@ -39,45 +36,24 @@ public function __construct(
3936 * @param \Magento\CatalogRule\Model\Rule $rule
4037 * @param array $productIds
4138 * @return array
39+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
4240 */
4341 public function afterGetMatchingProductIds (\Magento \CatalogRule \Model \Rule $ rule , array $ productIds )
4442 {
4543 $ configurableProductIds = $ this ->configurableProductsProvider ->getIds (array_keys ($ productIds ));
4644 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 ;
5554 }
5655 unset($ productIds [$ productId ]);
5756 }
5857 return $ productIds ;
5958 }
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- }
8359}
0 commit comments