Skip to content

Commit

Permalink
MAGETWO-97345: [Magento Cloud] Import doesn't work with skip error en…
Browse files Browse the repository at this point in the history
…tries
  • Loading branch information
Sergey Shvets committed Jan 8, 2019
1 parent 18a4484 commit d4d34ff
Showing 1 changed file with 41 additions and 36 deletions.
77 changes: 41 additions & 36 deletions app/code/Magento/CatalogImportExport/Model/Import/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\CatalogImportExport\Model\Import;

use Magento\Catalog\Api\ProductRepositoryInterface;
Expand Down Expand Up @@ -307,7 +308,7 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
ValidatorInterface::ERROR_MEDIA_URL_NOT_ACCESSIBLE => 'Imported resource (image) could not be downloaded from external resource due to timeout or access permissions',
ValidatorInterface::ERROR_INVALID_WEIGHT => 'Product weight is invalid',
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',
ValidatorInterface::ERROR_DUPLICATE_MULTISELECT_VALUES => "Value for multiselect attribute %s contains duplicated values",
ValidatorInterface::ERROR_DUPLICATE_MULTISELECT_VALUES => 'Value for multiselect attribute %s contains duplicated values',
ValidatorInterface::ERROR_NEW_TO_DATE => 'Make sure new_to_date is later than or the same as new_from_date',
];
//@codingStandardsIgnoreEnd
Expand Down Expand Up @@ -913,7 +914,7 @@ public function isAttributeValid($attrCode, array $attrParams, array $rowData, $
{
if (!$this->validator->isAttributeValid($attrCode, $attrParams, $rowData)) {
foreach ($this->validator->getMessages() as $message) {
$this->addRowError($message, $rowNum, $attrCode);
$this->skipRow($rowNum, $message, null, $attrCode);
}
return false;
}
Expand Down Expand Up @@ -1808,13 +1809,7 @@ protected function _saveProducts()
$uploadedImages[$columnImage] = $uploadedFile;
} else {
unset($rowData[$column]);
$this->addRowError(
ValidatorInterface::ERROR_MEDIA_URL_NOT_ACCESSIBLE,
$rowNum,
null,
null,
ProcessingError::ERROR_LEVEL_NOT_CRITICAL
);
$this->skipRow($rowNum, ValidatorInterface::ERROR_MEDIA_URL_NOT_ACCESSIBLE);
}
} else {
$uploadedFile = $uploadedImages[$columnImage];
Expand Down Expand Up @@ -2453,32 +2448,32 @@ public function validateRow(array $rowData, $rowNum)
// BEHAVIOR_DELETE and BEHAVIOR_REPLACE use specific validation logic
if (Import::BEHAVIOR_REPLACE == $this->getBehavior()) {
if (self::SCOPE_DEFAULT == $rowScope && !$this->isSkuExist($sku)) {
$this->addRowError(ValidatorInterface::ERROR_SKU_NOT_FOUND_FOR_DELETE, $rowNum);
$this->skipRow($rowNum, ValidatorInterface::ERROR_SKU_NOT_FOUND_FOR_DELETE);
return false;
}
}
if (Import::BEHAVIOR_DELETE == $this->getBehavior()) {
if (self::SCOPE_DEFAULT == $rowScope && !$this->isSkuExist($sku)) {
$this->addRowError(ValidatorInterface::ERROR_SKU_NOT_FOUND_FOR_DELETE, $rowNum);
$this->skipRow($rowNum, ValidatorInterface::ERROR_SKU_NOT_FOUND_FOR_DELETE);
return false;
}
return true;
}

if (!$this->validator->isValid($rowData)) {
foreach ($this->validator->getMessages() as $message) {
$this->addRowError($message, $rowNum, $this->validator->getInvalidAttribute());
$this->skipRow($rowNum, $message, null, $this->validator->getInvalidAttribute());
}
}

if (null === $sku) {
$this->addRowError(ValidatorInterface::ERROR_SKU_IS_EMPTY, $rowNum);
$this->skipRow($rowNum, ValidatorInterface::ERROR_SKU_IS_EMPTY);
} elseif (false === $sku) {
$this->addRowError(ValidatorInterface::ERROR_ROW_IS_ORPHAN, $rowNum);
$this->skipRow($rowNum, ValidatorInterface::ERROR_ROW_IS_ORPHAN);
} elseif (self::SCOPE_STORE == $rowScope
&& !$this->storeResolver->getStoreCodeToId($rowData[self::COL_STORE])
) {
$this->addRowError(ValidatorInterface::ERROR_INVALID_STORE, $rowNum);
$this->skipRow($rowNum, ValidatorInterface::ERROR_INVALID_STORE);
}

// SKU is specified, row is SCOPE_DEFAULT, new product block begins
Expand All @@ -2493,29 +2488,15 @@ public function validateRow(array $rowData, $rowNum)
$this->prepareNewSkuData($sku)
);
} else {
$this->addRowError(ValidatorInterface::ERROR_TYPE_UNSUPPORTED, $rowNum);
$this->skipRow($rowNum, ValidatorInterface::ERROR_TYPE_UNSUPPORTED);
}
} else {
// validate new product type and attribute set
if (!isset($rowData[self::COL_TYPE], $this->_productTypeModels[$rowData[self::COL_TYPE]])) {
$this->addRowError(
ValidatorInterface::ERROR_INVALID_TYPE,
$rowNum,
null,
null,
ProcessingError::ERROR_LEVEL_NOT_CRITICAL
);
$this->getErrorAggregator()->addRowToSkip($rowNum);
$this->skipRow($rowNum, ValidatorInterface::ERROR_INVALID_TYPE);
} elseif (!isset($rowData[self::COL_ATTR_SET], $this->_attrSetNameToId[$rowData[self::COL_ATTR_SET]])
) {
$this->addRowError(
ValidatorInterface::ERROR_INVALID_ATTR_SET,
$rowNum,
null,
null,
ProcessingError::ERROR_LEVEL_NOT_CRITICAL
);
$this->getErrorAggregator()->addRowToSkip($rowNum);
$this->skipRow($rowNum, ValidatorInterface::ERROR_INVALID_ATTR_SET);
} elseif ($this->skuProcessor->getNewSku($sku) === null) {
$this->skuProcessor->addNewSku(
$sku,
Expand Down Expand Up @@ -2571,8 +2552,11 @@ public function validateRow(array $rowData, $rowNum)
ValidatorInterface::ERROR_DUPLICATE_URL_KEY,
$rowNum,
$rowData[self::COL_NAME],
$message
);
$message,
ProcessingError::ERROR_LEVEL_NOT_CRITICAL
)
->getErrorAggregator()
->addRowToSkip($rowNum);
}
}
}
Expand Down Expand Up @@ -2603,8 +2587,8 @@ private function isNeedToValidateUrlKey($rowData)
{
return (!empty($rowData[self::URL_KEY]) || !empty($rowData[self::COL_NAME]))
&& (empty($rowData[self::COL_VISIBILITY])
|| $rowData[self::COL_VISIBILITY]
!== (string)Visibility::getOptionArray()[Visibility::VISIBILITY_NOT_VISIBLE]);
|| $rowData[self::COL_VISIBILITY]
!== (string)Visibility::getOptionArray()[Visibility::VISIBILITY_NOT_VISIBLE]);
}

/**
Expand Down Expand Up @@ -3112,4 +3096,25 @@ private function retrieveProductBySku($sku)
}
return $product;
}

/**
* Add row as skipped
*
* @param @param int $rowNumber
* @param string $errorCode Error code or simply column name
* @param string $errorLevel
* @param string $colName OPTIONAL Column name.
* @return $this
*/
private function skipRow(
$rowNum,
string $errorCode,
$errorLevel = ProcessingError::ERROR_LEVEL_NOT_CRITICAL,
$colName = null
): self {
$this->addRowError($errorCode, $rowNum, $colName, null, $errorLevel)
->getErrorAggregator()
->addRowToSkip($rowNum);
return $this;
}
}

0 comments on commit d4d34ff

Please sign in to comment.