/** * Start import process action * * @return \Magento\Framework\Controller\ResultInterface */ public function executeInternal() { $data = $this->getRequest()->getPostValue(); if ($data) { /** @var \Magento\Framework\View\Result\Layout $resultLayout */ $resultLayout = $this->resultFactory->create(ResultFactory::TYPE_LAYOUT); /** @var $resultBlock \Magento\ImportExport\Block\Adminhtml\Import\Frame\Result */ $resultBlock = $resultLayout->getLayout()->getBlock('import.frame.result'); $resultBlock->addAction('show', 'import_validation_container')->addAction('innerHTML', 'import_validation_container_header', __('Status'))->addAction('hide', ['edit_form', 'upload_button', 'messages']); $this->importModel->setData($data); $this->importModel->importSource(); $errorAggregator = $this->importModel->getErrorAggregator(); if ($this->importModel->getErrorAggregator()->hasToBeTerminated()) { $resultBlock->addError(__('Maximum error count has been reached or system error is occurred!')); $this->addErrorMessages($resultBlock, $errorAggregator); } else { $this->importModel->invalidateIndex(); $this->addErrorMessages($resultBlock, $errorAggregator); $resultBlock->addSuccess(__('Import successfully done')); } return $resultLayout; } /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); $resultRedirect->setPath('adminhtml/*/index'); return $resultRedirect; }
/** * @covers \Magento\ImportExport\Model\Import::_getEntityAdapter */ public function testImportSource() { /** @var $customersCollection \Magento\Customer\Model\ResourceModel\Customer\Collection */ $customersCollection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Customer\\Model\\ResourceModel\\Customer\\Collection'); $existCustomersCount = count($customersCollection->load()); $customersCollection->resetData(); $customersCollection->clear(); $this->_model->setData(Import::FIELD_NAME_VALIDATION_STRATEGY, Import\ErrorProcessing\ProcessingErrorAggregatorInterface::VALIDATION_STRATEGY_SKIP_ERRORS); $this->_model->importSource(); $customers = $customersCollection->getItems(); $addedCustomers = count($customers) - $existCustomersCount; $this->assertGreaterThan($existCustomersCount, $addedCustomers); }
/** * {@inheritdoc} */ public function setData($key, $value = null) { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'setData'); if (!$pluginInfo) { return parent::setData($key, $value); } else { return $this->___callPlugins('setData', func_get_args(), $pluginInfo); } }
/** * @param string $dir */ public function setImportImagesFileDir($dir) { $this->importModel->setData('import_images_file_dir', $dir); }
/** * @param $behavior */ public function setBehavior($behavior) { if (in_array($behavior, array(MagentoImport::BEHAVIOR_APPEND, MagentoImport::BEHAVIOR_ADD_UPDATE, MagentoImport::BEHAVIOR_REPLACE, MagentoImport::BEHAVIOR_DELETE))) { $this->importModel->setData('behavior', $behavior); } }