@@ -1316,7 +1316,8 @@ protected function _saveProducts()
1316
1316
1317
1317
// 2. Product-to-Website phase
1318
1318
if (!empty ($ rowData [self ::COL_PRODUCT_WEBSITES ])) {
1319
- $ websites [$ rowSku ][$ this ->storeResolver ->getWebsiteCodeToId ($ rowData [self ::COL_PRODUCT_WEBSITES ])] = true ;
1319
+ $ websiteId = $ this ->storeResolver ->getWebsiteCodeToId ($ rowData [self ::COL_PRODUCT_WEBSITES ]);
1320
+ $ websites [$ rowSku ][$ websiteId ] = true ;
1320
1321
}
1321
1322
1322
1323
// 3. Categories phase
@@ -1353,28 +1354,43 @@ protected function _saveProducts()
1353
1354
}
1354
1355
1355
1356
// 5. Media gallery phase
1356
- $ dispertionPath = \Magento \Framework \File \Uploader::getDispretionPath ($ rowData [self ::COL_MEDIA_IMAGE ]);
1357
- $ imageName = preg_replace ('/[^a-z0-9\._-]+/i ' ,'' , $ rowData [self ::COL_MEDIA_IMAGE ]);
1358
- $ fullDispertionPath = $ dispertionPath .'/ ' .$ imageName ;
1357
+
1358
+ $ fullDispersionPath = '' ;
1359
1359
$ imageIsSet = null ;
1360
1360
$ imageFromProduct = null ;
1361
1361
$ imageInProductIsSet = null ;
1362
- foreach ($ this ->cachedImages as $ image ) {
1363
- if ($ image ['sku ' ] == $ rowData [self ::COL_SKU ] && preg_replace ('/_[0-9]+/ ' , '' , $ image ['value ' ]) == $ fullDispertionPath ) {
1364
- $ imageInProductIsSet = true ;
1365
- $ imageFromProduct = preg_replace ('/_[0-9]+/ ' , '' , $ image ['value ' ]);
1366
- break ;
1367
- } elseif (in_array ($ fullDispertionPath , $ image )) {
1368
- $ imageIsSet = true ;
1369
- break ;
1362
+ if (!empty ($ rowData [self ::COL_MEDIA_IMAGE ])) {
1363
+ $ dispersionPath =
1364
+ \Magento \Framework \File \Uploader::getDispretionPath ($ rowData [self ::COL_MEDIA_IMAGE ]);
1365
+ $ imageName = preg_replace ('/[^a-z0-9\._-]+/i ' , '' , $ rowData [self ::COL_MEDIA_IMAGE ]);
1366
+ $ fullDispersionPath = $ dispersionPath . '/ ' . $ imageName ;
1367
+ foreach ($ this ->cachedImages as $ image ) {
1368
+ if (($ image ['sku ' ] == $ rowData [self ::COL_SKU ])
1369
+ && (preg_replace ('/_[0-9]+/ ' , '' , $ image ['value ' ]) == $ fullDispersionPath )
1370
+ ) {
1371
+ $ imageInProductIsSet = true ;
1372
+ $ imageFromProduct = preg_replace ('/_[0-9]+/ ' , '' , $ image ['value ' ]);
1373
+ break ;
1374
+ } elseif (in_array ($ fullDispersionPath , $ image )) {
1375
+ $ imageIsSet = true ;
1376
+ break ;
1377
+ }
1370
1378
}
1371
1379
}
1372
- if (($ imageInProductIsSet && $ imageFromProduct != $ fullDispertionPath ) || (!isset ($ imageIsSet ) && !isset ($ imageInProductIsSet ))) {
1380
+ if (($ imageInProductIsSet && ($ imageFromProduct != $ fullDispersionPath ))
1381
+ || (!isset ($ imageIsSet ) && !isset ($ imageInProductIsSet ))
1382
+ ) {
1373
1383
$ mediaGalleryImages = array ();
1374
1384
$ mediaGalleryLabels = array ();
1375
1385
if (!empty ($ rowData [self ::COL_MEDIA_IMAGE ])) {
1376
- $ mediaGalleryImages = explode ($ this ->getMultipleValueSeparator (), $ rowData [self ::COL_MEDIA_IMAGE ]);
1377
- $ mediaGalleryLabels = isset ($ rowData ['_media_image_label ' ]) ? explode ($ this ->getMultipleValueSeparator (), $ rowData ['_media_image_label ' ]) : array ();
1386
+ $ mediaGalleryImages =
1387
+ explode ($ this ->getMultipleValueSeparator (), $ rowData [self ::COL_MEDIA_IMAGE ]);
1388
+ if (isset ($ rowData ['_media_image_label ' ])) {
1389
+ $ mediaGalleryLabels =
1390
+ explode ($ this ->getMultipleValueSeparator (), $ rowData ['_media_image_label ' ]);
1391
+ } else {
1392
+ $ mediaGalleryLabels = [];
1393
+ }
1378
1394
if (count ($ mediaGalleryLabels ) > count ($ mediaGalleryImages )) {
1379
1395
$ mediaGalleryLabels = array_slice ($ mediaGalleryLabels , 0 , count ($ mediaGalleryImages ));
1380
1396
} elseif (count ($ mediaGalleryLabels ) < count ($ mediaGalleryImages )) {
@@ -1383,9 +1399,15 @@ protected function _saveProducts()
1383
1399
}
1384
1400
1385
1401
foreach ($ this ->_imagesArrayKeys as $ imageCol ) {
1386
- if (!empty ($ rowData [$ imageCol ]) && ($ imageCol != self ::COL_MEDIA_IMAGE ) && !in_array ($ rowData [$ imageCol ], $ mediaGalleryImages )) {
1402
+ if (!empty ($ rowData [$ imageCol ])
1403
+ && ($ imageCol != self ::COL_MEDIA_IMAGE )
1404
+ && !in_array ($ rowData [$ imageCol ], $ mediaGalleryImages )) {
1387
1405
$ mediaGalleryImages [] = $ rowData [$ imageCol ];
1388
- $ mediaGalleryLabels [] = isset ($ rowData [$ imageCol . '_label ' ]) ? $ rowData [$ imageCol . '_label ' ] : '' ;
1406
+ if (isset ($ mediaGalleryLabels )) {
1407
+ $ mediaGalleryLabels [] = isset ($ rowData [$ imageCol . '_label ' ]);
1408
+ } else {
1409
+ $ mediaGalleryLabels [] = '' ;
1410
+ }
1389
1411
}
1390
1412
}
1391
1413
@@ -1418,12 +1440,18 @@ protected function _saveProducts()
1418
1440
];
1419
1441
}
1420
1442
}
1421
- } elseif ($ imageInProductIsSet && $ imageFromProduct == $ fullDispertionPath ) {
1443
+ } elseif ($ imageInProductIsSet && $ imageFromProduct == $ fullDispersionPath ) {
1422
1444
$ mediaGalleryImages = array ();
1423
1445
$ mediaGalleryLabels = array ();
1424
1446
if (!empty ($ rowData [self ::COL_MEDIA_IMAGE ])) {
1425
- $ mediaGalleryImages = explode ($ this ->getMultipleValueSeparator (), $ rowData [self ::COL_MEDIA_IMAGE ]);
1426
- $ mediaGalleryLabels = isset ($ rowData ['_media_image_label ' ]) ? explode ($ this ->getMultipleValueSeparator (), $ rowData ['_media_image_label ' ]) : array ();
1447
+ $ mediaGalleryImages =
1448
+ explode ($ this ->getMultipleValueSeparator (), $ rowData [self ::COL_MEDIA_IMAGE ]);
1449
+ if (isset ($ rowData ['_media_image_label ' ])) {
1450
+ $ mediaGalleryLabels =
1451
+ explode ($ this ->getMultipleValueSeparator (), $ rowData ['_media_image_label ' ]);
1452
+ } else {
1453
+ $ mediaGalleryLabels = array ();
1454
+ }
1427
1455
if (count ($ mediaGalleryLabels ) > count ($ mediaGalleryImages )) {
1428
1456
$ mediaGalleryLabels = array_slice ($ mediaGalleryLabels , 0 , count ($ mediaGalleryImages ));
1429
1457
} elseif (count ($ mediaGalleryLabels ) < count ($ mediaGalleryImages )) {
@@ -1432,9 +1460,15 @@ protected function _saveProducts()
1432
1460
}
1433
1461
1434
1462
foreach ($ this ->_imagesArrayKeys as $ imageCol ) {
1435
- if (!empty ($ rowData [$ imageCol ]) && ($ imageCol != self ::COL_MEDIA_IMAGE ) && !in_array ($ rowData [$ imageCol ], $ mediaGalleryImages )) {
1463
+ if (!empty ($ rowData [$ imageCol ])
1464
+ && ($ imageCol != self ::COL_MEDIA_IMAGE )
1465
+ && !in_array ($ rowData [$ imageCol ], $ mediaGalleryImages )) {
1436
1466
$ mediaGalleryImages [] = $ rowData [$ imageCol ];
1437
- $ mediaGalleryLabels [] = isset ($ rowData [$ imageCol . '_label ' ]) ? $ rowData [$ imageCol . '_label ' ] : '' ;
1467
+ if (isset ($ rowData [$ imageCol . '_label ' ])) {
1468
+ $ mediaGalleryLabels [] = $ rowData [$ imageCol . '_label ' ];
1469
+ } else {
1470
+ $ mediaGalleryLabels [] = '' ;
1471
+ }
1438
1472
}
1439
1473
}
1440
1474
@@ -1450,7 +1484,6 @@ protected function _saveProducts()
1450
1484
}
1451
1485
} else {
1452
1486
$ this ->addRowError (__ ("Image already exists for '%s' " ), $ rowNum , self ::COL_MEDIA_IMAGE );
1453
-
1454
1487
}
1455
1488
1456
1489
// 6. Attributes phase
@@ -1479,7 +1512,8 @@ protected function _saveProducts()
1479
1512
1480
1513
$ productTypeModel = $ this ->_productTypeModels [$ productType ];
1481
1514
if (!empty ($ rowData ['tax_class_name ' ])) {
1482
- $ rowData ['tax_class_id ' ] = $ this ->taxClassProcessor ->upsertTaxClass ($ rowData ['tax_class_name ' ], $ productTypeModel );
1515
+ $ rowData ['tax_class_id ' ] =
1516
+ $ this ->taxClassProcessor ->upsertTaxClass ($ rowData ['tax_class_name ' ], $ productTypeModel );
1483
1517
}
1484
1518
1485
1519
if ($ this ->getBehavior () == \Magento \ImportExport \Model \Import::BEHAVIOR_APPEND ||
@@ -1563,7 +1597,10 @@ protected function _saveProducts()
1563
1597
$ attributes
1564
1598
);
1565
1599
1566
- $ this ->_eventManager ->dispatch ('catalog_product_import_bunch_save_after ' , ['adapter ' => $ this , 'bunch ' => $ bunch ]);
1600
+ $ this ->_eventManager ->dispatch (
1601
+ 'catalog_product_import_bunch_save_after ' ,
1602
+ ['adapter ' => $ this , 'bunch ' => $ bunch ]
1603
+ );
1567
1604
}
1568
1605
return $ this ;
1569
1606
}
0 commit comments