public function OrderItemAdjustment::transform in Commerce Migrate 3.1.x
Same name in this branch
- 3.1.x modules/ubercart/src/Plugin/migrate/process/OrderItemAdjustment.php \Drupal\commerce_migrate_ubercart\Plugin\migrate\process\OrderItemAdjustment::transform()
- 3.1.x modules/commerce/src/Plugin/migrate/process/commerce1/OrderItemAdjustment.php \Drupal\commerce_migrate_commerce\Plugin\migrate\process\commerce1\OrderItemAdjustment::transform()
Same name and namespace in other branches
- 8.2 modules/ubercart/src/Plugin/migrate/process/OrderItemAdjustment.php \Drupal\commerce_migrate_ubercart\Plugin\migrate\process\OrderItemAdjustment::transform()
- 3.0.x modules/ubercart/src/Plugin/migrate/process/OrderItemAdjustment.php \Drupal\commerce_migrate_ubercart\Plugin\migrate\process\OrderItemAdjustment::transform()
Performs the associated process.
Parameters
mixed $value: The value to be transformed.
\Drupal\migrate\MigrateExecutableInterface $migrate_executable: The migration in which this process is being executed.
\Drupal\migrate\Row $row: The row from the source to process. Normally, just transforming the value is adequate but very rarely you might need to change two columns at the same time or something like that.
string $destination_property: The destination property currently worked on. This is only used together with the $row above.
Return value
string|array The newly transformed value.
Overrides ProcessPluginBase::transform
File
- modules/
ubercart/ src/ Plugin/ migrate/ process/ OrderItemAdjustment.php, line 129
Class
- OrderItemAdjustment
- Builds an array of adjustment data.
Namespace
Drupal\commerce_migrate_ubercart\Plugin\migrate\processCode
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$adjustment = [];
if (is_array($value)) {
$adj_type = '';
$percentage = NULL;
if (!empty($value['type'])) {
if ($value['type'] === 'tax' || $value['type'] === 'generic') {
$adj_type = 'tax';
$percentage = !empty($value['data']['tax_rate']) ? $value['data']['tax_rate'] : $percentage;
}
if ($value['type'] === 'coupon') {
$adj_type = 'promotion';
}
}
if ($adj_type === '') {
throw new MigrateSkipRowException(sprintf("Unknown adjustment type '%s' for line item '%s'.", $value['type'], $value['line_item_id']));
}
$label = !empty($value['title']) ? $value['title'] : '';
// Distribute the adjustment across all product line items.
$num_product_line = $row
->getSourceProperty('num_product_line');
$price = new Price((string) $value['amount'], $value['currency_code']);
$price = $this->rounder
->round($price);
$last_line = FALSE;
if ($row
->getSourceProperty('order_product_id') == $row
->getSourceProperty('max_order_product_id')) {
$last_line = TRUE;
}
$amount = $this
->split($num_product_line, $last_line, $price);
if ($amount) {
$adjustment = [
'type' => $adj_type,
'label' => $label,
'amount' => $amount
->getNumber(),
'currency_code' => $amount
->getCurrencyCode(),
'percentage' => $percentage,
'source_id' => 'custom',
'included' => FALSE,
'locked' => TRUE,
];
}
}
return $adjustment;
}