diff --git a/src/Profile/Shopware/Gateway/Local/Reader/CustomerReader.php b/src/Profile/Shopware/Gateway/Local/Reader/CustomerReader.php index 2dfbd0ed6..57839b5f8 100644 --- a/src/Profile/Shopware/Gateway/Local/Reader/CustomerReader.php +++ b/src/Profile/Shopware/Gateway/Local/Reader/CustomerReader.php @@ -87,7 +87,21 @@ private function fetchCustomers(MigrationContextInterface $migrationContext): ar $query->leftJoin('defaultpayment', 's_core_paymentmeans_attributes', 'defaultpayment_attributes', 'defaultpayment.id = defaultpayment_attributes.paymentmeanID'); $this->addTableSelection($query, 's_core_paymentmeans_attributes', 'defaultpayment_attributes', $migrationContext); - $query->leftJoin('customer', 's_core_locales', 'customerlanguage', 'customer.language = customerlanguage.id'); + // customer.language maps to the shopID and not directly to the localeID + $query->leftJoin( + 'customer', + 's_core_shops', + 'customerlanguageshop', + 'customer.language = customerlanguageshop.id' + ); + + $query->leftJoin( + 'customerlanguageshop', + 's_core_locales', + 'customerlanguage', + 'customerlanguageshop.locale_id = customerlanguage.id' + ); + $this->addTableSelection($query, 's_core_locales', 'customerlanguage', $migrationContext); $query->leftJoin('customer', 's_core_shops', 'shop', 'customer.subshopID = shop.id'); diff --git a/src/Profile/Shopware/Gateway/Local/Reader/LanguageReader.php b/src/Profile/Shopware/Gateway/Local/Reader/LanguageReader.php index f1cff213a..0d3d4148a 100644 --- a/src/Profile/Shopware/Gateway/Local/Reader/LanguageReader.php +++ b/src/Profile/Shopware/Gateway/Local/Reader/LanguageReader.php @@ -86,11 +86,29 @@ private function fetchShopLocaleIds(MigrationContextInterface $migrationContext) private function fetchCustomerLocaleIds(MigrationContextInterface $migrationContext): array { $connection = $this->getConnection($migrationContext); + $query = $connection->createQueryBuilder(); $query->from('s_user', 'customer'); - $query->addSelect('customer.language'); + + $query->leftJoin( + 'customer', + 's_core_shops', + 'customerlanguageshop', + 'customer.language = customerlanguageshop.id' + ); + + $query->leftJoin( + 'customerlanguageshop', + 's_core_locales', + 'customerlocales', + 'customerlanguageshop.locale_id = customerlocales.id' + ); + + $query->addSelect('customerlocales.id'); $query->distinct(); $query->where('customer.language IS NOT NULL'); + $query->andWhere('customerlanguageshop.locale_id IS NOT NULL'); + $query->andWhere('customerlocales.id IS NOT NULL'); return $query->executeQuery()->fetchFirstColumn(); } diff --git a/tests/Profile/Shopware/Gateway/Local/CustomerReaderTest.php b/tests/Profile/Shopware/Gateway/Local/CustomerReaderTest.php index d3272eb1c..3a2e86f3c 100644 --- a/tests/Profile/Shopware/Gateway/Local/CustomerReaderTest.php +++ b/tests/Profile/Shopware/Gateway/Local/CustomerReaderTest.php @@ -74,7 +74,7 @@ public function testRead(): void static::assertSame('5', $data[2]['default_billing_address_id']); static::assertSame('5', $data[2]['default_shipping_address_id']); static::assertSame('prepayment', $data[2]['defaultpayment']['name']); - static::assertSame('de-DE', $data[2]['customerlanguage']['locale']); + static::assertSame('ro-RO', $data[2]['customerlanguage']['locale']); static::assertSame('0', $data[2]['shop']['customer_scope']); static::assertCount(1, $data[2]['addresses']); } diff --git a/tests/Profile/Shopware/Gateway/Local/SalesChannelReaderTest.php b/tests/Profile/Shopware/Gateway/Local/SalesChannelReaderTest.php index ce3fe03a0..67fc8523a 100644 --- a/tests/Profile/Shopware/Gateway/Local/SalesChannelReaderTest.php +++ b/tests/Profile/Shopware/Gateway/Local/SalesChannelReaderTest.php @@ -60,11 +60,15 @@ public function testRead(): void static::assertSame('de-DE', $data[0]['_locale']); static::assertSame('EUR', $data[0]['currency']); - static::assertCount(1, $data[0]['children']); + static::assertCount(2, $data[0]['children']); static::assertSame('39', $data[0]['children'][0]['category_id']); static::assertSame('en-GB', $data[0]['children'][0]['locale']); static::assertSame('de-DE', $data[0]['children'][0]['_locale']); static::assertSame('EUR', $data[0]['children'][0]['currency']); + static::assertSame('39', $data[0]['children'][1]['category_id']); + static::assertSame('ro-RO', $data[0]['children'][1]['locale']); + static::assertSame('de-DE', $data[0]['children'][1]['_locale']); + static::assertSame('EUR', $data[0]['children'][1]['currency']); } public function testReadTotal(): void @@ -79,6 +83,6 @@ public function testReadTotal(): void static::assertNotNull($dataSet); static::assertSame($dataSet::getEntity(), $totalStruct->getEntityName()); - static::assertSame(2, $totalStruct->getTotal()); + static::assertSame(3, $totalStruct->getTotal()); } } diff --git a/tests/_fixtures/database/shopware55.sql b/tests/_fixtures/database/shopware55.sql index beee565e5..262998c41 100644 --- a/tests/_fixtures/database/shopware55.sql +++ b/tests/_fixtures/database/shopware55.sql @@ -4001,7 +4001,7 @@ CREATE TABLE `s_core_shops` ( LOCK TABLES `s_core_shops` WRITE; /*!40000 ALTER TABLE `s_core_shops` DISABLE KEYS */; -INSERT INTO `s_core_shops` VALUES (1,NULL,'Deutsch',NULL,0,'sw55.local','',NULL,'',0,23,23,3,1,1,1,NULL,0,1,1),(2,1,'English','English',0,NULL,NULL,NULL,'',0,NULL,NULL,39,2,1,1,2,0,0,1); +INSERT INTO `s_core_shops` VALUES (1,NULL,'Deutsch',NULL,0,'sw55.local','',NULL,'',0,23,23,3,1,1,1,NULL,0,1,1),(2,1,'English','English',0,NULL,NULL,NULL,'',0,NULL,NULL,39,2,1,1,2,0,0,1),(3, 1, 'Romanian', 'Romanian', 0, NULL, NULL, NULL, '', 0, NULL, NULL, 39, 192, 1, 1, 3, 0, 0, 1); /*!40000 ALTER TABLE `s_core_shops` ENABLE KEYS */; UNLOCK TABLES; @@ -7658,7 +7658,7 @@ CREATE TABLE `s_user` ( LOCK TABLES `s_user` WRITE; /*!40000 ALTER TABLE `s_user` DISABLE KEYS */; -INSERT INTO `s_user` VALUES (1,'a256a310bc1e5db755fd392c524028a8','md5','test@example.com',1,0,'',5,0,NULL,NULL,'2011-11-23','2012-01-04 14:12:05','uiorqd755gaar8dn89ukp178c7',0,'',0,'EK',0,'1',1,'',NULL,'',0,NULL,1,3,NULL,'mr','Max','Mustermann',NULL,'20001',NULL,NULL,'2019-11-13 13:47:27',NULL),(2,'352db51c3ff06159d380d3d9935ec814','md5','mustermann@b2b.de',1,0,'',4,0,NULL,NULL,'2012-08-30','2012-08-30 11:43:17','66e9b10064a19b1fcf6eb9310c0753866c764836',0,'0',0,'H',4,'1',1,'',NULL,'',0,NULL,2,4,NULL,'mr','Händler','Kundengruppe-Netto',NULL,'20003',NULL,NULL,'2019-11-13 13:47:27',NULL),(3,'$2y$10$NVX9a/qzhoo0jS6U3i7YH.jBluI0hsOFqCnw/obStDxxkexPlDuHC','bcrypt','k.luetjann@shopware.com',1,0,'',5,0,NULL,NULL,'2020-02-26','2020-02-26 08:01:53','bioapqo043f3csuoctclulor7t',0,'0',0,'H',0,'1',1,'',NULL,'',0,NULL,5,5,'','mr','Krispin','Luetjann',NULL,'20005','27e8f8d6-a59d-476e-a6f0-9fcbbd03faf1.1','2020-02-26 08:00:31','2020-02-26 07:40:50',NULL); +INSERT INTO `s_user` VALUES (1,'a256a310bc1e5db755fd392c524028a8','md5','test@example.com',1,0,'',5,0,NULL,NULL,'2011-11-23','2012-01-04 14:12:05','uiorqd755gaar8dn89ukp178c7',0,'',0,'EK',0,'1',1,'',NULL,'',0,NULL,1,3,NULL,'mr','Max','Mustermann',NULL,'20001',NULL,NULL,'2019-11-13 13:47:27',NULL),(2,'352db51c3ff06159d380d3d9935ec814','md5','mustermann@b2b.de',1,0,'',4,0,NULL,NULL,'2012-08-30','2012-08-30 11:43:17','66e9b10064a19b1fcf6eb9310c0753866c764836',0,'0',0,'H',4,'1',1,'',NULL,'',0,NULL,2,4,NULL,'mr','Händler','Kundengruppe-Netto',NULL,'20003',NULL,NULL,'2019-11-13 13:47:27',NULL),(3,'$2y$10$NVX9a/qzhoo0jS6U3i7YH.jBluI0hsOFqCnw/obStDxxkexPlDuHC','bcrypt','k.luetjann@shopware.com',1,0,'',5,0,NULL,NULL,'2020-02-26','2020-02-26 08:01:53','bioapqo043f3csuoctclulor7t',0,'0',0,'H',0,'3',3,'',NULL,'',0,NULL,5,5,'','mr','Krispin','Luetjann',NULL,'20005','27e8f8d6-a59d-476e-a6f0-9fcbbd03faf1.1','2020-02-26 08:00:31','2020-02-26 07:40:50',NULL); /*!40000 ALTER TABLE `s_user` ENABLE KEYS */; UNLOCK TABLES;