Skip to content

Commit b7ea348

Browse files
committed
MAGETWO-58242: Issue with an Import Export when Attribute Changes
2 parents 12602c4 + 7a3e952 commit b7ea348

File tree

2 files changed

+38
-15
lines changed
  • app/code/Magento/CatalogImportExport/Model/Import
  • dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import

2 files changed

+38
-15
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
273273
ValidatorInterface::ERROR_MEDIA_PATH_NOT_ACCESSIBLE => 'Imported resource (image) does not exist in the local media storage',
274274
ValidatorInterface::ERROR_MEDIA_URL_NOT_ACCESSIBLE => 'Imported resource (image) could not be downloaded from external resource due to timeout or access permissions',
275275
ValidatorInterface::ERROR_INVALID_WEIGHT => 'Product weight is invalid',
276-
ValidatorInterface::ERROR_DUPLICATE_URL_KEY => 'Specified URL key already exists',
276+
ValidatorInterface::ERROR_DUPLICATE_URL_KEY => 'Url key: \'%s\' was already generated for an item with the SKU: \'%s\'. You need to specify the unique URL key manually'
277277
];
278278

279279
/**
@@ -2367,7 +2367,17 @@ public function validateRow(array $rowData, $rowNum)
23672367
$this->urlKeys[$storeId][$urlPath] = $rowData[self::COL_SKU];
23682368
$this->rowNumbers[$storeId][$urlPath] = $rowNum;
23692369
} else {
2370-
$this->addRowError(ValidatorInterface::ERROR_DUPLICATE_URL_KEY, $rowNum);
2370+
$message = sprintf(
2371+
$this->retrieveMessageTemplate(ValidatorInterface::ERROR_DUPLICATE_URL_KEY),
2372+
$urlKey,
2373+
$this->urlKeys[$storeId][$urlPath]
2374+
);
2375+
$this->addRowError(
2376+
ValidatorInterface::ERROR_DUPLICATE_URL_KEY,
2377+
$rowNum,
2378+
$rowData[self::COL_NAME],
2379+
$message
2380+
);
23712381
}
23722382
}
23732383
}

dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ProductTest.php

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Magento\Framework\App\Bootstrap;
2121
use Magento\Framework\App\Filesystem\DirectoryList;
2222
use Magento\ImportExport\Model\Import;
23+
use Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface;
2324

2425
/**
2526
* Class ProductTest
@@ -1050,9 +1051,9 @@ protected function loadCategoryByName($categoryName)
10501051
* @magentoAppIsolation enabled
10511052
* @dataProvider validateUrlKeysDataProvider
10521053
* @param $importFile string
1053-
* @param $errorsCount int
1054+
* @param $expectedErrors array
10541055
*/
1055-
public function testValidateUrlKeys($importFile, $errorsCount)
1056+
public function testValidateUrlKeys($importFile, $expectedErrors)
10561057
{
10571058
$filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
10581059
\Magento\Framework\Filesystem::class
@@ -1066,19 +1067,16 @@ public function testValidateUrlKeys($importFile, $errorsCount)
10661067
'directory' => $directory
10671068
]
10681069
);
1070+
/** @var \Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface $errors */
10691071
$errors = $this->_model->setParameters(
10701072
['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND, 'entity' => 'catalog_product']
10711073
)->setSource(
10721074
$source
10731075
)->validateData();
1074-
1075-
$this->assertTrue($errors->getErrorsCount() == $errorsCount);
1076-
if ($errorsCount >= 1) {
1077-
$this->assertEquals(
1078-
"Specified URL key already exists",
1079-
$errors->getErrorByRowNumber(1)[0]->getErrorMessage()
1080-
);
1081-
}
1076+
$this->assertEquals(
1077+
$expectedErrors[RowValidatorInterface::ERROR_DUPLICATE_URL_KEY],
1078+
count($errors->getErrorsByCode([RowValidatorInterface::ERROR_DUPLICATE_URL_KEY]))
1079+
);
10821080
}
10831081

10841082
/**
@@ -1087,9 +1085,24 @@ public function testValidateUrlKeys($importFile, $errorsCount)
10871085
public function validateUrlKeysDataProvider()
10881086
{
10891087
return [
1090-
['products_to_check_valid_url_keys.csv', 0],
1091-
['products_to_check_duplicated_url_keys.csv', 2],
1092-
['products_to_check_duplicated_names.csv' , 1]
1088+
[
1089+
'products_to_check_valid_url_keys.csv',
1090+
[
1091+
RowValidatorInterface::ERROR_DUPLICATE_URL_KEY => 0
1092+
]
1093+
],
1094+
[
1095+
'products_to_check_duplicated_url_keys.csv',
1096+
[
1097+
RowValidatorInterface::ERROR_DUPLICATE_URL_KEY => 2
1098+
]
1099+
],
1100+
[
1101+
'products_to_check_duplicated_names.csv' ,
1102+
[
1103+
RowValidatorInterface::ERROR_DUPLICATE_URL_KEY => 1
1104+
]
1105+
]
10931106
];
10941107
}
10951108

0 commit comments

Comments
 (0)