70 self::ERROR_CODE_SYSTEM_EXCEPTION =>
'General system exception happened',
71 self::ERROR_CODE_COLUMN_NOT_FOUND =>
'We can\'t find required columns: %s.',
72 self::ERROR_CODE_COLUMN_EMPTY_HEADER =>
'Columns number: "%s" have empty headers',
73 self::ERROR_CODE_COLUMN_NAME_INVALID =>
'Column names: "%s" are invalid',
74 self::ERROR_CODE_ATTRIBUTE_NOT_VALID =>
"Please correct the value for '%s'",
75 self::ERROR_CODE_DUPLICATE_UNIQUE_ATTRIBUTE =>
"Duplicate Unique Attribute for '%s'",
76 self::ERROR_CODE_ILLEGAL_CHARACTERS =>
"Illegal character used for attribute %s",
77 self::ERROR_CODE_INVALID_ATTRIBUTE =>
'Header contains invalid attribute(s): "%s"',
78 self::ERROR_CODE_WRONG_QUOTES =>
"Curly quotes used instead of straight quotes",
79 self::ERROR_CODE_COLUMNS_NUMBER =>
"Number of columns does not correspond to the number of rows in the header",
80 self::ERROR_EXCEEDED_MAX_LENGTH =>
'Attribute %s exceeded max length',
81 self::ERROR_INVALID_ATTRIBUTE_TYPE =>
'Value for \'%s\' attribute contains incorrect value',
82 self::ERROR_INVALID_ATTRIBUTE_OPTION =>
"Value for %s attribute contains incorrect value" 83 .
", see acceptable values on settings specified for Admin",
305 $this->_scopeConfig = $scopeConfig;
306 $this->_dataSourceModel = isset(
307 $data[
'data_source_model']
308 ) ?
$data[
'data_source_model'] : $importFactory->create()->getDataSourceModel();
310 isset(
$data[
'connection']) ?
311 $data[
'connection'] :
314 $this->_pageSize = isset(
316 ) ?
$data[
'page_size'] : (static::XML_PATH_PAGE_SIZE ? (int)$this->_scopeConfig->getValue(
317 static::XML_PATH_PAGE_SIZE,
318 \
Magento\Store\Model\ScopeInterface::SCOPE_STORE
320 $this->_maxDataSize = isset(
321 $data[
'max_data_size']
322 ) ?
$data[
'max_data_size'] : $resourceHelper->getMaxDataSize();
323 $this->_bunchSize = isset(
325 ) ?
$data[
'bunch_size'] : (static::XML_PATH_BUNCH_SIZE ? (int)$this->_scopeConfig->getValue(
326 static::XML_PATH_BUNCH_SIZE,
327 \
Magento\Store\Model\ScopeInterface::SCOPE_STORE
332 foreach ($this->errorMessageTemplates as $errorCode =>
$message) {
374 foreach ($rowData as $key => $val) {
376 $rowData[$key] =
null;
412 $startNewBunch =
false;
415 $this->_dataSourceModel->cleanBunches();
418 while (
$source->valid() || count($bunchRows) || isset($entityGroup)) {
419 if ($startNewBunch || !
$source->valid()) {
421 if (!
$source->valid() && isset($entityGroup)) {
422 foreach ($entityGroup as $key =>
$value) {
423 $bunchRows[$key] =
$value;
430 $startNewBunch =
false;
436 foreach ($rowData as $attrName =>
$element) {
437 if (!mb_check_encoding(
$element,
'UTF-8')) {
441 $this->_processedRowsCount,
446 }
catch (\InvalidArgumentException $e) {
451 $this->_processedRowsCount++;
458 if (isset($entityGroup)) {
459 foreach ($entityGroup as $key =>
$value) {
460 $bunchRows[$key] =
$value;
462 $productDataSize = strlen($this->getSerializer()->
serialize($bunchRows));
465 $isBunchSizeExceeded = ($this->_bunchSize > 0 && count($bunchRows) >=
$this->_bunchSize);
466 $startNewBunch = $productDataSize >= $this->_maxDataSize || $isBunchSizeExceeded;
476 }
elseif (isset($entityGroup)) {
481 $this->_processedRowsCount++;
496 private function getSerializer()
498 if (
null === $this->serializer) {
499 $this->serializer = ObjectManager::getInstance()->get(Json::class);
501 return $this->serializer;
519 $errorMessage =
null,
521 $errorDescription =
null 523 $errorCode = (string)$errorCode;
559 $this->_parameters[
'behavior']
561 $this->_parameters[
'behavior'],
562 $this->_availableBehaviors
565 $behavior = $this->_parameters[
'behavior'];
568 if (array_key_exists(self::COLUMN_ACTION, $rowData)) {
569 if (strtolower($rowData[self::COLUMN_ACTION]) == self::COLUMN_ACTION_VALUE_DELETE) {
576 if (in_array($behavior, $this->_availableBehaviors)) {
596 return \Magento\ImportExport\Model\Import::BEHAVIOR_ADD_UPDATE;
627 if (!$this->_source) {
628 throw new \Magento\Framework\Exception\LocalizedException(
__(
'The source is not set.'));
675 array $attributeParams,
681 switch ($attributeParams[
'type']) {
697 $valid = isset($attributeParams[
'options'][
$value]);
711 $valid = strtotime(
$value) !==
false;
725 if (
$message == self::ERROR_INVALID_ATTRIBUTE_TYPE) {
727 $this->errorMessageTemplates[
$message],
729 $attributeParams[
'type']
733 }
elseif (!empty($attributeParams[
'is_unique'])) {
762 return $this->
validateRow($rowData, $rowNumber) && !isset($this->_skippedRows[$rowNumber]);
782 abstract public function validateRow(array $rowData, $rowNumber);
792 $this->_parameters = $parameters;
805 $this->_dataValidated =
false;
818 if (!$this->_dataValidated) {
821 $absentColumns = array_diff($this->_permanentAttributes, $this->
getSource()->getColNames());
822 $this->
addErrors(self::ERROR_CODE_COLUMN_NOT_FOUND, $absentColumns);
826 $emptyHeaderColumns = [];
827 $invalidColumns = [];
828 $invalidAttributes = [];
829 foreach ($this->
getSource()->getColNames() as $columnName) {
832 if (trim($columnName) ==
'') {
833 $emptyHeaderColumns[] = $columnNumber;
834 }
elseif (!preg_match(
'/^[a-z][a-z0-9_]*$/', $columnName)) {
835 $invalidColumns[] = $columnName;
837 $invalidAttributes[] = $columnName;
841 $this->
addErrors(self::ERROR_CODE_INVALID_ATTRIBUTE, $invalidAttributes);
842 $this->
addErrors(self::ERROR_CODE_COLUMN_EMPTY_HEADER, $emptyHeaderColumns);
843 $this->
addErrors(self::ERROR_CODE_COLUMN_NAME_INVALID, $invalidColumns);
847 $this->_dataValidated =
true;
893 $this->countItemsCreated = count($created);
894 $this->countItemsUpdated = count($updated);
895 $this->countItemsDeleted = count($deleted);
isRowAllowedToImport(array $rowData, $rowNumber)
const ERROR_CODE_SYSTEM_EXCEPTION
setParameters(array $parameters)
const ERROR_INVALID_ATTRIBUTE_OPTION
const ERROR_CODE_COLUMN_NOT_FOUND
isAttributeValid( $attributeCode, array $attributeParams, array $rowData, $rowNumber, $multiSeparator=Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR)
elseif(isset( $params[ 'redirect_parent']))
const ERROR_CODE_COLUMN_EMPTY_HEADER
const BEHAVIOR_ADD_UPDATE
const ERROR_CODE_DUPLICATE_UNIQUE_ATTRIBUTE
addRowError( $errorCode, $errorRowNum, $colName=null, $errorMessage=null, $errorLevel=ProcessingError::ERROR_LEVEL_CRITICAL, $errorDescription=null)
const ERROR_CODE_WRONG_QUOTES
const DB_MAX_VARCHAR_LENGTH
const ERROR_CODE_INVALID_ATTRIBUTE
const ERROR_CODE_COLUMNS_NUMBER
const ERROR_CODE_ILLEGAL_CHARACTERS
const DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR
getProcessedEntitiesCount()
isAttributeParticular($attributeCode)
const XML_PATH_BUNCH_SIZE
__construct(\Magento\Framework\Stdlib\StringUtils $string, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\ImportExport\Model\ImportFactory $importFactory, \Magento\ImportExport\Model\ResourceModel\Helper $resourceHelper, ResourceConnection $resource, ProcessingErrorAggregatorInterface $errorAggregator, array $data=[])
serialize($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
const ERROR_LEVEL_CRITICAL
getBehavior(array $rowData=null)
addErrors($code, $errors)
const ERROR_CODE_ATTRIBUTE_NOT_VALID
const ERROR_EXCEEDED_MAX_LENGTH
validateRow(array $rowData, $rowNumber)
addMessageTemplate($errorCode, $message)
const ERROR_INVALID_ATTRIBUTE_TYPE
updateItemsCounterStats(array $created=[], array $updated=[], array $deleted=[])
setSource(AbstractSource $source)
static getDefaultBehavior()
_prepareRowForDb(array $rowData)
const COLUMN_ACTION_VALUE_DELETE
const ERROR_CODE_COLUMN_NAME_INVALID