public function CSVExportForm::downloadCsv in Commerce Smart Importer 8
Downloads CSV.
1 call to CSVExportForm::downloadCsv()
- CSVExportForm::buildForm in src/
Form/ CSVExportForm.php - Builds form.
File
- src/
Form/ CSVExportForm.php, line 433
Class
- CSVExportForm
- Form for exporting products in CSV format.
Namespace
Drupal\commerce_smart_importer\FormCode
public function downloadCsv() {
$config = $this->smartImporterService
->getConfig();
if ($config['store'] != 'all') {
$store = Store::load($config['store']);
$name = $store
->getName();
}
else {
$name = $this
->config('system.site')
->get('name');
}
$filename = 'temporary://export-' . str_replace(' ', '-', $name) . '.csv';
if (is_file($filename)) {
$csv_file = file_get_contents($filename);
header('Content-Description: File Transfer');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Type: application/csv');
header("Content-length: " . filesize($filename));
header('Content-Disposition: attachment; filename="' . basename($filename) . '"');
echo $csv_file;
exit;
}
else {
$this
->messenger()
->addStatus($this
->t('Export first'));
}
}