You are here

public function CSVExportForm::putExportedProductsInCsv in Commerce Smart Importer 8

Writes formated product to CSV file.

File

src/Form/CSVExportForm.php, line 338

Class

CSVExportForm
Form for exporting products in CSV format.

Namespace

Drupal\commerce_smart_importer\Form

Code

public function putExportedProductsInCsv($start, $limit, $field_definitions, array $field_value) {
  $config = $this->smartImporterService
    ->getConfig();
  if ($config['store'] != 'all') {
    $store = Store::load($config['store']);
    $name = $store
      ->getName();
  }
  else {
    $name = $this
      ->config('system.site')
      ->get('name');
  }
  $file = fopen('temporary://export-' . str_replace(' ', '-', $name) . '.csv', 'a');
  $rows = $this
    ->exportProducts($start, $limit, $field_definitions, $field_value);
  foreach ($rows as $row) {
    fputcsv($file, $row);
  }
  fclose($file);
}