diff --git a/modules/ubercart/migrations/uc6_product_variation.yml b/modules/ubercart/migrations/uc6_product_variation.yml index 3d32a4d..9c0a6b2 100644 --- a/modules/ubercart/migrations/uc6_product_variation.yml +++ b/modules/ubercart/migrations/uc6_product_variation.yml @@ -15,7 +15,7 @@ process: # 'default' is the default 'commerce_product_variation' bundle initially # installed default_value: default - uid: uid + uid: node_uid sku: model title: title 'price/number': sell_price diff --git a/modules/ubercart/src/Plugin/migrate/source/uc6/ProductVariation.php b/modules/ubercart/src/Plugin/migrate/source/uc6/ProductVariation.php index 6370d87..6c91155 100644 --- a/modules/ubercart/src/Plugin/migrate/source/uc6/ProductVariation.php +++ b/modules/ubercart/src/Plugin/migrate/source/uc6/ProductVariation.php @@ -3,7 +3,7 @@ namespace Drupal\commerce_migrate_ubercart\Plugin\migrate\source\uc6; use Drupal\migrate\Row; -use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase; +use Drupal\node\Plugin\migrate\source\d6\Node; /** * Ubercart 6 product variation source. @@ -13,28 +13,15 @@ use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase; * source_module = "uc_product" * ) */ -class ProductVariation extends DrupalSqlBase { +class ProductVariation extends Node { /** * {@inheritdoc} */ public function query() { - $query = $this->select('node', 'n')->fields('n', [ - 'nid', - 'vid', - 'type', - 'title', - 'uid', - 'created', - 'changed', - 'status', - ]); + $query = parent::query(); $query->innerJoin('uc_products', 'ucp', 'n.nid = ucp.nid AND n.vid = ucp.vid'); $query->fields('ucp', ['model', 'sell_price']); - $query->distinct(); - if (isset($this->configuration['node_type'])) { - $query->condition('n.type', $this->configuration['node_type']); - } return $query; } @@ -42,18 +29,14 @@ class ProductVariation extends DrupalSqlBase { * {@inheritdoc} */ public function fields() { - return ([ - 'nid' => $this->t('Node ID'), - 'vid' => $this->t('Node revision ID'), - 'title' => $this->t('Product title'), - 'type' => $this->t('Product type'), + $fields = [ + 'vid' => t('The primary identifier for this version.'), + 'log' => $this->t('Revision Log message'), 'uid' => $this->t('Node UID.'), - 'status' => $this->t('Node status'), - 'created' => $this->t('Node created time'), - 'changed' => $this->t('Node changed time'), 'model' => $this->t('SKU code'), 'sell_price' => $this->t('Product price'), - ]); + ]; + return parent::fields() + $fields; } /** diff --git a/modules/ubercart/tests/src/Kernel/Plugin/migrate/source/uc6/ProductVariationTest.php b/modules/ubercart/tests/src/Kernel/Plugin/migrate/source/uc6/ProductVariationTest.php index 2bee899..69d08e1 100644 --- a/modules/ubercart/tests/src/Kernel/Plugin/migrate/source/uc6/ProductVariationTest.php +++ b/modules/ubercart/tests/src/Kernel/Plugin/migrate/source/uc6/ProductVariationTest.php @@ -16,7 +16,7 @@ class ProductVariationTest extends MigrateSqlSourceTestBase { /** * {@inheritdoc} */ - public static $modules = ['migrate_drupal', 'commerce_migrate_ubercart']; + public static $modules = ['node', 'migrate_drupal', 'commerce_migrate_ubercart']; /** * {@inheritdoc} @@ -76,6 +76,42 @@ class ProductVariationTest extends MigrateSqlSourceTestBase { 'tnid' => 0, ], ]; + $tests[0]['source_data']['node_revisions'] = [ + [ + 'nid' => 1, + 'vid' => 1, + 'uid' => 1, + 'title' => 'node title 1', + 'body' => 'body for node 1', + 'teaser' => 'teaser for node 1', + 'log' => '', + 'format' => 1, + 'timestamp' => 1279051598, + ], + [ + 'nid' => 2, + 'vid' => 2, + 'uid' => 1, + 'title' => 'ship 1', + 'body' => 'body for node 2', + 'teaser' => 'teaser for node 2', + 'log' => '', + 'format' => 1, + 'timestamp' => 1279308993, + ], + [ + 'nid' => 3, + 'vid' => 3, + 'uid' => 1, + 'title' => 'product 1', + 'body' => 'body for node 3', + 'teaser' => 'teaser for node 3', + 'log' => '', + 'format' => 1, + 'timestamp' => 1279308993, + ], + ]; + $tests[0]['source_data']['uc_products'] = [ [ 'vid' => '2', @@ -123,26 +159,52 @@ class ProductVariationTest extends MigrateSqlSourceTestBase { [ 'nid' => 2, 'vid' => 2, - 'type' => 'ship', + 'language' => 'en', + 'status' => '1', + 'created' => '1279290900', + 'changed' => '1279308000', + 'comment' => '0', + 'promote' => '1', + 'moderate' => '0', + 'sticky' => '0', + 'tnid' => '2', + 'translate' => '0', 'title' => 'ship 1', - 'uid' => 1, - 'status' => 1, - 'created' => 1279290900, - 'changed' => 1279308000, + 'body' => 'body for node 2', + 'teaser' => 'teaser for node 2', + 'log' => '', + 'timestamp' => '1279308993', + 'format' => '1', + 'node_uid' => '1', + 'revision_uid' => '1', 'model' => 'Heart of Gold', 'sell_price' => '900.0000', + 'type' => 'ship', ], [ 'nid' => 3, 'vid' => 3, - 'type' => 'product', + 'language' => 'en', + 'status' => '1', + 'created' => '1279290908', + 'changed' => '1279308993', + 'comment' => '0', + 'promote' => '1', + 'moderate' => '0', + 'sticky' => '0', + 'tnid' => '3', + 'translate' => '0', 'title' => 'product 1', - 'uid' => 1, - 'status' => 1, - 'created' => 1279290908, - 'changed' => 1279308993, + 'body' => 'body for node 3', + 'teaser' => 'teaser for node 3', + 'log' => '', + 'timestamp' => '1279308993', + 'format' => '1', + 'node_uid' => '1', + 'revision_uid' => '1', 'model' => 'book', 'sell_price' => '20.0000', + 'type' => 'product', ], ]; $tests[0]['expected_count'] = 2; @@ -153,14 +215,28 @@ class ProductVariationTest extends MigrateSqlSourceTestBase { [ 'nid' => 2, 'vid' => 2, - 'type' => 'ship', + 'language' => 'en', + 'status' => '1', + 'created' => '1279290900', + 'changed' => '1279308000', + 'comment' => '0', + 'promote' => '1', + 'moderate' => '0', + 'sticky' => '0', + 'tnid' => '2', + 'translate' => '0', 'title' => 'ship 1', - 'uid' => 1, - 'status' => 1, - 'created' => 1279290900, - 'changed' => 1279308000, + 'body' => 'body for node 2', + 'teaser' => 'teaser for node 2', + 'log' => '', + 'timestamp' => '1279308993', + 'format' => '1', + 'node_uid' => '1', + 'revision_uid' => '1', 'model' => 'Heart of Gold', 'sell_price' => '900.0000', + 'type' => 'ship', + ], ]; $tests[1]['expected_count'] = 1;