diff -u b/migration_templates/d6_ubercart_store.yml b/migration_templates/d6_ubercart_store.yml --- b/migration_templates/d6_ubercart_store.yml +++ b/migration_templates/d6_ubercart_store.yml @@ -28,6 +28,14 @@ # Bundle type: 'constants/type' name: uc_store_name + uid: + - + plugin: default_value + default_value: 1 + - + plugin: migration_lookup + migration: d6_user + default_currency: uc_currency_code mail: uc_store_email # Country code is required. If is it null none of the address fields are saved. diff -u b/src/Plugin/migrate/source/ubercart/Store.php b/src/Plugin/migrate/source/ubercart/Store.php --- b/src/Plugin/migrate/source/ubercart/Store.php +++ b/src/Plugin/migrate/source/ubercart/Store.php @@ -18,6 +18,12 @@ * {@inheritdoc} */ public function prepareRow(Row $row) { + $store_owner = $row->getSourceProperty('uc_store_owner'); + $query = $this->select('users', 'u') + ->fields('u', ['uid']) + ->condition('name', $store_owner); + $uid = $query->execute()->fetchField(); + $row->setSourceProperty('uid', $uid); $country = $row->getSourceProperty('uc_store_country'); // Get the country iso code 2 for this country. $query = $this->select('uc_countries', 'ucc') diff -u b/tests/src/Kernel/d6/Ubercart/StoreTest.php b/tests/src/Kernel/d6/Ubercart/StoreTest.php --- b/tests/src/Kernel/d6/Ubercart/StoreTest.php +++ b/tests/src/Kernel/d6/Ubercart/StoreTest.php @@ -25,12 +25,7 @@ protected function setUp() { parent::setUp(); $this->installEntitySchema('commerce_store'); - $this->executeMigrations([ - 'd6_filter_format', - 'd6_user_role', - 'd6_user', - 'd6_ubercart_store' - ]); + $this->migrateStore(); } /** @@ -45,6 +40,7 @@ $this->assertSame('awesome_stuff@example.com', $store->getEmail()); $this->assertSame('NZD', $store->getDefaultCurrencyCode()); $this->assertSame('online', $store->bundle()); + $this->assertSame('1', $store->getOwnerId()); $address = $store->getAddress(); $this->assertInstanceOf(AddressItem::class, $address); only in patch2: unchanged: --- a/migration_templates/d6_ubercart_product.yml +++ b/migration_templates/d6_ubercart_product.yml @@ -26,9 +26,10 @@ process: changed: changed # Fills in variation id from stubs created in product variation migration. 'variations/target_id': - plugin: migration + plugin: migration_lookup migration: d6_ubercart_product_variation source: nid + stores/target_id: stores destination: plugin: entity:commerce_product migration_dependencies: only in patch2: unchanged: --- a/migration_templates/d6_ubercart_product_variation.yml +++ b/migration_templates/d6_ubercart_product_variation.yml @@ -25,3 +25,6 @@ process: changed: changed destination: plugin: entity:commerce_product_variation +migration_dependencies: + required: + - d6_ubercart_store only in patch2: unchanged: --- a/src/Plugin/migrate/source/ubercart/d6/Product.php +++ b/src/Plugin/migrate/source/ubercart/d6/Product.php @@ -16,25 +16,6 @@ use Drupal\migrate\Row; class Product extends SqlBase { /** - * The default store. - * - * @var \Drupal\commerce_store\Entity\StoreInterface - */ - protected $defaultStore; - - /** - * {@inheritdoc} - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, StateInterface $state) { - parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $state); - - $this->defaultStore = \Drupal::service('commerce_store.default_store_resolver')->resolve(); - if (!$this->defaultStore) { - throw new MigrateException('You must have a store saved in order to import products.'); - } - } - - /** * {@inheritdoc} */ public function query() { @@ -88,9 +69,9 @@ class Product extends SqlBase { // ->fetchCol(); // $row->setSourceProperty('images', $image_ids); // @codingStandardsIgnoreEnd - $row->setDestinationProperty('stores', [ - 'target_id' => $this->defaultStore->id(), - ]); + + // Assume an id of 1 because there is only store in Ubercart by default. + $row->setSourceProperty('stores', 1); $row->setSourceProperty('name', str_replace(' ', '_', strtolower($row->getSourceProperty('name')))); return parent::prepareRow($row); only in patch2: unchanged: --- a/tests/src/Kernel/d6/Ubercart/OrderItemTest.php +++ b/tests/src/Kernel/d6/Ubercart/OrderItemTest.php @@ -34,12 +34,9 @@ class OrderItemTest extends Ubercart6TestBase { $this->installEntitySchema('commerce_order_item'); $this->installConfig(['commerce_order']); $this->installConfig(['commerce_product']); - $this->createDefaultStore(); + $this->migrateStore(); $this->startCollectingMessages(); $this->executeMigrations([ - 'd6_filter_format', - 'd6_user_role', - 'd6_user', 'd6_ubercart_billing_profile', 'd6_ubercart_order', 'd6_ubercart_product_variation', only in patch2: unchanged: --- a/tests/src/Kernel/d6/Ubercart/OrderTest.php +++ b/tests/src/Kernel/d6/Ubercart/OrderTest.php @@ -32,7 +32,6 @@ class OrderTest extends Ubercart6TestBase { $this->installEntitySchema('commerce_order'); $this->installEntitySchema('commerce_order_item'); $this->installConfig(['commerce_order']); - $this->createDefaultStore(); $this->startCollectingMessages(); $this->executeMigrations([ 'd6_filter_format', only in patch2: unchanged: --- a/tests/src/Kernel/d6/Ubercart/ProductTest.php +++ b/tests/src/Kernel/d6/Ubercart/ProductTest.php @@ -30,7 +30,7 @@ class ProductTest extends Ubercart6TestBase { $this->installEntitySchema('commerce_product_variation'); $this->installEntitySchema('commerce_product'); $this->installConfig(['commerce_product']); - $this->createDefaultStore(); + $this->migrateStore(); $this->executeMigrations([ 'd6_ubercart_product_variation', 'd6_ubercart_product', only in patch2: unchanged: --- a/tests/src/Kernel/d6/Ubercart/ProductVariationTest.php +++ b/tests/src/Kernel/d6/Ubercart/ProductVariationTest.php @@ -30,7 +30,7 @@ class ProductVariationTest extends Ubercart6TestBase { $this->installEntitySchema('commerce_product_variation'); $this->installEntitySchema('commerce_product'); $this->installConfig(['commerce_product']); - $this->createDefaultStore(); + $this->migrateStore(); $this->executeMigrations([ 'd6_ubercart_product_variation', 'd6_ubercart_product', only in patch2: unchanged: --- a/tests/src/Kernel/d6/Ubercart/Ubercart6TestBase.php +++ b/tests/src/Kernel/d6/Ubercart/Ubercart6TestBase.php @@ -44,29 +44,21 @@ abstract class Ubercart6TestBase extends MigrateDrupal6TestBase { } /** + * Executes store migrations. + */ + protected function migrateStore() { + $this->createCurrency(); + $this->migrateUsers(FALSE); + $this->executeMigration('d6_ubercart_store'); + } + + /** * Creates a default store. */ - protected function createDefaultStore() { + protected function createCurrency() { $currency_importer = \Drupal::service('commerce_price.currency_importer'); - /** @var \Drupal\commerce_store\StoreStorage $store_storage */ - $store_storage = \Drupal::service('entity_type.manager')->getStorage('commerce_store'); - $currency_importer->import('USD'); $currency_importer->import('NZD'); - $store_values = [ - 'type' => 'default', - 'uid' => 1, - 'name' => 'Demo store', - 'mail' => 'admin@example.com', - 'address' => [ - 'country_code' => 'US', - ], - 'default_currency' => 'USD', - ]; - /** @var \Drupal\commerce_store\Entity\StoreInterface $store */ - $store = $store_storage->create($store_values); - $store->save(); - $store_storage->markAsDefault($store); } }