You are here

class OrderItemAdjustment in Commerce Migrate 3.1.x

Same name in this branch
  1. 3.1.x modules/ubercart/src/Plugin/migrate/process/OrderItemAdjustment.php \Drupal\commerce_migrate_ubercart\Plugin\migrate\process\OrderItemAdjustment
  2. 3.1.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
  1. 8.2 modules/commerce/src/Plugin/migrate/process/commerce1/OrderItemAdjustment.php \Drupal\commerce_migrate_commerce\Plugin\migrate\process\commerce1\OrderItemAdjustment
  2. 3.0.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

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\commerce1
View 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

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property
DependencySerializationTrait::$_serviceIds protected property
DependencySerializationTrait::__sleep public function 2
DependencySerializationTrait::__wakeup public function 2
MessengerTrait::$messenger protected property The messenger. 27
MessengerTrait::messenger public function Gets the messenger. 27
MessengerTrait::setMessenger public function Sets the messenger.
OrderItemAdjustment::transform public function Performs the associated process. Overrides CommercePrice::transform
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 2
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
PluginBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. 98
ProcessPluginBase::multiple public function Indicates whether the returned value requires multiple handling. Overrides MigrateProcessInterface::multiple 3
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.