You are here

public function ProductDisplay::prepareRow in Commerce Migrate 8.2

Same name and namespace in other branches
  1. 3.1.x modules/commerce/src/Plugin/migrate/source/commerce1/ProductDisplay.php \Drupal\commerce_migrate_commerce\Plugin\migrate\source\commerce1\ProductDisplay::prepareRow()
  2. 3.0.x modules/commerce/src/Plugin/migrate/source/commerce1/ProductDisplay.php \Drupal\commerce_migrate_commerce\Plugin\migrate\source\commerce1\ProductDisplay::prepareRow()

Adds additional data to the row.

Parameters

\Drupal\migrate\Row $row: The row object.

Return value

bool FALSE if this row needs to be skipped.

Overrides SourcePluginBase::prepareRow

File

modules/commerce/src/Plugin/migrate/source/commerce1/ProductDisplay.php, line 109

Class

ProductDisplay
DGets Commerce 1 commerce_line_item data from database.

Namespace

Drupal\commerce_migrate_commerce\Plugin\migrate\source\commerce1

Code

public function prepareRow(Row $row) {
  $default_store = $this->defaultStoreResolver
    ->resolve();
  if ($default_store) {
    $row
      ->setDestinationProperty('stores', [
      'target_id' => $default_store
        ->id(),
    ]);
  }
  else {
    throw new MigrateException('You must have a store saved in order to import products.');
  }
  $variations_field_name = $row
    ->getSourceProperty('field_name');

  // Get Field API field values.
  $nid = $row
    ->getSourceProperty('nid');
  $vid = $row
    ->getSourceProperty('vid');
  foreach (array_keys($this
    ->getFields('node', $row
    ->getSourceProperty('type'))) as $field) {

    // If this is the product reference field, map it to `variations_field`
    // since it does not have a standardized name.
    if ($field == $variations_field_name) {
      $row
        ->setSourceProperty('variations_field', $this
        ->getFieldValues('node', $variations_field_name, $nid, $vid));
    }
    else {
      $row
        ->setSourceProperty($field, $this
        ->getFieldValues('node', $field, $nid, $vid));
    }
  }
  return parent::prepareRow($row);
}