public function OrderItemDiscountAdjustment::transform in Commerce Migrate 8.2
Same name and namespace in other branches
- 3.1.x modules/commerce/src/Plugin/migrate/process/commerce1/OrderItemDiscountAdjustment.php \Drupal\commerce_migrate_commerce\Plugin\migrate\process\commerce1\OrderItemDiscountAdjustment::transform()
- 3.0.x modules/commerce/src/Plugin/migrate/process/commerce1/OrderItemDiscountAdjustment.php \Drupal\commerce_migrate_commerce\Plugin\migrate\process\commerce1\OrderItemDiscountAdjustment::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 CommercePrice::transform
File
- modules/
commerce/ src/ Plugin/ migrate/ process/ commerce1/ OrderItemDiscountAdjustment.php, line 111
Class
- OrderItemDiscountAdjustment
- Builds an array of adjustment data.
Namespace
Drupal\commerce_migrate_commerce\Plugin\migrate\process\commerce1Code
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$adjustment = [];
// Find all price components on the order, not the line item, that are not
// a shipping type and not also in the line item price components.
$order_components = $row
->getSourceProperty('order_components/0/data/components');
$order_names = [];
foreach ($order_components as $order_component) {
$order_names[] = $order_component['name'];
}
$shipping = $row
->getSourceProperty('shipping');
$not_shipping = [];
if (!empty($order_names)) {
$shipping_names = [];
foreach ($shipping as $shipping_item) {
$data = unserialize($shipping_item['data']);
$shipping_names[] = $data['shipping_service']['price_component'];
}
$not_shipping = array_diff($order_names, $shipping_names);
}
if (!empty($not_shipping)) {
foreach ($not_shipping as $item) {
if ($value['name'] === $item) {
$adjustment = $this
->getAdjustment($value, $migrate_executable, $row);
}
}
}
return $adjustment;
}