You are here

public function Image::getYield in Commerce Migrate 3.0.x

Same name in this branch
  1. 3.0.x modules/csv_example/src/Plugin/migrate/source/Image.php \Drupal\commerce_migrate_csv_example\Plugin\migrate\source\Image::getYield()
  2. 3.0.x modules/magento/src/Plugin/migrate/source/magento2/Image.php \Drupal\commerce_migrate_magento\Plugin\migrate\source\magento2\Image::getYield()
Same name and namespace in other branches
  1. 8.2 modules/csv_example/src/Plugin/migrate/source/Image.php \Drupal\commerce_migrate_csv_example\Plugin\migrate\source\Image::getYield()
  2. 3.1.x modules/csv_example/src/Plugin/migrate/source/Image.php \Drupal\commerce_migrate_csv_example\Plugin\migrate\source\Image::getYield()

Prepare one row per image file in the source row.

@codingStandardsIgnoreStart

@codingStandardsIgnoreEnd

Parameters

\Generator $file: The source CSV file object.

Return value

\Generator A new row, one for each filename in the source image column.

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

File

modules/csv_example/src/Plugin/migrate/source/Image.php, line 42

Class

Image
Yields each image and sku.

Namespace

Drupal\commerce_migrate_csv_example\Plugin\migrate\source

Code

public function getYield(\Generator $file) {
  foreach ($file as $row) {
    if (!empty($row['sku'])) {

      // There is a SKU so let's check for images.
      $new_row = [];
      $new_row['sku'] = trim($row['sku']);

      // Product variation images.
      for ($i = 1; $i < 4; $i++) {
        $new_row['image'] = trim($row["image{$i}"]);
        if (!empty($new_row['image'])) {
          (yield $new_row);
        }
      }

      // Video thumbnails.
      for ($i = 1; $i < 4; $i++) {
        $new_row['image'] = trim($row["thumbnail{$i}"]);
        if (!empty($new_row['image'])) {
          (yield $new_row);
        }
      }

      // Call to action images.
      for ($i = 1; $i < 3; $i++) {
        $new_row['image'] = trim($row["cta_image{$i}"]);
        if (!empty($new_row['image'])) {
          (yield $new_row);
        }
      }
    }
  }
}