5
5
*/
6
6
namespace Magento \ConfigurableProductSales \Model \Order \Reorder ;
7
7
8
- use Magento \Sales \Model \Order \Reorder \OrderedProductAvailabilityCheckerInterface ;
9
- use Magento \Sales \Model \Order \Item ;
10
8
use Magento \Catalog \Api \Data \ProductInterface ;
9
+ use Magento \Catalog \Api \ProductRepositoryInterface ;
11
10
use Magento \Framework \App \ResourceConnection ;
12
11
use Magento \Framework \EntityManager \MetadataPool ;
12
+ use Magento \Sales \Model \Order \Item ;
13
+ use Magento \Sales \Model \Order \Reorder \OrderedProductAvailabilityCheckerInterface ;
13
14
use Magento \Store \Model \Store ;
14
15
15
16
/**
@@ -27,16 +28,24 @@ class OrderedProductAvailabilityChecker implements OrderedProductAvailabilityChe
27
28
*/
28
29
private $ metadataPool ;
29
30
31
+ /**
32
+ * @var ProductRepositoryInterface
33
+ */
34
+ private $ productRepository ;
35
+
30
36
/**
31
37
* @param ResourceConnection $resourceConnection
32
38
* @param MetadataPool $metadataPool
39
+ * @param ProductRepositoryInterface $productRepository
33
40
*/
34
41
public function __construct (
35
42
ResourceConnection $ resourceConnection ,
36
- MetadataPool $ metadataPool
43
+ MetadataPool $ metadataPool ,
44
+ ProductRepositoryInterface $ productRepository
37
45
) {
38
46
$ this ->resourceConnection = $ resourceConnection ;
39
47
$ this ->metadataPool = $ metadataPool ;
48
+ $ this ->productRepository = $ productRepository ;
40
49
}
41
50
42
51
/**
@@ -48,7 +57,9 @@ public function isAvailable(Item $item)
48
57
$ superAttribute = $ buyRequest ->getData ()['super_attribute ' ] ?? [];
49
58
$ connection = $ this ->getConnection ();
50
59
$ select = $ connection ->select ();
51
- $ orderItemParentId = $ item ->getParentItem ()->getProductId ();
60
+ $ linkField = $ this ->getMetadata ()->getLinkField ();
61
+ $ parentItem = $ this ->productRepository ->getById ($ item ->getParentItem ()->getProductId ());
62
+ $ orderItemParentId = $ parentItem ->getData ($ linkField );
52
63
$ select ->from (
53
64
['cpe ' => $ this ->resourceConnection ->getTableName ('catalog_product_entity ' )],
54
65
['cpe.entity_id ' ]
@@ -67,7 +78,7 @@ public function isAvailable(Item $item)
67
78
['cpid ' . $ attributeId => $ this ->resourceConnection ->getTableName ('catalog_product_entity_int ' )],
68
79
sprintf (
69
80
'cpe.%1$s = cpid%2$d.%1$s AND cpid%2$d.attribute_id = %2$d AND cpid%2$d.store_id = %3$d ' ,
70
- $ this -> getMetadata ()-> getLinkField () ,
81
+ $ linkField ,
71
82
$ attributeId ,
72
83
Store::DEFAULT_STORE_ID
73
84
),
@@ -77,7 +88,7 @@ public function isAvailable(Item $item)
77
88
['cpis ' . $ attributeId => $ this ->resourceConnection ->getTableName ('catalog_product_entity_int ' )],
78
89
sprintf (
79
90
'cpe.%1$s = cpis%2$d.%1$s AND cpis%2$d.attribute_id = %2$d AND cpis%2$d.store_id = %3$d ' ,
80
- $ this -> getMetadata ()-> getLinkField () ,
91
+ $ linkField ,
81
92
$ attributeId ,
82
93
$ item ->getStoreId ()
83
94
),
0 commit comments