/** * @param \Magento\Framework\View\Element\AbstractBlock $resultBlock * @param ProcessingErrorAggregatorInterface $errorAggregator * @return $this */ protected function addErrorMessages(\Magento\Framework\View\Element\AbstractBlock $resultBlock, ProcessingErrorAggregatorInterface $errorAggregator) { if ($errorAggregator->getErrorsCount()) { $message = ''; $counter = 0; foreach ($this->getErrorMessages($errorAggregator) as $error) { $message .= ++$counter . '. ' . $error . '<br>'; if ($counter >= self::LIMIT_ERRORS_MESSAGE) { break; } } if ($errorAggregator->hasFatalExceptions()) { foreach ($this->getSystemExceptions($errorAggregator) as $error) { $message .= $error->getErrorMessage() . ' <a href="#" onclick="$(this).next().show();$(this).hide();return false;">' . __('Show more') . '</a><div style="display:none;">' . __('Additional data') . ': ' . $error->getErrorDescription() . '</div>'; } } try { $resultBlock->addNotice('<strong>' . __('Following Error(s) has been occurred during importing process:') . '</strong><br>' . '<div class="import-error-wrapper">' . __('Only first 100 errors are displayed here. ') . '<a href="' . $this->createDownloadUrlImportHistoryFile($this->createErrorReport($errorAggregator)) . '">' . __('Download full report') . '</a><br>' . '<div class="import-error-list">' . $message . '</div></div>'); } catch (\Exception $e) { foreach ($this->getErrorMessages($errorAggregator) as $errorMessage) { $resultBlock->addError($errorMessage); } } } return $this; }
/** * TODO: Refactor Code * @param \Magento\Framework\View\Element\AbstractBlock $resultBlock * @param ProcessingErrorAggregatorInterface $errorAggregator * @return $this */ public function getImportErrorMessages(ProcessingErrorAggregatorInterface $errorAggregator) { $resultText = ''; if ($errorAggregator->getErrorsCount()) { $message = ''; $counter = 0; foreach ($this->getErrorMessages($errorAggregator) as $error) { $message .= ++$counter . '. ' . $error . '<br>'; if ($counter >= self::LIMIT_ERRORS_MESSAGE) { break; } } if ($errorAggregator->hasFatalExceptions()) { foreach ($this->getSystemExceptions($errorAggregator) as $error) { $message .= $error->getErrorMessage() . ' <a href="#" onclick="$(this).next().show();$(this).hide();return false;">' . __('Show more') . '</a><div style="display:none;">' . __('Additional data') . ': ' . $error->getErrorDescription() . '</div>'; } } try { $resultText .= '<strong>' . __('Following Error(s) has been occurred during importing process:') . '</strong><br>' . '<div class="import-error-wrapper">' . __('Only first 100 errors are displayed here. ') . '<a href="' . '">' . __('Download full report') . '</a><br>' . '<div class="import-error-list">' . $message . '</div></div>'; } catch (\Exception $e) { foreach ($this->getErrorMessages($errorAggregator) as $errorMessage) { $resultText .= $errorMessage; } } } return $resultText; }
/** * Return operation result messages * * @param ProcessingErrorAggregatorInterface $validationResult * @return string[] */ public function getOperationResultMessages(ProcessingErrorAggregatorInterface $validationResult) { $messages = []; if ($this->getProcessedRowsCount()) { if ($validationResult->getErrorsCount()) { $messages[] = __('Data validation is failed. Please fix errors and re-upload the file.'); // errors info foreach ($validationResult->getRowsGroupedByErrorCode() as $errorMessage => $rows) { $error = $errorMessage . ' ' . __('in rows') . ': ' . implode(', ', $rows); $messages[] = $error; } } else { if ($this->isImportAllowed()) { $messages[] = __('The validation is complete.'); } else { $messages[] = __('The file is valid, but we can\'t import it for some reason.'); } } $messages[] = __('Checked rows: %1, checked entities: %2, invalid rows: %3, total errors: %4', $this->getProcessedRowsCount(), $this->getProcessedEntitiesCount(), $validationResult->getInvalidRowsCount(), $validationResult->getErrorsCount([ProcessingError::ERROR_LEVEL_CRITICAL, ProcessingError::ERROR_LEVEL_NOT_CRITICAL])); } else { $messages[] = __('This file does not contain any data.'); } return $messages; }