You are here

public function CommercePrice::transform in Commerce Migrate 3.1.x

Same name in this branch
  1. 3.1.x modules/magento/src/Plugin/migrate/process/CommercePrice.php \Drupal\commerce_migrate_magento\Plugin\migrate\process\CommercePrice::transform()
  2. 3.1.x modules/csv_example/src/Plugin/migrate/process/CommercePrice.php \Drupal\commerce_migrate_csv_example\Plugin\migrate\process\CommercePrice::transform()
  3. 3.1.x modules/shopify/src/Plugin/migrate/process/CommercePrice.php \Drupal\commerce_migrate_shopify\Plugin\migrate\process\CommercePrice::transform()
  4. 3.1.x modules/commerce/src/Plugin/migrate/process/commerce1/CommercePrice.php \Drupal\commerce_migrate_commerce\Plugin\migrate\process\commerce1\CommercePrice::transform()
Same name and namespace in other branches
  1. 8.2 modules/csv_example/src/Plugin/migrate/process/CommercePrice.php \Drupal\commerce_migrate_csv_example\Plugin\migrate\process\CommercePrice::transform()
  2. 3.0.x modules/csv_example/src/Plugin/migrate/process/CommercePrice.php \Drupal\commerce_migrate_csv_example\Plugin\migrate\process\CommercePrice::transform()

Performs the associated process.

Parameters

mixed $value: The value to be transformed.

\Drupal\migrate\MigrateExecutableInterface $migrate_executable: The migration in which this process is being executed.

\Drupal\migrate\Row $row: The row from the source to process. Normally, just transforming the value is adequate but very rarely you might need to change two columns at the same time or something like that.

string $destination_property: The destination property currently worked on. This is only used together with the $row above.

Return value

string|array The newly transformed value.

Overrides ProcessPluginBase::transform

File

modules/csv_example/src/Plugin/migrate/process/CommercePrice.php, line 38

Class

CommercePrice
Creates a price array from the input value.

Namespace

Drupal\commerce_migrate_csv_example\Plugin\migrate\process

Code

public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
  if (!is_array($value)) {
    throw new MigrateException(sprintf("Input should be an array, instead it was of type '%s'", gettype($value)));
  }
  $new_value = NULL;
  $number = $value[0];
  if ($number) {
    $new_value = [
      'number' => $number,
      'currency_code' => strtoupper($value[1]),
    ];
  }
  return $new_value;
}