forked from shopware/shopware
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes shopware#3455
- Loading branch information
Showing
7 changed files
with
180 additions
and
4 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
changelog/_unreleased/2023-12-04-fix-download-link-mail.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
title: Fix download link mail | ||
issue: NEXT-00000 | ||
author: Elias Lackner | ||
author_email: [email protected] | ||
author_github: @lacknere | ||
--- | ||
# Core | ||
* Changed `downloads_delivery` mail fixtures to use `rawUrl` instead of `url` for product download link to use the correct sales channel. | ||
* Added new migration `Migration1701688920FixDownloadLinkMail` to update `downloads_delivery` mail templates. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/Core/Migration/V6_6/Migration1701688920FixDownloadLinkMail.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Shopware\Core\Migration\V6_6; | ||
|
||
use Doctrine\DBAL\Connection; | ||
use Shopware\Core\Content\MailTemplate\MailTemplateTypes; | ||
use Shopware\Core\Framework\Log\Package; | ||
use Shopware\Core\Framework\Migration\MigrationStep; | ||
use Shopware\Core\Migration\Traits\MailUpdate; | ||
use Shopware\Core\Migration\Traits\UpdateMailTrait; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
#[Package('core')] | ||
class Migration1701688920FixDownloadLinkMail extends MigrationStep | ||
{ | ||
use UpdateMailTrait; | ||
|
||
public function getCreationTimestamp(): int | ||
{ | ||
return 1701688920; | ||
} | ||
|
||
public function update(Connection $connection): void | ||
{ | ||
$update = new MailUpdate( | ||
MailTemplateTypes::MAILTYPE_DOWNLOADS_DELIVERY, | ||
(string) file_get_contents(__DIR__ . '/../Fixtures/mails/downloads_delivery/en-plain.html.twig'), | ||
(string) file_get_contents(__DIR__ . '/../Fixtures/mails/downloads_delivery/en-html.html.twig'), | ||
(string) file_get_contents(__DIR__ . '/../Fixtures/mails/downloads_delivery/de-plain.html.twig'), | ||
(string) file_get_contents(__DIR__ . '/../Fixtures/mails/downloads_delivery/de-html.html.twig') | ||
); | ||
|
||
$this->updateMail($update, $connection); | ||
} | ||
|
||
public function updateDestructive(Connection $connection): void | ||
{ | ||
// implement update destructive | ||
} | ||
} |
124 changes: 124 additions & 0 deletions
124
tests/migration/Core/V6_6/Migration1701688920FixDownloadLinkMailTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Shopware\Tests\Migration\Core\V6_6; | ||
|
||
use Doctrine\DBAL\Connection; | ||
use Doctrine\DBAL\Exception; | ||
use PHPUnit\Framework\TestCase; | ||
use Shopware\Core\Content\MailTemplate\MailTemplateTypes; | ||
use Shopware\Core\Framework\Test\TestCaseBase\KernelLifecycleManager; | ||
use Shopware\Core\Migration\V6_6\Migration1701688920FixDownloadLinkMail; | ||
use Shopware\Tests\Migration\MigrationTestTrait; | ||
|
||
/** | ||
* @internal | ||
* | ||
* @covers \Shopware\Core\Migration\V6_6\Migration1701688920FixDownloadLinkMail | ||
*/ | ||
class Migration1701688920FixDownloadLinkMailTest extends TestCase | ||
{ | ||
use MigrationTestTrait; | ||
|
||
public function testCreationTimestamp(): void | ||
{ | ||
$migration = new Migration1701688920FixDownloadLinkMail(); | ||
static::assertSame(1701688920, $migration->getCreationTimestamp()); | ||
} | ||
|
||
public function testMailTemplateUpdated(): void | ||
{ | ||
$connection = KernelLifecycleManager::getConnection(); | ||
|
||
$migration = new Migration1701688920FixDownloadLinkMail(); | ||
$migration->update($connection); | ||
|
||
$deLangId = $this->fetchLanguageId($connection, 'de-DE'); | ||
$enLangId = $this->fetchLanguageId($connection, 'en-GB'); | ||
static::assertNotNull($deLangId); | ||
static::assertNotNull($enLangId); | ||
|
||
$template = [ | ||
'id' => $this->fetchSystemMailTemplateIdFromType( | ||
$connection, | ||
MailTemplateTypes::MAILTYPE_DOWNLOADS_DELIVERY | ||
), | ||
'htmlDe' => (string) file_get_contents(__DIR__ . '/../../../../src/Core/Migration/Fixtures/mails/downloads_delivery/de-html.html.twig'), | ||
'plainDe' => (string) file_get_contents(__DIR__ . '/../../../../src/Core/Migration/Fixtures/mails/downloads_delivery/de-plain.html.twig'), | ||
'htmlEn' => (string) file_get_contents(__DIR__ . '/../../../../src/Core/Migration/Fixtures/mails/downloads_delivery/en-html.html.twig'), | ||
'plainEn' => (string) file_get_contents(__DIR__ . '/../../../../src/Core/Migration/Fixtures/mails/downloads_delivery/en-plain.html.twig'), | ||
]; | ||
|
||
$mailTemplateTranslationDe = $this->getMailTemplateTranslation( | ||
$connection, | ||
$template, | ||
$deLangId | ||
); | ||
|
||
static::assertEquals($mailTemplateTranslationDe['htmlDe'], $mailTemplateTranslationDe['content_html']); | ||
static::assertEquals($mailTemplateTranslationDe['plainDe'], $mailTemplateTranslationDe['content_plain']); | ||
|
||
$mailTemplateTranslationEn = $this->getMailTemplateTranslation( | ||
$connection, | ||
$template, | ||
$enLangId | ||
); | ||
|
||
static::assertEquals($mailTemplateTranslationEn['htmlEn'], $mailTemplateTranslationEn['content_html']); | ||
static::assertEquals($mailTemplateTranslationEn['plainEn'], $mailTemplateTranslationEn['content_plain']); | ||
} | ||
|
||
/** | ||
* @param array<string, string|null> $template | ||
* | ||
* @throws Exception | ||
* | ||
* @return array<string, string> | ||
*/ | ||
private function getMailTemplateTranslation(Connection $connection, array $template, string $langId): array | ||
{ | ||
$sqlString = 'SELECT `content_plain`, `content_html` from `mail_template_translation` WHERE `mail_template_id`= :templateId AND `language_id` = :langId AND `updated_at` IS NULL'; | ||
|
||
static::assertNotNull($template['id']); | ||
$translation = $connection->fetchAssociative($sqlString, [ | ||
'langId' => $langId, | ||
'templateId' => $template['id'], | ||
]); | ||
|
||
if (!$translation) { | ||
static::fail('mail template content empty'); | ||
} | ||
|
||
return array_merge($template, ['content_html' => $translation['content_html'], 'content_plain' => $translation['content_plain']]); | ||
} | ||
|
||
/** | ||
* @throws \Doctrine\DBAL\Driver\Exception | ||
* @throws Exception | ||
*/ | ||
private function fetchSystemMailTemplateIdFromType(Connection $connection, string $type): ?string | ||
{ | ||
$templateTypeId = $connection->executeQuery(' | ||
SELECT `id` from `mail_template_type` WHERE `technical_name` = :type | ||
', ['type' => $type])->fetchOne(); | ||
|
||
$templateId = $connection->executeQuery(' | ||
SELECT `id` from `mail_template` WHERE `mail_template_type_id` = :typeId AND `system_default` = 1 AND `updated_at` IS NULL | ||
', ['typeId' => $templateTypeId])->fetchOne(); | ||
|
||
if ($templateId === false || !\is_string($templateId)) { | ||
return null; | ||
} | ||
|
||
return $templateId; | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
private function fetchLanguageId(Connection $connection, string $code): ?string | ||
{ | ||
return $connection->fetchOne(' | ||
SELECT `language`.`id` FROM `language` INNER JOIN `locale` ON `language`.`locale_id` = `locale`.`id` WHERE `code` = :code LIMIT 1 | ||
', ['code' => $code]) ?: null; | ||
} | ||
} |