Skip to content

Commit 179d453

Browse files
author
Oleksandr Iegorov
committed
ACP2E-766: Error during Category import 'Integrity constraint violation: 1062 Duplicate entry'
1 parent 44d8a93 commit 179d453

File tree

1 file changed

+29
-1
lines changed
  • app/code/Magento/CatalogImportExport/Model/Import/Product

1 file changed

+29
-1
lines changed

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,11 @@ protected function isValidAttributes()
310310
if ($entityTypeModel) {
311311
foreach ($this->_rowData as $attrCode => $attrValue) {
312312
$attrParams = $entityTypeModel->retrieveAttributeFromCache($attrCode);
313-
if ($attrParams) {
313+
if ($attrCode === Product::COL_CATEGORY) {
314+
if (!$this->isCategoriesValid($attrValue)) {
315+
return false;
316+
}
317+
} elseif ($attrParams) {
314318
$this->isAttributeValid($attrCode, $attrParams, $this->_rowData);
315319
}
316320
}
@@ -352,6 +356,30 @@ public function getRowScope(array $rowData)
352356
return Product::SCOPE_STORE;
353357
}
354358

359+
/**
360+
* Validate category names
361+
*
362+
* @param string $value
363+
* @return bool
364+
*/
365+
private function isCategoriesValid(string $value) : bool
366+
{
367+
$result = true;
368+
if ($value) {
369+
$values = explode($this->context->getMultipleValueSeparator(), $value);
370+
foreach ($values as $categoryName) {
371+
if ($result === true) {
372+
$result = $this->string->strlen($categoryName) < Product::DB_MAX_VARCHAR_LENGTH;
373+
}
374+
}
375+
}
376+
if ($result === false) {
377+
$this->_addMessages([RowValidatorInterface::ERROR_EXCEEDED_MAX_LENGTH]);
378+
$this->setInvalidAttribute(Product::COL_CATEGORY);
379+
}
380+
return $result;
381+
}
382+
355383
/**
356384
* Init
357385
*

0 commit comments

Comments
 (0)