6
6
*/
7
7
namespace Magento \CatalogRuleConfigurable \Plugin \CatalogRule \Model \Rule ;
8
8
9
+ use Magento \Catalog \Api \ProductRepositoryInterface ;
9
10
use Magento \ConfigurableProduct \Model \Product \Type \Configurable ;
10
11
use Magento \CatalogRule \Model \Rule ;
11
12
use Magento \Framework \DataObject ;
@@ -21,12 +22,19 @@ class Validation
21
22
*/
22
23
private $ configurable ;
23
24
25
+ /**
26
+ * @var ProductRepositoryInterface
27
+ */
28
+ private $ productRepository ;
29
+
24
30
/**
25
31
* @param Configurable $configurableType
32
+ * @param ProductRepositoryInterface $productRepository
26
33
*/
27
- public function __construct (Configurable $ configurableType )
34
+ public function __construct (Configurable $ configurableType, ProductRepositoryInterface $ productRepository )
28
35
{
29
36
$ this ->configurable = $ configurableType ;
37
+ $ this ->productRepository = $ productRepository ;
30
38
}
31
39
32
40
/**
@@ -41,7 +49,12 @@ public function afterValidate(Rule $rule, $validateResult, DataObject $product)
41
49
{
42
50
if (!$ validateResult && ($ configurableProducts = $ this ->configurable ->getParentIdsByChild ($ product ->getId ()))) {
43
51
foreach ($ configurableProducts as $ configurableProductId ) {
44
- $ validateResult = $ rule ->getConditions ()->validateByEntityId ($ configurableProductId );
52
+ $ configurableProduct = $ this ->productRepository ->getById (
53
+ $ configurableProductId ,
54
+ false ,
55
+ $ product ->getStoreId ()
56
+ );
57
+ $ validateResult = $ rule ->getConditions ()->validate ($ configurableProduct );
45
58
// If any of configurable product is valid for current rule, then their sub-product must be valid too
46
59
if ($ validateResult ) {
47
60
break ;
0 commit comments