CommercePrice.php in Commerce Migrate 8.2
Same filename in this branch
- 8.2 modules/magento/src/Plugin/migrate/process/CommercePrice.php
- 8.2 modules/csv_example/src/Plugin/migrate/process/CommercePrice.php
- 8.2 modules/shopify/src/Plugin/migrate/process/CommercePrice.php
- 8.2 modules/commerce/src/Plugin/migrate/process/commerce1/CommercePrice.php
- 8.2 modules/commerce/src/Plugin/migrate/field/commerce1/CommercePrice.php
Same filename and directory in other branches
File
modules/shopify/src/Plugin/migrate/process/CommercePrice.phpView source
<?php
namespace Drupal\commerce_migrate_shopify\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: shopify_commerce_price
* source:
* - price
* - code
* @endcode
*
* When price = 12.00 and code is 'CAD', a an associative array, where
* 'number' => 12.00 and 'currency_code => 'CAD' is returned.
*
* @MigrateProcessPlugin(
* id = "shopify_commerce_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. |