commerce_export-8.x-1.0-alpha1/src/Plugin/migrate/process/CommercePrice.php
src/Plugin/migrate/process/CommercePrice.php
<?php namespace Drupal\commerce_export\Plugin\migrate\process; use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\ProcessPluginBase; use Drupal\migrate\Row; /** * Creates a price array from the input value. * * Build a keyed array where price is the first value in the input array and the * currency code is the second. If there is no price value, an empty array is * returned. * * Example: * @code * price: * plugin: get_price * source: * - price * - code * @endcode * * When price = 12.00 and code is 'CAD', a keyed array, where 'number' => 12.00 * and 'currency_code => 'CAD'. * * @MigrateProcessPlugin( * id = "get_price" * ) */ class CommercePrice extends ProcessPluginBase { /** * {@inheritdoc} */ public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { $new_value = NULL; $number = $value[0]; if ($number) { $new_value = [ 'number' => $number, 'currency_code' => strtoupper($value[1]), ]; } return $new_value; } }