diff --git a/migration_templates/d6_ubercart_order_product.yml b/migration_templates/d6_ubercart_order_product.yml index dc96519..e41d0d8 100644 --- a/migration_templates/d6_ubercart_order_product.yml +++ b/migration_templates/d6_ubercart_order_product.yml @@ -24,10 +24,13 @@ process: source: nid title: title quantity: qty + currency_code: + plugin: store_default_currency + source: currency 'unit_price/number': price - 'unit_price/currency_code': currency + 'unit_price/currency_code': '@currency_code' 'total_price/number': total_price - 'total_price/currency_code': currency + 'total_price/currency_code': '@currency_code' # Source field name 'data' changed to 'attributes' in prepareRow function data: attributes created: created diff --git a/migration_templates/d6_ubercart_product_variation.yml b/migration_templates/d6_ubercart_product_variation.yml index 9b94e8e..5b10545 100644 --- a/migration_templates/d6_ubercart_product_variation.yml +++ b/migration_templates/d6_ubercart_product_variation.yml @@ -18,8 +18,11 @@ process: default_value: default uid: uid sku: model + currency_code: + plugin: store_default_currency + source: currency 'price/number': sell_price - 'price/currency_code': currency + 'price/currency_code': '@currency_code' status: status created: created changed: changed diff --git a/src/Plugin/migrate/process/DefaultStoreCurrency.php b/src/Plugin/migrate/process/DefaultStoreCurrency.php new file mode 100644 index 0000000..a5518cb --- /dev/null +++ b/src/Plugin/migrate/process/DefaultStoreCurrency.php @@ -0,0 +1,84 @@ +configFactory = $config_factory; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('config.factory') + ); + } + + /** + * {@inheritdoc} + */ + public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { + if (!empty($value)) { + $config = $this->configFactory->get('commerce_price.commerce_currency.' . $value); + if ($config->get('currencyCode')) { + return $value; + } + else { + // TODO: Should have failed before getting here. + return NULL; + } + } + else { + $store_id = 1; + if ($order_id = $row->getSourceProperty('order_id')) { + $order = Order::load($order_id); + $store_id = $order->getStoreId(); + } + $store = Store::load($store_id); + $currency_code = $store->getDefaultCurrencyCode(); + return $currency_code; + } + } + +} diff --git a/src/Plugin/migrate/source/ubercart/d6/OrderProduct.php b/src/Plugin/migrate/source/ubercart/d6/OrderProduct.php index 23c6c95..93f8843 100644 --- a/src/Plugin/migrate/source/ubercart/d6/OrderProduct.php +++ b/src/Plugin/migrate/source/ubercart/d6/OrderProduct.php @@ -19,7 +19,7 @@ class OrderProduct extends SqlBase { $query = $this->select('uc_order_products', 'uop') ->fields('uop', ['order_product_id', 'order_id', 'nid', 'title', 'qty', 'price', 'data']); $query->innerJoin('uc_orders', 'uo', 'uop.order_id = uo.order_id'); - $query->fields('uo', ['created', 'modified', 'currency']); + $query->fields('uo'); return $query; }