@@ -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 ->_oldSku [ strtolower ($ rowData [self ::COL_SKU ])] ['entity_id ' ];
928
+ $ idsToDelete [] = $ this ->getExistSku ($ rowData [self ::COL_SKU ])['entity_id ' ];
929
929
}
930
930
}
931
931
if ($ idsToDelete ) {
@@ -1115,7 +1115,7 @@ protected function _prepareRowForDb(array $rowData)
1115
1115
1116
1116
$ lastSku = $ rowData [self ::COL_SKU ];
1117
1117
1118
- if (isset ( $ this ->_oldSku [ strtolower ($ lastSku)] )) {
1118
+ if ($ this ->isSkuExist ($ lastSku )) {
1119
1119
$ newSku = $ this ->skuProcessor ->getNewSku ($ lastSku );
1120
1120
$ rowData [self ::COL_ATTR_SET ] = $ newSku ['attr_set_code ' ];
1121
1121
$ rowData [self ::COL_TYPE ] = $ newSku ['type_id ' ];
@@ -1187,15 +1187,14 @@ protected function _saveLinks()
1187
1187
$ linkedSku = trim ($ linkedSku );
1188
1188
if ((!is_null (
1189
1189
$ this ->skuProcessor ->getNewSku ($ linkedSku )
1190
- ) || isset (
1191
- $ this ->_oldSku [$ linkedSku ]
1192
- )) && $ linkedSku != $ sku
1190
+ ) || $ this ->isSkuExist ($ linkedSku )
1191
+ ) && strtolower ($ linkedSku ) != strtolower ($ sku )
1193
1192
) {
1194
1193
$ newSku = $ this ->skuProcessor ->getNewSku ($ linkedSku );
1195
1194
if (!empty ($ newSku )) {
1196
1195
$ linkedId = $ newSku ['entity_id ' ];
1197
1196
} else {
1198
- $ linkedId = $ this ->_oldSku [ strtolower ($ linkedSku )] ['entity_id ' ];
1197
+ $ linkedId = $ this ->getExistSku ($ linkedSku )['entity_id ' ];
1199
1198
}
1200
1199
1201
1200
if ($ linkedId == null ) {
@@ -1582,7 +1581,7 @@ protected function _saveProducts()
1582
1581
}
1583
1582
1584
1583
// 1. Entity phase
1585
- if (isset ( $ this ->_oldSku [ strtolower ($ rowSku)] )) {
1584
+ if ($ this ->isSkuExist ($ rowSku )) {
1586
1585
// existing row
1587
1586
if (isset ($ rowData ['attribute_set_code ' ])) {
1588
1587
$ attributeSetId = $ this ->catalogConfig ->getAttributeSetId (
@@ -1606,7 +1605,7 @@ protected function _saveProducts()
1606
1605
$ entityRowsUp [] = [
1607
1606
'updated_at ' => (new \DateTime ())->format (DateTime::DATETIME_PHP_FORMAT ),
1608
1607
'attribute_set_id ' => $ attributeSetId ,
1609
- $ this ->getProductEntityLinkField () => $ this ->_oldSku [ strtolower ($ rowSku )] [$ this ->getProductEntityLinkField ()]
1608
+ $ this ->getProductEntityLinkField () => $ this ->getExistSku ($ rowSku )[$ this ->getProductEntityLinkField ()]
1610
1609
];
1611
1610
} else {
1612
1611
if (!$ productLimit || $ productsQty < $ productLimit ) {
@@ -1770,7 +1769,7 @@ protected function _saveProducts()
1770
1769
1771
1770
$ rowData = $ productTypeModel ->prepareAttributesWithDefaultValueForSave (
1772
1771
$ rowData ,
1773
- !isset ( $ this ->_oldSku [ $ rowSku] )
1772
+ !$ this ->isSkuExist ( $ rowSku )
1774
1773
);
1775
1774
$ product = $ this ->_proxyProdFactory ->create (['data ' => $ rowData ]);
1776
1775
@@ -1812,7 +1811,7 @@ protected function _saveProducts()
1812
1811
} elseif (self ::SCOPE_STORE == $ attribute ->getIsGlobal ()) {
1813
1812
$ storeIds = [$ rowStore ];
1814
1813
}
1815
- if (!isset ( $ this ->_oldSku [ $ rowSku] )) {
1814
+ if (!$ this ->isSkuExist ( $ rowSku )) {
1816
1815
$ storeIds [] = 0 ;
1817
1816
}
1818
1817
}
@@ -2192,7 +2191,7 @@ protected function _saveStockItem()
2192
2191
}
2193
2192
2194
2193
$ row = [];
2195
- $ sku = strtolower ( $ rowData [self ::COL_SKU ]) ;
2194
+ $ sku = $ rowData [self ::COL_SKU ];
2196
2195
$ row ['product_id ' ] = $ this ->skuProcessor ->getNewSku ($ sku )['entity_id ' ];
2197
2196
$ productIdsToReindex [] = $ row ['product_id ' ];
2198
2197
@@ -2387,13 +2386,13 @@ public function validateRow(array $rowData, $rowNum)
2387
2386
2388
2387
// BEHAVIOR_DELETE and BEHAVIOR_REPLACE use specific validation logic
2389
2388
if (Import::BEHAVIOR_REPLACE == $ this ->getBehavior ()) {
2390
- if (self ::SCOPE_DEFAULT == $ rowScope && !isset ( $ this ->_oldSku [ $ sku] )) {
2389
+ if (self ::SCOPE_DEFAULT == $ rowScope && !$ this ->isSkuExist ( $ sku )) {
2391
2390
$ this ->addRowError (ValidatorInterface::ERROR_SKU_NOT_FOUND_FOR_DELETE , $ rowNum );
2392
2391
return false ;
2393
2392
}
2394
2393
}
2395
2394
if (Import::BEHAVIOR_DELETE == $ this ->getBehavior ()) {
2396
- if (self ::SCOPE_DEFAULT == $ rowScope && !isset ( $ this ->_oldSku [ $ sku] )) {
2395
+ if (self ::SCOPE_DEFAULT == $ rowScope && !$ this ->isSkuExist ( $ sku )) {
2397
2396
$ this ->addRowError (ValidatorInterface::ERROR_SKU_NOT_FOUND_FOR_DELETE , $ rowNum );
2398
2397
return false ;
2399
2398
}
@@ -2406,9 +2405,9 @@ public function validateRow(array $rowData, $rowNum)
2406
2405
}
2407
2406
}
2408
2407
2409
- if (null === $ rowData [ self :: COL_SKU ] ) {
2408
+ if (null === $ sku ) {
2410
2409
$ this ->addRowError (ValidatorInterface::ERROR_SKU_IS_EMPTY , $ rowNum );
2411
- } elseif (false === $ rowData [ self :: COL_SKU ] ) {
2410
+ } elseif (false === $ sku ) {
2412
2411
$ this ->addRowError (ValidatorInterface::ERROR_ROW_IS_ORPHAN , $ rowNum );
2413
2412
} elseif (self ::SCOPE_STORE == $ rowScope
2414
2413
&& !$ this ->storeResolver ->getStoreCodeToId ($ rowData [self ::COL_STORE ])
@@ -2419,10 +2418,10 @@ public function validateRow(array $rowData, $rowNum)
2419
2418
// SKU is specified, row is SCOPE_DEFAULT, new product block begins
2420
2419
$ this ->_processedEntitiesCount ++;
2421
2420
2422
- if (isset ( $ this ->_oldSku [ $ sku] ) && Import::BEHAVIOR_REPLACE !== $ this ->getBehavior ()) {
2421
+ if ($ this ->isSkuExist ( $ sku ) && Import::BEHAVIOR_REPLACE !== $ this ->getBehavior ()) {
2423
2422
// can we get all necessary data from existent DB product?
2424
2423
// check for supported type of existing product
2425
- if (isset ($ this ->_productTypeModels [$ this ->_oldSku [ $ sku] ['type_id ' ]])) {
2424
+ if (isset ($ this ->_productTypeModels [$ this ->getExistSku ( $ sku) ['type_id ' ]])) {
2426
2425
$ this ->skuProcessor ->addNewSku (
2427
2426
$ sku ,
2428
2427
$ this ->prepareNewSkuData ($ sku )
@@ -2471,7 +2470,7 @@ public function validateRow(array $rowData, $rowNum)
2471
2470
$ rowAttributesValid = $ productTypeValidator ->isRowValid (
2472
2471
$ rowData ,
2473
2472
$ rowNum ,
2474
- !(isset ( $ this ->_oldSku [ $ sku] ) && Import::BEHAVIOR_REPLACE !== $ this ->getBehavior ())
2473
+ !($ this ->isSkuExist ( $ sku ) && Import::BEHAVIOR_REPLACE !== $ this ->getBehavior ())
2475
2474
);
2476
2475
if (!$ rowAttributesValid && self ::SCOPE_DEFAULT == $ rowScope ) {
2477
2476
// mark SCOPE_DEFAULT row as invalid for future child rows if product not in DB already
@@ -2534,11 +2533,11 @@ private function isNeedToValidateUrlKey($rowData)
2534
2533
private function prepareNewSkuData ($ sku )
2535
2534
{
2536
2535
$ data = [];
2537
- foreach ($ this ->_oldSku [ $ sku] as $ key => $ value ) {
2536
+ foreach ($ this ->getExistSku ( $ sku) as $ key => $ value ) {
2538
2537
$ data [$ key ] = $ value ;
2539
2538
}
2540
2539
2541
- $ data ['attr_set_code ' ] = $ this ->_attrSetIdToName [$ this ->_oldSku [ $ sku] ['attr_set_id ' ]];
2540
+ $ data ['attr_set_code ' ] = $ this ->_attrSetIdToName [$ this ->getExistSku ( $ sku) ['attr_set_id ' ]];
2542
2541
2543
2542
return $ data ;
2544
2543
}
@@ -2929,4 +2928,23 @@ private function parseMultipleValues($labelRow)
2929
2928
$ this ->getMultipleValueSeparator ()
2930
2929
);
2931
2930
}
2931
+
2932
+ /**
2933
+ * @param $sku
2934
+ * @return bool
2935
+ */
2936
+ private function isSkuExist ($ sku )
2937
+ {
2938
+ $ sku = strtolower ($ sku );
2939
+ return isset ($ this ->_oldSku [$ sku ]);
2940
+ }
2941
+
2942
+ /**
2943
+ * @param $sku
2944
+ * @return mixed
2945
+ */
2946
+ private function getExistSku ($ sku )
2947
+ {
2948
+ return $ this ->_oldSku [strtolower ($ sku )];
2949
+ }
2932
2950
}
0 commit comments