diff --git a/modules/ubercart/src/Plugin/migrate/source/uc6/Order.php b/modules/ubercart/src/Plugin/migrate/source/uc6/Order.php index 03fede2..8d7f3cd 100644 --- a/modules/ubercart/src/Plugin/migrate/source/uc6/Order.php +++ b/modules/ubercart/src/Plugin/migrate/source/uc6/Order.php @@ -29,6 +29,12 @@ class Order extends DrupalSqlBase { protected $moduleHandler; /** + * Indicates if commerce_shipping is enabled. + * + * @var bool + */ + protected $commerceShippingEnabled = FALSE; + /** * {@inheritdoc} */ public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, StateInterface $state, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler) { @@ -56,6 +62,7 @@ class Order extends DrupalSqlBase { * {@inheritdoc} */ public function query() { + $this->commerceShippingEnabled = $this->moduleHandler->moduleExists('commerce_shipping'); return $this->select('uc_orders', 'uo')->fields('uo'); } @@ -120,14 +127,14 @@ class Order extends DrupalSqlBase { ->condition('uol.order_id', $order_id); $query->innerJoin('uc_orders', 'uo', 'uol.order_id = uo.order_id'); $adjustments = $query->execute()->fetchAll(); - // The line item type depends on whether commerce_shipping is installed. - // Save the state here for the UbercartLineItem process plugin. - $type = $this->moduleHandler->moduleExists('commerce_shipping') ? 'shipping' : 'custom';; $currency_code = $this->variableGet('uc_currency_code', 'USD'); foreach ($adjustments as &$adjustment) { $adjustment['currency_code'] = $currency_code; - $adjustment['type'] = $type; + // The line item type depends on whether commerce_shipping is installed. + if (($adjustment['type'] === 'shipping') && (!$this->commerceShippingEnabled)) { + $adjustment['type'] = 'custom'; + } } return $adjustments; } diff --git a/modules/ubercart/tests/src/Kernel/Plugin/migrate/source/uc6/OrderTest.php b/modules/ubercart/tests/src/Kernel/Plugin/migrate/source/uc6/OrderTest.php index 01ab5fa..d06b156 100644 --- a/modules/ubercart/tests/src/Kernel/Plugin/migrate/source/uc6/OrderTest.php +++ b/modules/ubercart/tests/src/Kernel/Plugin/migrate/source/uc6/OrderTest.php @@ -18,8 +18,9 @@ class OrderTest extends MigrateSqlSourceTestBase { * {@inheritdoc} */ public static $modules = [ - 'migrate_drupal', 'commerce_migrate_ubercart', + 'commerce_shipping', + 'migrate_drupal', ]; /** @@ -98,6 +99,27 @@ class OrderTest extends MigrateSqlSourceTestBase { 'currency' => 'USD', ], ]; + $tests[0]['source_data']['uc_order_line_items'] = + [ + [ + 'line_item_id' => '1', + 'order_id' => '1', + 'type' => 'shipping', + 'title' => 'Z Transport', + 'amount' => '9.99', + 'weight' => '1', + 'data' => 'N;', + ], + [ + 'line_item_id' => '2', + 'order_id' => '2', + 'type' => 'custom', + 'title' => 'xyz', + 'amount' => '5.00', + 'weight' => '2', + 'data' => 'N;', + ], + ]; $tests[0]['source_data']['uc_order_products'] = [ [ @@ -166,6 +188,18 @@ class OrderTest extends MigrateSqlSourceTestBase { 'modified' => '1498620003', 'host' => '192.168.0.2', 'order_item_ids' => [1, 3, 4], + 'adjustments' => [ + [ + 'line_item_id' => '1', + 'order_id' => '1', + 'type' => 'shipping', + 'title' => 'Z Transport', + 'amount' => '9.99', + 'weight' => '1', + 'data' => 'N;', + 'currency_code' => 'USD', + ], + ], ], [ 'order_id' => '2', @@ -177,6 +211,18 @@ class OrderTest extends MigrateSqlSourceTestBase { 'modified' => '1498630003', 'host' => '192.168.0.2', 'order_item_ids' => [9], + 'adjustments' => [ + [ + 'line_item_id' => '2', + 'order_id' => '2', + 'type' => 'custom', + 'title' => 'xyz', + 'amount' => '5.00', + 'weight' => '2', + 'data' => 'N;', + 'currency_code' => 'USD', + ], + ], ], ]; return $tests;