@@ -140,6 +140,7 @@ private function processLinkBunches(
140
140
$ productIds = [];
141
141
$ linkRows = [];
142
142
$ positionRows = [];
143
+ $ linksToDelete = [];
143
144
144
145
$ bunch = array_filter ($ bunch , [$ importEntity , 'isRowAllowedToImport ' ], ARRAY_FILTER_USE_BOTH );
145
146
foreach ($ bunch as $ rowData ) {
@@ -156,6 +157,12 @@ function ($linkName) use ($rowData) {
156
157
);
157
158
foreach ($ linkNameToId as $ linkName => $ linkId ) {
158
159
$ linkSkus = explode ($ importEntity ->getMultipleValueSeparator (), $ rowData [$ linkName . 'sku ' ]);
160
+
161
+ //process empty value
162
+ if (!empty ($ linkSkus [0 ]) && $ linkSkus [0 ] === $ importEntity ->getEmptyAttributeValueConstant ()) {
163
+ $ linksToDelete [$ linkId ][] = $ productId ;
164
+ continue ;
165
+ }
159
166
$ linkPositions = ! empty ($ rowData [$ linkName . 'position ' ])
160
167
? explode ($ importEntity ->getMultipleValueSeparator (), $ rowData [$ linkName . 'position ' ])
161
168
: [];
@@ -203,9 +210,43 @@ function ($linkedSku) use ($sku, $importEntity) {
203
210
}
204
211
}
205
212
}
213
+
214
+ $ this ->deleteProductsLinks ($ importEntity , $ resource , $ linksToDelete );
206
215
$ this ->saveLinksData ($ importEntity , $ resource , $ productIds , $ linkRows , $ positionRows );
207
216
}
208
217
218
+ /**
219
+ * Delete links
220
+ *
221
+ * @param Product $importEntity
222
+ * @param Link $resource
223
+ * @param array $linksToDelete
224
+ * @return void
225
+ * @throws LocalizedException
226
+ */
227
+ private function deleteProductsLinks (
228
+ Product $ importEntity ,
229
+ Link $ resource ,
230
+ array $ linksToDelete
231
+ )
232
+ {
233
+ if (!empty ($ linksToDelete ) && Import::BEHAVIOR_APPEND === $ importEntity ->getBehavior ()) {
234
+ foreach ($ linksToDelete as $ linkTypeId => $ productIds ) {
235
+ if (!empty ($ productIds )) {
236
+ $ whereLinkId = $ importEntity ->getConnection ()->quoteInto ('link_type_id ' , $ linkTypeId );
237
+ $ whereProductId = $ importEntity ->getConnection ()->quoteInto (
238
+ 'product_id IN (?) ' ,
239
+ array_unique ($ productIds )
240
+ );
241
+ $ importEntity ->getConnection ()->delete (
242
+ $ resource ->getMainTable (),
243
+ $ whereLinkId . ' AND ' . $ whereProductId
244
+ );
245
+ }
246
+ }
247
+ }
248
+ }
249
+
209
250
/**
210
251
* Check if product exists for specified SKU
211
252
*
0 commit comments