Skip to content

Commit 7565dd8

Browse files
author
Sergey Shvets
committed
MAGETWO-97345: [Magento Cloud] Import doesn't work with skip error entries
1 parent d6f672a commit 7565dd8

File tree

1 file changed

+25
-17
lines changed
  • app/code/Magento/CatalogImportExport/Model/Import

1 file changed

+25
-17
lines changed

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

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2432,6 +2432,7 @@ public function getRowScope(array $rowData)
24322432
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
24332433
* @SuppressWarnings(PHPMD.NPathComplexity)
24342434
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
2435+
* @throws \Zend_Validate_Exception
24352436
*/
24362437
public function validateRow(array $rowData, $rowNum)
24372438
{
@@ -2459,25 +2460,23 @@ public function validateRow(array $rowData, $rowNum)
24592460
return true;
24602461
}
24612462

2463+
// if product doesn't exist, need to throw critical error else all errors should be not critical.
2464+
$errorLevel = $this->getValidationErrorLevel();
2465+
24622466
if (!$this->validator->isValid($rowData)) {
24632467
foreach ($this->validator->getMessages() as $message) {
2464-
$this->skipRow(
2465-
$rowNum,
2466-
$message,
2467-
ProcessingError::ERROR_LEVEL_NOT_CRITICAL,
2468-
$this->validator->getInvalidAttribute()
2469-
);
2468+
$this->skipRow($rowNum, $message, $errorLevel, $this->validator->getInvalidAttribute());
24702469
}
24712470
}
24722471

24732472
if (null === $sku) {
2474-
$this->skipRow($rowNum, ValidatorInterface::ERROR_SKU_IS_EMPTY);
2473+
$this->skipRow($rowNum, ValidatorInterface::ERROR_SKU_IS_EMPTY, $errorLevel);
24752474
} elseif (false === $sku) {
2476-
$this->skipRow($rowNum, ValidatorInterface::ERROR_ROW_IS_ORPHAN);
2475+
$this->skipRow($rowNum, ValidatorInterface::ERROR_ROW_IS_ORPHAN, $errorLevel);
24772476
} elseif (self::SCOPE_STORE == $rowScope
24782477
&& !$this->storeResolver->getStoreCodeToId($rowData[self::COL_STORE])
24792478
) {
2480-
$this->skipRow($rowNum, ValidatorInterface::ERROR_INVALID_STORE);
2479+
$this->skipRow($rowNum, ValidatorInterface::ERROR_INVALID_STORE, $errorLevel);
24812480
}
24822481

24832482
// SKU is specified, row is SCOPE_DEFAULT, new product block begins
@@ -2492,15 +2491,15 @@ public function validateRow(array $rowData, $rowNum)
24922491
$this->prepareNewSkuData($sku)
24932492
);
24942493
} else {
2495-
$this->skipRow($rowNum, ValidatorInterface::ERROR_TYPE_UNSUPPORTED);
2494+
$this->skipRow($rowNum, ValidatorInterface::ERROR_TYPE_UNSUPPORTED, $errorLevel);
24962495
}
24972496
} else {
24982497
// validate new product type and attribute set
24992498
if (!isset($rowData[self::COL_TYPE], $this->_productTypeModels[$rowData[self::COL_TYPE]])) {
2500-
$this->skipRow($rowNum, ValidatorInterface::ERROR_INVALID_TYPE);
2499+
$this->skipRow($rowNum, ValidatorInterface::ERROR_INVALID_TYPE, $errorLevel);
25012500
} elseif (!isset($rowData[self::COL_ATTR_SET], $this->_attrSetNameToId[$rowData[self::COL_ATTR_SET]])
25022501
) {
2503-
$this->skipRow($rowNum, ValidatorInterface::ERROR_INVALID_ATTR_SET);
2502+
$this->skipRow($rowNum, ValidatorInterface::ERROR_INVALID_ATTR_SET, $errorLevel);
25042503
} elseif ($this->skuProcessor->getNewSku($sku) === null) {
25052504
$this->skuProcessor->addNewSku(
25062505
$sku,
@@ -2570,11 +2569,7 @@ public function validateRow(array $rowData, $rowNum)
25702569
$newFromTimestamp = strtotime($this->dateTime->formatDate($rowData[self::COL_NEW_FROM_DATE], false));
25712570
$newToTimestamp = strtotime($this->dateTime->formatDate($rowData[self::COL_NEW_TO_DATE], false));
25722571
if ($newFromTimestamp > $newToTimestamp) {
2573-
$this->addRowError(
2574-
ValidatorInterface::ERROR_NEW_TO_DATE,
2575-
$rowNum,
2576-
$rowData[self::COL_NEW_TO_DATE]
2577-
);
2572+
$this->skipRow($rowNum, ValidatorInterface::ERROR_NEW_TO_DATE, $errorLevel, $rowData[self::COL_NEW_TO_DATE]);
25782573
}
25792574
}
25802575

@@ -3121,4 +3116,17 @@ private function skipRow(
31213116
->addRowToSkip($rowNum);
31223117
return $this;
31233118
}
3119+
3120+
/**
3121+
* Returns errorLevel for validation
3122+
*
3123+
* @param string $sku
3124+
* @return string
3125+
*/
3126+
private function getValidationErrorLevel($sku): string
3127+
{
3128+
return (!$this->isSkuExist($sku) && Import::BEHAVIOR_REPLACE !== $this->getBehavior())
3129+
? ProcessingError::ERROR_LEVEL_CRITICAL
3130+
: ProcessingError::ERROR_LEVEL_NOT_CRITICAL;
3131+
}
31243132
}

0 commit comments

Comments
 (0)