10
10
use Magento \Catalog \Api \Data \ProductInterface ;
11
11
use Magento \Catalog \Model \Product ;
12
12
use Magento \Catalog \Model \ProductLink \MapProviderInterface ;
13
- use Magento \Catalog \Model \Product \LinkFactory ;
14
13
use Magento \Catalog \Model \Product \Link ;
15
14
use Magento \Framework \EntityManager \MetadataPool ;
16
15
use Magento \Catalog \Model \ResourceModel \Product \Link \Product \Collection as LinkedProductCollection ;
@@ -36,9 +35,9 @@ class LinkedMapProvider implements MapProviderInterface
36
35
];
37
36
38
37
/**
39
- * @var LinkFactory
38
+ * @var Link
40
39
*/
41
- private $ linkModelFactory ;
40
+ private $ linkModel ;
42
41
43
42
/**
44
43
* @var MetadataPool
@@ -52,16 +51,16 @@ class LinkedMapProvider implements MapProviderInterface
52
51
53
52
/**
54
53
* LinkedMapProvider constructor.
55
- * @param LinkFactory $linkFactory
54
+ * @param Link $linkModel
56
55
* @param MetadataPool $metadataPool
57
56
* @param LinkedProductCollectionFactory $productCollectionFactory
58
57
*/
59
58
public function __construct (
60
- LinkFactory $ linkFactory ,
59
+ Link $ linkModel ,
61
60
MetadataPool $ metadataPool ,
62
61
LinkedProductCollectionFactory $ productCollectionFactory
63
62
) {
64
- $ this ->linkModelFactory = $ linkFactory ;
63
+ $ this ->linkModel = $ linkModel ;
65
64
$ this ->metadata = $ metadataPool ;
66
65
$ this ->productCollectionFactory = $ productCollectionFactory ;
67
66
}
@@ -138,17 +137,15 @@ private function processCached(array $products, array $types, array &$map): arra
138
137
private function queryLinkedProducts (array $ productIds , array $ types ): array
139
138
{
140
139
$ found = [];
141
- /** @var \Magento\Catalog\Model\Product\Link $linkModel */
142
- $ linkModel = $ this ->linkModelFactory ->create ();
143
140
foreach ($ types as $ type => $ typeId ) {
144
141
if (!array_key_exists ($ type , $ productIds )) {
145
142
continue ;
146
143
}
147
144
148
145
/** @var LinkedProductCollection $collection */
149
146
$ collection = $ this ->productCollectionFactory ->create (['productIds ' => $ productIds [$ type ]]);
150
- $ linkModel ->setLinkTypeId ($ typeId );
151
- $ collection ->setLinkModel ($ linkModel );
147
+ $ this -> linkModel ->setLinkTypeId ($ typeId );
148
+ $ collection ->setLinkModel ($ this -> linkModel );
152
149
$ collection ->setIsStrongMode ();
153
150
$ found [$ type ] = $ collection ->getItems ();
154
151
}
0 commit comments