Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/Profile/Shopware/Gateway/Local/Reader/CustomerReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
20 changes: 19 additions & 1 deletion src/Profile/Shopware/Gateway/Local/Reader/LanguageReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
}
}
4 changes: 2 additions & 2 deletions tests/_fixtures/database/shopware55.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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);

@jozsefdamokos Jozsef Damokos (jozsefdamokos) Jun 9, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this addition here.

Instead we should add this special scenario in CustomerReaderTest andLanguageReaderTest

// in setUp method:
$this->dbConnection->executeStatement(
    'INSERT INTO s_core_shops (
        id, name, position, hosts, secure, locale_id, customer_scope, `default`, active
    ) VALUES (
        999, "English shop", 0, "", 0, 2, 0, 0, 1
    )'
);

$this->dbConnection->executeStatement('UPDATE s_user SET language = :language WHERE id = :id', [
    'language' => 999,
    'id' => 1,
]);

in LanguageReaderTest we can remove testReadIncludesCustomerLocalesOutsideShopLocales so it becomes something like:

class LanguageReaderTest extends TestCase
{
    use LocalCredentialTrait;

    private LanguageReader $languageReader;

    private MigrationContext $migrationContext;

    private Connection $dbConnection;

    protected function setUp(): void
    {
        $this->connectionSetup();

        $connectionFactory = new ConnectionFactory();
        $this->languageReader = new LanguageReader($connectionFactory);

        $this->migrationContext = new MigrationContext(
            $this->connection,
            new Shopware55Profile(),
            null,
            new LanguageDataSet(),
            $this->runId,
            0,
            10
        );

        $this->migrationContext->setGateway(new DummyLocalGateway());

        $this->dbConnection = $connectionFactory->createDatabaseConnection($this->migrationContext);

        $this->dbConnection->executeStatement(
            'INSERT INTO s_core_shops (
                id, name, position, hosts, secure, locale_id, customer_scope, `default`, active
            ) VALUES (
                999, "English shop", 0, "", 0, 2, 0, 0, 1
            )'
        );
        $this->dbConnection->executeStatement('UPDATE s_user SET language = :language WHERE id = :id', [
            'language' => 999,
            'id' => 1,
        ]);
    }

    protected function tearDown(): void
    {
        $this->dbConnection->executeStatement('UPDATE s_user SET language = :language WHERE id = :id', [
            'language' => 1,
            'id' => 1,
        ]);
        $this->dbConnection->executeStatement('DELETE FROM s_core_shops WHERE id = :id', [
            'id' => 999,
        ]);
    }

    public function testRead(): void
    {
        static::assertTrue($this->languageReader->supports($this->migrationContext));

        $data = $this->languageReader->read($this->migrationContext);
        $locales = \array_column($data, 'locale');

        static::assertCount(2, $data);
        static::assertContains('de-DE', $locales);
        static::assertContains('en-GB', $locales);
        static::assertNotContains('bn-IN', $locales);
    }
}

/*!40000 ALTER TABLE `s_core_shops` ENABLE KEYS */;
UNLOCK TABLES;

Expand Down Expand Up @@ -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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, please revert

/*!40000 ALTER TABLE `s_user` ENABLE KEYS */;
UNLOCK TABLES;

Expand Down
Loading