You are here

protected function Product::getProductsWithVariations in Commerce Migrate 3.1.x

Same name and namespace in other branches
  1. 8.2 modules/csv_example/src/Plugin/migrate/source/Product.php \Drupal\commerce_migrate_csv_example\Plugin\migrate\source\Product::getProductsWithVariations()
  2. 3.0.x modules/csv_example/src/Plugin/migrate/source/Product.php \Drupal\commerce_migrate_csv_example\Plugin\migrate\source\Product::getProductsWithVariations()

Builds a product row including an array of variation SKUs for this product.

Parameters

\Generator $file: The source CSV file object.

Return value

array The product array.

1 call to Product::getProductsWithVariations()
Product::initializeIterator in modules/csv_example/src/Plugin/migrate/source/Product.php

File

modules/csv_example/src/Plugin/migrate/source/Product.php, line 48

Class

Product
Builds the product rows.

Namespace

Drupal\commerce_migrate_csv_example\Plugin\migrate\source

Code

protected function getProductsWithVariations(\Generator $file) {

  // Initialize the new row.
  $new_row = [];
  foreach ($file as $line) {
    if (array_key_exists($line['title'], $new_row)) {

      // The new_row has a row for this product, add this SKU.
      $new_row[$line['title']]['variation_sku'][] = trim($line['sku']);
    }
    else {

      // This is a new product, initialize the new_row.
      $line['variation_sku'][] = trim($line['sku']);
      $new_row[$line['title']] = $line;
    }
  }
  return $new_row;
}