You are here

public function CategoryTerm::getYield in Commerce Migrate 8.2

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

Prepare one row per taxonomy term field in the source.

@codingStandardsIgnoreStart

@codingStandardsIgnoreEnd

Parameters

\Generator $file: The source CSV file object.

Return value

\Generator A new row with properties, 'vocabulary', 'parent' and 'term'.

1 call to CategoryTerm::getYield()
CategoryTerm::initializeIterator in modules/magento/src/Plugin/migrate/source/magento2/CategoryTerm.php

File

modules/magento/src/Plugin/migrate/source/magento2/CategoryTerm.php, line 52

Class

CategoryTerm
Yields each taxonomy term and vocabulary pair..

Namespace

Drupal\commerce_migrate_magento\Plugin\migrate\source\magento2

Code

public function getYield(\Generator $file) {
  foreach ($file as $row) {
    $new_row = $row;
    $categories = explode(',', $row['categories']);
    foreach ($categories as $category) {
      $names = explode('/', $category);

      // Set the vocabulary key to this name.
      $new_row['vocabulary'] = $names[0];
      unset($names[0]);
      $previous_name = '';

      // Build a row for each term name.
      foreach ($names as $name) {
        if ($previous_name) {
          $new_row['parent'] = $previous_name;
        }
        $previous_name = $name;
        $new_row['name'] = $name;
        (yield $new_row);
      }
    }
  }
}