You are here

public function CommercePrice::transform in Commerce Migrate 3.0.x

Same name in this branch
  1. 3.0.x modules/magento/src/Plugin/migrate/process/CommercePrice.php \Drupal\commerce_migrate_magento\Plugin\migrate\process\CommercePrice::transform()
  2. 3.0.x modules/csv_example/src/Plugin/migrate/process/CommercePrice.php \Drupal\commerce_migrate_csv_example\Plugin\migrate\process\CommercePrice::transform()
  3. 3.0.x modules/shopify/src/Plugin/migrate/process/CommercePrice.php \Drupal\commerce_migrate_shopify\Plugin\migrate\process\CommercePrice::transform()
  4. 3.0.x modules/commerce/src/Plugin/migrate/process/commerce1/CommercePrice.php \Drupal\commerce_migrate_commerce\Plugin\migrate\process\commerce1\CommercePrice::transform()
Same name and namespace in other branches
  1. 8.2 modules/commerce/src/Plugin/migrate/process/commerce1/CommercePrice.php \Drupal\commerce_migrate_commerce\Plugin\migrate\process\commerce1\CommercePrice::transform()
  2. 3.1.x modules/commerce/src/Plugin/migrate/process/commerce1/CommercePrice.php \Drupal\commerce_migrate_commerce\Plugin\migrate\process\commerce1\CommercePrice::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

2 calls to CommercePrice::transform()
OrderItemAdjustment::transform in modules/commerce/src/Plugin/migrate/process/commerce1/OrderItemAdjustment.php
Performs the associated process.
OrderItemDiscountAdjustment::getAdjustment in modules/commerce/src/Plugin/migrate/process/commerce1/OrderItemDiscountAdjustment.php
Get the adjustments on this order item.
2 methods override CommercePrice::transform()
OrderItemAdjustment::transform in modules/commerce/src/Plugin/migrate/process/commerce1/OrderItemAdjustment.php
Performs the associated process.
OrderItemDiscountAdjustment::transform in modules/commerce/src/Plugin/migrate/process/commerce1/OrderItemDiscountAdjustment.php
Performs the associated process.

File

modules/commerce/src/Plugin/migrate/process/commerce1/CommercePrice.php, line 63

Class

CommercePrice
Scales the price from Commerce 1 to Commerce 2.

Namespace

Drupal\commerce_migrate_commerce\Plugin\migrate\process\commerce1

Code

public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
  if (!is_array($value)) {
    throw new MigrateSkipRowException(sprintf("CommercePrice input is not an array for destination '%s'", $destination_property));
  }

  // If the destination is a unit price then use the base price component, if
  // if it is available.
  if ($destination_property && strpos('unit_price', (string) $destination_property) !== FALSE) {
    if (isset($value['data']['components'])) {
      foreach ($value['data']['components'] as $component) {
        if ($component['name'] === 'base_price') {
          $value['amount'] = $component['price']['amount'];
          $value['currency_code'] = $component['price']['currency_code'];
          break;
        }
      }
    }
  }
  if (isset($value['amount']) && isset($value['currency_code']) && isset($value['fraction_digits']) && $value['fraction_digits'] >= 0) {
    $new_value = [
      'number' => Calculator::divide($value['amount'], bcpow(10, $value['fraction_digits'])),
      'currency_code' => $value['currency_code'],
    ];
  }
  else {
    throw new MigrateSkipRowException(sprintf("CommercePrice input array is invalid for destination '%s'", $destination_property));
  }
  return $new_value;
}