From 849cc8bac01f81f266ddc10c57606b41d5625b2a Mon Sep 17 00:00:00 2001 From: Tomas Stiller Date: Thu, 17 Aug 2017 15:18:03 +0200 Subject: [PATCH] Adding flag for fields enclosure --- Console/Command/ImportCommand.php | 8 ++++++-- Model/Import.php | 9 ++++++++- README.md | 3 ++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Console/Command/ImportCommand.php b/Console/Command/ImportCommand.php index 5414820..89905b5 100644 --- a/Console/Command/ImportCommand.php +++ b/Console/Command/ImportCommand.php @@ -47,7 +47,8 @@ protected function configure() ->setDescription('Import catalog') ->addArgument('filename', InputArgument::REQUIRED, "CSV file path") ->addOption('images_path', "i", InputOption::VALUE_OPTIONAL, "Images path") - ->addOption('behavior', "b", InputOption::VALUE_OPTIONAL, "Behavior"); + ->addOption('behavior', "b", InputOption::VALUE_OPTIONAL, "Behavior") + ->addOption('fields_enclosure', "f", InputOption::VALUE_NONE, "Fields Enclosure"); parent::configure(); } @@ -63,6 +64,10 @@ protected function execute(InputInterface $input, OutputInterface $output) if ($input->getOption('behavior')) { $import->setBehavior($input->getOption('behavior')); } + if ($input->getOption('fields_enclosure')) + { + $import->setFieldsEnclosure(true); + } try { $import->setFile(realpath($input->getArgument('filename'))); @@ -99,4 +104,3 @@ protected function getImportModel() return $this->objectManager->create('CedricBlondeau\CatalogImportCommand\Model\Import'); } } - diff --git a/Model/Import.php b/Model/Import.php index 930159a..2be2860 100644 --- a/Model/Import.php +++ b/Model/Import.php @@ -89,6 +89,14 @@ public function setImagesPath($imagesPath) $this->importModel->setData(MagentoImport::FIELD_NAME_IMG_FILE_DIR, $imagesPath); } + /** + * @param $fieldsEnclosure + */ + public function setFieldsEnclosure($fieldsEnclosure) + { + $this->importModel->setData(MagentoImport::FIELDS_ENCLOSURE, $fieldsEnclosure ? 1 : 0); + } + /** * @param $behavior */ @@ -133,4 +141,3 @@ public function getErrors() return $this->importModel->getErrorAggregator()->getAllErrors(); } } - diff --git a/README.md b/README.md index 48804e1..cd70669 100644 --- a/README.md +++ b/README.md @@ -10,11 +10,12 @@ php bin/magento setup:upgrade ## Usage ```bash -php bin/magento catalog:import [-i|--images_path[="..."]] [-b|--behavior[="..."]] csv_file +php bin/magento catalog:import [-i|--images_path[="..."]] [-b|--behavior[="..."]] [-f|--fields_enclosure] csv_file ``` - `--images_path`: (default `pub/media/catalog/product`) must be a relative path starting from your Magento2 project root - `--behavior`: (default `append`) possible values: append, add_update, replace, delete +- `--fields_enclosure`: (default false) use fields enclosure - csv_file: could be a relative or an absolute path to a valid CSV file ## Inspiration