You are here

public function CommerceSmartImporerService::eraseAllProductsOnSite in Commerce Smart Importer 8

Caution: Erase all products on site.

File

src/Plugin/CommerceSmartImporerService.php, line 1721
Main Commerce Smart Importer Service.

Class

CommerceSmartImporerService
This is main Commerce Smart Importer Service.

Namespace

Drupal\commerce_smart_importer\Plugin

Code

public function eraseAllProductsOnSite($pass) {
  if ($pass == 'mrmotmrmot23#42234d') {
    $results = $this->database
      ->select('commerce_product')
      ->fields('commerce_product', [
      'product_id',
    ])
      ->execute()
      ->fetchAll();
    $count = count($results);
    $batches = ceil($count / 70);
    $batch = [
      'title' => $this
        ->t('ERASING ALL DATA'),
      'init_message' => $this
        ->t('Beginning...'),
      'progress_message' => $this
        ->t('ERASED @current out of @total products'),
      'error_message' => $this
        ->t('Something went wrong'),
      'progressive' => FALSE,
      'finished' => [
        $this,
        'finished',
      ],
      'operations' => [],
    ];
    for ($i = 0; $i < $batches; $i++) {
      $batch['operations'][] = [
        [
          $this,
          'productEraser',
        ],
        [
          70,
        ],
      ];
    }
    batch_set($batch);
  }
}