class OrderAdjustmentShipping in Commerce Migrate 3.1.x
Same name and namespace in other branches
- 8.2 modules/commerce/src/Plugin/migrate/process/commerce1/OrderAdjustmentShipping.php \Drupal\commerce_migrate_commerce\Plugin\migrate\process\commerce1\OrderAdjustmentShipping
- 3.0.x modules/commerce/src/Plugin/migrate/process/commerce1/OrderAdjustmentShipping.php \Drupal\commerce_migrate_commerce\Plugin\migrate\process\commerce1\OrderAdjustmentShipping
Builds an array of adjustment data.
Plugin annotation
@MigrateProcessPlugin(
id = "commerce1_order_adjustment_shipping"
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\migrate\ProcessPluginBase implements MigrateProcessInterface
- class \Drupal\commerce_migrate_commerce\Plugin\migrate\process\commerce1\OrderAdjustmentShipping
- class \Drupal\migrate\ProcessPluginBase implements MigrateProcessInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of OrderAdjustmentShipping
1 file declares its use of OrderAdjustmentShipping
- OrderAdjustmentShippingTest.php in modules/
commerce/ tests/ src/ Unit/ Plugin/ migrate/ process/ commerce1/ OrderAdjustmentShippingTest.php
File
- modules/
commerce/ src/ Plugin/ migrate/ process/ commerce1/ OrderAdjustmentShipping.php, line 17
Namespace
Drupal\commerce_migrate_commerce\Plugin\migrate\process\commerce1View source
class OrderAdjustmentShipping extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$adjustment = [];
// It is not an error if $value is not an array. In that case return an
// empty array.
if (is_array($value)) {
if (!isset($value['commerce_total'])) {
throw new MigrateSkipRowException(sprintf("Adjustment does not have a total for destination '%s'", $destination_property));
}
$total = $value['commerce_total'][0];
if (!isset($total['amount'])) {
throw new MigrateSkipRowException(sprintf("Adjustment total amount does not exist for destination '%s'", $destination_property));
}
if (!isset($total['currency_code'])) {
throw new MigrateSkipRowException(sprintf("Adjustment currency code does not exist for destination '%s'", $destination_property));
}
$fraction_digits = isset($total['fraction_digits']) ? $total['fraction_digits'] : '2';
// Scale the incoming price by the fraction digits.
$input = [
'amount' => $total['amount'],
'fraction_digits' => $fraction_digits,
'currency_code' => $total['currency_code'],
];
$price = new CommercePrice([], 'price', '');
$price_scaled = $price
->transform($input, $migrate_executable, $row, NULL);
// Build the adjustment array.
$adjustment = [
'type' => 'shipping',
'label' => isset($value['line_item_label']) ? $value['line_item_label'] : 'Shipping',
'amount' => $price_scaled['number'],
'currency_code' => $price_scaled['currency_code'],
'sourceId' => 'custom',
'included' => FALSE,
'locked' => TRUE,
];
}
return $adjustment;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
OrderAdjustmentShipping:: |
public | function |
Performs the associated process. Overrides ProcessPluginBase:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
2 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 98 |
ProcessPluginBase:: |
public | function |
Indicates whether the returned value requires multiple handling. Overrides MigrateProcessInterface:: |
3 |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |