You are here

class OrderAdjustmentShipping in Commerce Migrate 3.0.x

Same name and namespace in other branches
  1. 8.2 modules/commerce/src/Plugin/migrate/process/commerce1/OrderAdjustmentShipping.php \Drupal\commerce_migrate_commerce\Plugin\migrate\process\commerce1\OrderAdjustmentShipping
  2. 3.1.x modules/commerce/src/Plugin/migrate/process/commerce1/OrderAdjustmentShipping.php \Drupal\commerce_migrate_commerce\Plugin\migrate\process\commerce1\OrderAdjustmentShipping

Builds an array of adjustment data.

Plugin annotation


@MigrateProcessPlugin(
  id = "commerce1_order_adjustment_shipping"
)

Hierarchy

Expanded class hierarchy of OrderAdjustmentShipping

1 file declares its use of OrderAdjustmentShipping
OrderAdjustmentShippingTest.php in modules/commerce/tests/src/Unit/Plugin/migrate/process/commerce1/OrderAdjustmentShippingTest.php

File

modules/commerce/src/Plugin/migrate/process/commerce1/OrderAdjustmentShipping.php, line 17

Namespace

Drupal\commerce_migrate_commerce\Plugin\migrate\process\commerce1
View source
class OrderAdjustmentShipping extends ProcessPluginBase {

  /**
   * {@inheritdoc}
   */
  public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
    $adjustment = [];

    // It is not an error if $value is not an array. In that case return an
    // empty array.
    if (is_array($value)) {
      if (!isset($value['commerce_total'])) {
        throw new MigrateSkipRowException(sprintf("Adjustment does not have a total for destination '%s'", $destination_property));
      }
      $total = $value['commerce_total'][0];
      if (!isset($total['amount'])) {
        throw new MigrateSkipRowException(sprintf("Adjustment total amount does not exist for destination '%s'", $destination_property));
      }
      if (!isset($total['currency_code'])) {
        throw new MigrateSkipRowException(sprintf("Adjustment currency code does not exist for destination '%s'", $destination_property));
      }
      $fraction_digits = isset($total['fraction_digits']) ? $total['fraction_digits'] : '2';

      // Scale the incoming price by the fraction digits.
      $input = [
        'amount' => $total['amount'],
        'fraction_digits' => $fraction_digits,
        'currency_code' => $total['currency_code'],
      ];
      $price = new CommercePrice([], 'price', '');
      $price_scaled = $price
        ->transform($input, $migrate_executable, $row, NULL);

      // Build the adjustment array.
      $adjustment = [
        'type' => 'shipping',
        'label' => isset($value['line_item_label']) ? $value['line_item_label'] : 'Shipping',
        'amount' => $price_scaled['number'],
        'currency_code' => $price_scaled['currency_code'],
        'sourceId' => '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.
OrderAdjustmentShipping::transform public function Performs the associated process. Overrides ProcessPluginBase::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.