/**
  * @param $filePath Absolute file path to CSV file
  */
 public function setFile($filePath)
 {
     if (!file_exists($filePath)) {
         throw new FileNotFoundException();
     }
     // Hacky but quick fix for https://github.com/cedricblondeau/magento2-module-catalog-import-command/issues/1
     $pathInfo = pathinfo($filePath);
     $validate = $this->importModel->validateSource($this->csvSourceFactory->create(['file' => $pathInfo['basename'], 'directory' => $this->readFactory->create($pathInfo['dirname'])]));
     if (!$validate) {
         throw new \InvalidArgumentException();
     }
 }
Пример #2
0
 /**
  * @inheritdoc
  */
 public function install()
 {
     $this->eavConfig->clear();
     $importModel = $this->importModel;
     $importModel->setData(['entity' => 'catalog_product', 'behavior' => 'append', 'import_images_file_dir' => 'pub/media/catalog/product', Import::FIELD_NAME_VALIDATION_STRATEGY => ProcessingErrorAggregatorInterface::VALIDATION_STRATEGY_SKIP_ERRORS]);
     $source = $this->csvSourceFactory->create(['file' => 'fixtures/products.csv', 'directory' => $this->readFactory->create($this->componentRegistrar->getPath(ComponentRegistrar::MODULE, 'Magento_ConfigurableSampleData'))]);
     $currentPath = getcwd();
     chdir(BP);
     $importModel->validateSource($source);
     $importModel->importSource();
     chdir($currentPath);
     $this->eavConfig->clear();
     $this->reindex();
 }
 /**
  * @inheritdoc
  */
 public function run()
 {
     $this->logger->log('Installing configurable products:');
     $importModel = $this->importModel;
     $importModel->setData(['entity' => 'catalog_product', 'behavior' => 'append', 'import_images_file_dir' => 'pub/media/catalog/product', Import::FIELD_NAME_VALIDATION_STRATEGY => ProcessingErrorAggregatorInterface::VALIDATION_STRATEGY_SKIP_ERRORS]);
     $source = $this->csvSourceFactory->create(['file' => 'Magento/SampleData/fixtures/ConfigurableProduct/import-export_products-img.csv', 'directory' => $this->filesystem->getDirectoryWrite(DirectoryList::MODULES)]);
     $currentPath = getcwd();
     chdir($this->filesystem->getDirectoryRead(DirectoryList::ROOT)->getAbsolutePath());
     $importModel->validateSource($source);
     $importModel->importSource();
     chdir($currentPath);
     $this->logger->logInline('.');
     $this->eavConfig->clear();
     $this->reindex();
     $this->logger->logInline('.');
 }
Пример #4
0
 /**
  * @param string $sourceFile
  * @return \Magento\ImportExport\Model\Import\Source\Csv
  */
 protected function createSourceCsvModel($sourceFile)
 {
     return $this->sourceCsvFactory->create(['file' => $sourceFile, 'directory' => $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR)]);
 }