CommercePrice.php in Commerce Migrate 3.1.x
Same filename in this branch
- 3.1.x modules/magento/src/Plugin/migrate/process/CommercePrice.php
- 3.1.x modules/csv_example/src/Plugin/migrate/process/CommercePrice.php
- 3.1.x modules/shopify/src/Plugin/migrate/process/CommercePrice.php
- 3.1.x modules/commerce/src/Plugin/migrate/process/commerce1/CommercePrice.php
- 3.1.x modules/commerce/src/Plugin/migrate/field/commerce1/CommercePrice.php
Same filename and directory in other branches
File
modules/csv_example/src/Plugin/migrate/process/CommercePrice.phpView source
<?php
namespace Drupal\commerce_migrate_csv_example\Plugin\migrate\process;
use Drupal\migrate\MigrateException;
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: csv_example_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 = "csv_example_get_price"
* )
*/
class CommercePrice extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
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;
}
}
Classes
Name | Description |
---|---|
CommercePrice | Creates a price array from the input value. |