@@ -25,25 +25,34 @@ class LinkProcessor
25
25
private $ linkNameToId ;
26
26
27
27
/**
28
- * @var LinkFactory
28
+ * @var LinkFactory
29
29
*/
30
30
private $ linkFactory ;
31
31
32
32
/**
33
- * @var Helper
33
+ * @var Helper
34
34
*/
35
35
private $ resourceHelper ;
36
36
37
37
/**
38
- * @var SkuProcessor
38
+ * @var SkuProcessor
39
39
*/
40
40
private $ skuProcessor ;
41
41
42
42
/**
43
- * @var LoggerInterface
43
+ * @var LoggerInterface
44
44
*/
45
45
private $ logger ;
46
46
47
+ /**
48
+ * LinkProcessor constructor.
49
+ *
50
+ * @param LinkFactory $linkFactory
51
+ * @param Helper $resourceHelper
52
+ * @param SkuProcessor $skuProcessor
53
+ * @param LoggerInterface $logger
54
+ * @param array $linkNameToId
55
+ */
47
56
public function __construct (
48
57
LinkFactory $ linkFactory ,
49
58
Helper $ resourceHelper ,
@@ -64,17 +73,17 @@ public function __construct(
64
73
*
65
74
* Must be called after ALL products saving done.
66
75
*
76
+ * @param Product $importEntity
77
+ * @param Data $dataSourceModel
78
+ * @param string $linkField
67
79
* @return $this
68
80
* @throws LocalizedException
69
81
*/
70
82
public function saveLinks (
71
83
Product $ importEntity ,
72
84
Data $ dataSourceModel ,
73
85
string $ linkField
74
- ) {
75
- /**
76
- * @var Link $resource
77
- */
86
+ ): void {
78
87
$ resource = $ this ->linkFactory ->create ();
79
88
$ mainTable = $ resource ->getMainTable ();
80
89
$ positionAttrId = [];
@@ -94,21 +103,27 @@ public function saveLinks(
94
103
while ($ bunch = $ dataSourceModel ->getNextBunch ()) {
95
104
$ this ->processLinkBunches ($ importEntity , $ linkField , $ bunch , $ resource , $ nextLinkId , $ positionAttrId );
96
105
}
97
-
98
- return $ this ;
99
106
}
100
107
101
- public function addNameToIds ($ nameToIds )
108
+ /**
109
+ * Add link types (exists for backwards compatibility)
110
+ *
111
+ * @deprecated Use DI to inject to the constructor
112
+ * @param array $nameToIds
113
+ */
114
+ public function addNameToIds (array $ nameToIds ): void
102
115
{
103
116
$ this ->linkNameToId = array_merge ($ nameToIds , $ this ->linkNameToId );
104
117
}
105
118
106
119
/**
107
120
* Processes link bunches
108
121
*
122
+ * @param Product $importEntity
123
+ * @param string $linkField
109
124
* @param array $bunch
110
- * @param Link $resource
111
- * @param int $nextLinkId
125
+ * @param Link $resource
126
+ * @param int $nextLinkId
112
127
* @param array $positionAttrId
113
128
*
114
129
* @return void
@@ -194,10 +209,11 @@ function ($linkedSku) use ($sku, $importEntity) {
194
209
/**
195
210
* Check if product exists for specified SKU
196
211
*
197
- * @param string $sku
212
+ * @param Product $importEntity
213
+ * @param string $sku
198
214
* @return bool
199
215
*/
200
- private function isSkuExist (Product $ importEntity , $ sku )
216
+ private function isSkuExist (Product $ importEntity , string $ sku ): bool
201
217
{
202
218
$ sku = strtolower ($ sku );
203
219
return isset ($ importEntity ->getOldSku ()[$ sku ]);
@@ -206,8 +222,9 @@ private function isSkuExist(Product $importEntity, $sku)
206
222
/**
207
223
* Fetches Product Links
208
224
*
225
+ * @param Product $importEntity
209
226
* @param Link $resource
210
- * @param int $productId
227
+ * @param int $productId
211
228
*
212
229
* @return array
213
230
*/
@@ -248,15 +265,21 @@ private function getProductLinkedId(string $linkedSku): ?int
248
265
/**
249
266
* Saves information about product links
250
267
*
251
- * @param Link $resource
268
+ * @param Product $importEntity
269
+ * @param Link $resource
252
270
* @param array $productIds
253
271
* @param array $linkRows
254
272
* @param array $positionRows
255
273
*
256
274
* @throws LocalizedException
257
275
*/
258
- private function saveLinksData (Product $ importEntity , Link $ resource , array $ productIds , array $ linkRows , array $ positionRows )
259
- {
276
+ private function saveLinksData (
277
+ Product $ importEntity ,
278
+ Link $ resource ,
279
+ array $ productIds ,
280
+ array $ linkRows ,
281
+ array $ positionRows
282
+ ) {
260
283
$ mainTable = $ resource ->getMainTable ();
261
284
if (Import::BEHAVIOR_APPEND != $ importEntity ->getBehavior () && $ productIds ) {
262
285
$ importEntity ->getConnection ()->delete (
0 commit comments