@@ -925,7 +925,7 @@ protected function _deleteProducts()
925
925
926
926
foreach ($ bunch as $ rowNum => $ rowData ) {
927
927
if ($ this ->validateRow ($ rowData , $ rowNum ) && self ::SCOPE_DEFAULT == $ this ->getRowScope ($ rowData )) {
928
- $ idsToDelete [] = $ this ->getExistSku ($ rowData [self ::COL_SKU ])['entity_id ' ];
928
+ $ idsToDelete [] = $ this ->getExistingSku ($ rowData [self ::COL_SKU ])['entity_id ' ];
929
929
}
930
930
}
931
931
if ($ idsToDelete ) {
@@ -1185,16 +1185,14 @@ protected function _saveLinks()
1185
1185
: [];
1186
1186
foreach ($ linkSkus as $ linkedKey => $ linkedSku ) {
1187
1187
$ linkedSku = trim ($ linkedSku );
1188
- if ((!is_null (
1189
- $ this ->skuProcessor ->getNewSku ($ linkedSku )
1190
- ) || $ this ->isSkuExist ($ linkedSku )
1191
- ) && strtolower ($ linkedSku ) != strtolower ($ sku )
1188
+ if ((!is_null ($ this ->skuProcessor ->getNewSku ($ linkedSku )) || $ this ->isSkuExist ($ linkedSku ))
1189
+ && strcasecmp ($ linkedSku , $ sku ) !== 0
1192
1190
) {
1193
1191
$ newSku = $ this ->skuProcessor ->getNewSku ($ linkedSku );
1194
1192
if (!empty ($ newSku )) {
1195
1193
$ linkedId = $ newSku ['entity_id ' ];
1196
1194
} else {
1197
- $ linkedId = $ this ->getExistSku ($ linkedSku )['entity_id ' ];
1195
+ $ linkedId = $ this ->getExistingSku ($ linkedSku )['entity_id ' ];
1198
1196
}
1199
1197
1200
1198
if ($ linkedId == null ) {
@@ -1454,7 +1452,7 @@ protected function getExistingImages($bunch)
1454
1452
}
1455
1453
1456
1454
$ this ->initMediaGalleryResources ();
1457
- $ productSKUs = array_map ('strtolower ' , array_column ($ bunch , self ::COL_SKU ));
1455
+ $ productSKUs = array_map ('strval ' , array_column ($ bunch , self ::COL_SKU ));
1458
1456
$ select = $ this ->_connection ->select ()->from (
1459
1457
['mg ' => $ this ->mediaGalleryTableName ],
1460
1458
['value ' => 'mg.value ' ]
@@ -1536,6 +1534,7 @@ protected function _saveProducts()
1536
1534
$ priceIsGlobal = $ this ->_catalogData ->isPriceGlobal ();
1537
1535
$ productLimit = null ;
1538
1536
$ productsQty = null ;
1537
+ $ entityLinkField = $ this ->getProductEntityLinkField ();
1539
1538
1540
1539
while ($ bunch = $ this ->_dataSourceModel ->getNextBunch ()) {
1541
1540
$ entityRowsIn = [];
@@ -1605,14 +1604,14 @@ protected function _saveProducts()
1605
1604
$ entityRowsUp [] = [
1606
1605
'updated_at ' => (new \DateTime ())->format (DateTime::DATETIME_PHP_FORMAT ),
1607
1606
'attribute_set_id ' => $ attributeSetId ,
1608
- $ this -> getProductEntityLinkField () => $ this ->getExistSku ($ rowSku )[$ this -> getProductEntityLinkField () ]
1607
+ $ entityLinkField => $ this ->getExistingSku ($ rowSku )[$ entityLinkField ]
1609
1608
];
1610
1609
} else {
1611
1610
if (!$ productLimit || $ productsQty < $ productLimit ) {
1612
1611
$ entityRowsIn [$ rowSku ] = [
1613
1612
'attribute_set_id ' => $ this ->skuProcessor ->getNewSku ($ rowSku )['attr_set_id ' ],
1614
1613
'type_id ' => $ this ->skuProcessor ->getNewSku ($ rowSku )['type_id ' ],
1615
- 'sku ' => $ rowData [ self :: COL_SKU ] ,
1614
+ 'sku ' => $ rowSku ,
1616
1615
'has_options ' => isset ($ rowData ['has_options ' ]) ? $ rowData ['has_options ' ] : 0 ,
1617
1616
'created_at ' => (new \DateTime ())->format (DateTime::DATETIME_PHP_FORMAT ),
1618
1617
'updated_at ' => (new \DateTime ())->format (DateTime::DATETIME_PHP_FORMAT ),
@@ -2382,7 +2381,7 @@ public function validateRow(array $rowData, $rowNum)
2382
2381
$ this ->_validatedRows [$ rowNum ] = true ;
2383
2382
2384
2383
$ rowScope = $ this ->getRowScope ($ rowData );
2385
- $ sku = strtolower ( $ rowData [self ::COL_SKU ]) ;
2384
+ $ sku = $ rowData [self ::COL_SKU ];
2386
2385
2387
2386
// BEHAVIOR_DELETE and BEHAVIOR_REPLACE use specific validation logic
2388
2387
if (Import::BEHAVIOR_REPLACE == $ this ->getBehavior ()) {
@@ -2421,15 +2420,13 @@ public function validateRow(array $rowData, $rowNum)
2421
2420
if ($ this ->isSkuExist ($ sku ) && Import::BEHAVIOR_REPLACE !== $ this ->getBehavior ()) {
2422
2421
// can we get all necessary data from existent DB product?
2423
2422
// check for supported type of existing product
2424
- if (isset ($ this ->_productTypeModels [$ this ->getExistSku ($ sku )['type_id ' ]])) {
2423
+ if (isset ($ this ->_productTypeModels [$ this ->getExistingSku ($ sku )['type_id ' ]])) {
2425
2424
$ this ->skuProcessor ->addNewSku (
2426
2425
$ sku ,
2427
2426
$ this ->prepareNewSkuData ($ sku )
2428
2427
);
2429
2428
} else {
2430
2429
$ this ->addRowError (ValidatorInterface::ERROR_TYPE_UNSUPPORTED , $ rowNum );
2431
- // child rows of legacy products with unsupported types are orphans
2432
- $ sku = false ;
2433
2430
}
2434
2431
} else {
2435
2432
// validate new product type and attribute set
@@ -2454,10 +2451,6 @@ public function validateRow(array $rowData, $rowNum)
2454
2451
]
2455
2452
);
2456
2453
}
2457
- if ($ this ->getErrorAggregator ()->isRowInvalid ($ rowNum )) {
2458
- // mark SCOPE_DEFAULT row as invalid for future child rows if product not in DB already
2459
- $ sku = false ;
2460
- }
2461
2454
}
2462
2455
2463
2456
if (!$ this ->getErrorAggregator ()->isRowInvalid ($ rowNum )) {
@@ -2466,16 +2459,13 @@ public function validateRow(array $rowData, $rowNum)
2466
2459
$ rowData [self ::COL_ATTR_SET ] = $ newSku ['attr_set_code ' ];
2467
2460
2468
2461
/** @var \Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType $productTypeValidator */
2462
+ // isRowValid can add error to general errors pull if row is invalid
2469
2463
$ productTypeValidator = $ this ->_productTypeModels [$ newSku ['type_id ' ]];
2470
- $ rowAttributesValid = $ productTypeValidator ->isRowValid (
2464
+ $ productTypeValidator ->isRowValid (
2471
2465
$ rowData ,
2472
2466
$ rowNum ,
2473
2467
!($ this ->isSkuExist ($ sku ) && Import::BEHAVIOR_REPLACE !== $ this ->getBehavior ())
2474
2468
);
2475
- if (!$ rowAttributesValid && self ::SCOPE_DEFAULT == $ rowScope ) {
2476
- // mark SCOPE_DEFAULT row as invalid for future child rows if product not in DB already
2477
- $ sku = false ;
2478
- }
2479
2469
}
2480
2470
// validate custom options
2481
2471
$ this ->getOptionEntity ()->validateRow ($ rowData , $ rowNum );
@@ -2533,11 +2523,11 @@ private function isNeedToValidateUrlKey($rowData)
2533
2523
private function prepareNewSkuData ($ sku )
2534
2524
{
2535
2525
$ data = [];
2536
- foreach ($ this ->getExistSku ($ sku ) as $ key => $ value ) {
2526
+ foreach ($ this ->getExistingSku ($ sku ) as $ key => $ value ) {
2537
2527
$ data [$ key ] = $ value ;
2538
2528
}
2539
2529
2540
- $ data ['attr_set_code ' ] = $ this ->_attrSetIdToName [$ this ->getExistSku ($ sku )['attr_set_id ' ]];
2530
+ $ data ['attr_set_code ' ] = $ this ->_attrSetIdToName [$ this ->getExistingSku ($ sku )['attr_set_id ' ]];
2541
2531
2542
2532
return $ data ;
2543
2533
}
@@ -2930,7 +2920,9 @@ private function parseMultipleValues($labelRow)
2930
2920
}
2931
2921
2932
2922
/**
2933
- * @param $sku
2923
+ * Check if product exists for specified SKU
2924
+ *
2925
+ * @param string $sku
2934
2926
* @return bool
2935
2927
*/
2936
2928
private function isSkuExist ($ sku )
@@ -2940,10 +2932,12 @@ private function isSkuExist($sku)
2940
2932
}
2941
2933
2942
2934
/**
2943
- * @param $sku
2944
- * @return mixed
2935
+ * Get existing product data for specified SKU
2936
+ *
2937
+ * @param string $sku
2938
+ * @return array
2945
2939
*/
2946
- private function getExistSku ($ sku )
2940
+ private function getExistingSku ($ sku )
2947
2941
{
2948
2942
return $ this ->_oldSku [strtolower ($ sku )];
2949
2943
}
0 commit comments