You are here

private function GenerateProducts::generateProducts in Commerce Bulk 8

1 call to GenerateProducts::generateProducts()
GenerateProducts::generateElements in modules/commerce_generate/src/Plugin/DevelGenerate/GenerateProducts.php

File

modules/commerce_generate/src/Plugin/DevelGenerate/GenerateProducts.php, line 390

Class

GenerateProducts
Provides a GenerateProducts plugin.

Namespace

Drupal\commerce_generate\Plugin\DevelGenerate

Code

private function generateProducts($values) {
  $values['product_types'] = array_filter((array) $values['product_types']);
  $values['stores'] = array_filter((array) $values['stores']);
  if (!empty($values['kill']) && ($values['product_types'] || $values['stores'])) {
    $this
      ->productKill($values);
  }
  if ($values['product_types'] && $values['num']) {

    // Generate products.
    $this
      ->prepareGenerateProduct($values);
    $start = time();
    for ($i = 1; $i <= $values['num']; $i++) {
      $this
        ->generateSaveProduct($values);
      if (method_exists($this, 'isDrush8') && $this
        ->isDrush8() && function_exists('drush_log') && $this
        ->isDrush8() && $i % drush_get_option('feedback', 1000) == 0) {
        $now = time();
        \Drupal::logger(dt('Completed @feedback products (@rate products/min)', [
          '@feedback' => drush_get_option('feedback', 1000),
          '@rate' => drush_get_option('feedback', 1000) * 60 / ($now - $start),
        ]), 'ok');
        $start = $now;
      }
    }
    $this
      ->setMessage($this
      ->formatPlural($values['num'], '1 product created.', 'Finished creating @count products'));
  }
}