You are here

protected function GenerateProducts::productKill in Commerce Bulk 8

2 calls to GenerateProducts::productKill()
GenerateProducts::batchProductKill in modules/commerce_generate/src/Plugin/DevelGenerate/GenerateProducts.php
GenerateProducts::generateProducts in modules/commerce_generate/src/Plugin/DevelGenerate/GenerateProducts.php

File

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

Class

GenerateProducts
Provides a GenerateProducts plugin.

Namespace

Drupal\commerce_generate\Plugin\DevelGenerate

Code

protected function productKill($values) {
  $products = $in_stores = $in_product_types = [];
  if ($values['stores']) {
    $products = $in_stores = (array) $this->productStorage
      ->loadByProperties([
      'stores' => $values['stores'],
    ]);
  }
  if ($values['product_types']) {
    $products = $in_product_types = (array) $this->productStorage
      ->loadByProperties([
      'type' => $values['product_types'],
    ]);
  }
  if ($in_stores && $in_product_types) {
    $products = array_intersect_key($in_stores, $in_product_types);
  }
  if ($count = count($products)) {
    $this->productStorage
      ->delete($products);
    $this
      ->setMessage($this
      ->t('Deleted %count products.', [
      '%count' => $count,
    ]));
  }
  else {
    $this
      ->setMessage($this
      ->t('Nothing to delete, skipped.'));
  }
}