Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding flag for fields enclosure #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Console/Command/ImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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')));
Expand Down Expand Up @@ -99,4 +104,3 @@ protected function getImportModel()
return $this->objectManager->create('CedricBlondeau\CatalogImportCommand\Model\Import');
}
}

9 changes: 8 additions & 1 deletion Model/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -133,4 +141,3 @@ public function getErrors()
return $this->importModel->getErrorAggregator()->getAllErrors();
}
}

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down