You are here

public function CommerceSmartImporerService::countProductsAndVariations in Commerce Smart Importer 8

Counts Products and Variations in CSV file.

File

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

Class

CommerceSmartImporerService
This is main Commerce Smart Importer Service.

Namespace

Drupal\commerce_smart_importer\Plugin

Code

public function countProductsAndVariations($file) {
  $linecount = 0;
  $productCount = 0;
  $handle = fopen($file, "r");
  while (($line = fgetcsv($handle)) !== FALSE) {
    $linecount++;
    if (!empty($line[0]) || $linecount === 1 || $linecount === 2) {
      $productCount++;
    }
  }
  fclose($handle);
  return [
    'product_count' => $productCount - 2,
    'variation_count' => $linecount - 2,
  ];
}