class OrderItemAdjustment in Commerce Migrate 3.0.x
Same name in this branch
- 3.0.x modules/ubercart/src/Plugin/migrate/process/OrderItemAdjustment.php \Drupal\commerce_migrate_ubercart\Plugin\migrate\process\OrderItemAdjustment
- 3.0.x modules/commerce/src/Plugin/migrate/process/commerce1/OrderItemAdjustment.php \Drupal\commerce_migrate_commerce\Plugin\migrate\process\commerce1\OrderItemAdjustment
Same name and namespace in other branches
- 8.2 modules/commerce/src/Plugin/migrate/process/commerce1/OrderItemAdjustment.php \Drupal\commerce_migrate_commerce\Plugin\migrate\process\commerce1\OrderItemAdjustment
- 3.1.x modules/commerce/src/Plugin/migrate/process/commerce1/OrderItemAdjustment.php \Drupal\commerce_migrate_commerce\Plugin\migrate\process\commerce1\OrderItemAdjustment
Builds an array of adjustment data.
This plugin creates an adjustment array from data from uc_order_line_items.
The input value:
- name: Component name.
- price: An array with keys 'amount', 'currency_code' and 'data'.
- included: True if included in the price.
adjustments:
-
plugin: commerce1_order_item_adjustment
source: commerce_total/0/data/components
adjustments:
Plugin annotation
@MigrateProcessPlugin(
id = "commerce1_order_item_adjustment"
)
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\CommercePrice
- class \Drupal\commerce_migrate_commerce\Plugin\migrate\process\commerce1\OrderItemAdjustment
- class \Drupal\commerce_migrate_commerce\Plugin\migrate\process\commerce1\CommercePrice
- class \Drupal\migrate\ProcessPluginBase implements MigrateProcessInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of OrderItemAdjustment
File
- modules/
commerce/ src/ Plugin/ migrate/ process/ commerce1/ OrderItemAdjustment.php, line 31
Namespace
Drupal\commerce_migrate_commerce\Plugin\migrate\process\commerce1View source
class OrderItemAdjustment extends CommercePrice {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$adjustment = [];
if (is_array($value)) {
if (empty($value['name'])) {
throw new MigrateSkipRowException(sprintf("Adjustment has no name for line item '%s'.", $row
->getSourceProperty('line_item_id')));
}
if ($value['name'] !== 'base_price') {
$parts = explode('|', $value['name'], -1);
if (!empty($parts)) {
$percentage = NULL;
$type = '';
$label = '';
$amount = (string) $value['price']['amount'];
$currency_code = $value['price']['currency_code'];
if ($parts[0] === 'tax') {
$type = 'tax';
$tax_rate = $value['price']['data']['tax_rate'];
$label = $tax_rate['display_title'];
$percentage = $tax_rate['rate'];
}
if ($parts[0] === 'discount') {
$type = 'promotion';
$label = $value['price']['data']['discount_component_title'];
}
if (empty($type)) {
throw new MigrateSkipRowException(sprintf("Unknown adjustment type for line item '%s'.", $row
->getSourceProperty('line_item_id')));
}
// Scale the incoming price by the fraction digits.
$fraction_digits = isset($value['price']['fraction_digits']) ? $value['price']['fraction_digits']['fraction_digits'] : '2';
$input = [
'amount' => $amount,
'fraction_digits' => $fraction_digits,
'currency_code' => $currency_code,
];
$price_scaled = parent::transform($input, $migrate_executable, $row, NULL);
$adjustment = [
'type' => $type,
'label' => $label,
'amount' => $price_scaled['number'],
'currency_code' => $currency_code,
'percentage' => $percentage,
'source_id' => '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. | |
OrderItemAdjustment:: |
public | function |
Performs the associated process. Overrides CommercePrice:: |
|
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. |