diff --git a/.github/workflows/store.yml b/.github/workflows/store.yml
index 7b4c748..c3a1288 100644
--- a/.github/workflows/store.yml
+++ b/.github/workflows/store.yml
@@ -2,7 +2,7 @@ name: PackPlugin
on:
push:
branches:
- - 0.2
+ - 0.3
tags:
- '*'
diff --git a/CHANGELOG_de-DE.md b/CHANGELOG_de-DE.md
index 3a6a301..e72dd8b 100644
--- a/CHANGELOG_de-DE.md
+++ b/CHANGELOG_de-DE.md
@@ -1,3 +1,6 @@
+# 0.3.0
+* Kompatiblität zu 6.4
+
# 0.2.2
* Um die Lesbarkeit zu erhöhen, wurden die Boxen für HTML- und TEXT-Mail erhöht
* In den Mail-Details wird nun auch die Uhrzeit des Versands angezeigt
diff --git a/CHANGELOG_en-GB.md b/CHANGELOG_en-GB.md
index 614a0fe..5cfafc4 100644
--- a/CHANGELOG_en-GB.md
+++ b/CHANGELOG_en-GB.md
@@ -1,3 +1,8 @@
+# 0.3.0
+
+* Add compatibility for Shopware 6.4
+
+
# 0.2.2
* To improve readability, the boxes for HTML and TEXT mail have been raised
* The time of sending is now also displayed in the mail details
@@ -5,16 +10,16 @@
# 0.2.1
-* Absender Name hinzugefügt
-* Standardsortierung zu neueste Einträge geändert
+* Sender name added
+* Default sorting changed to newest entries
# 0.2.0
-* Add compability for Shopware 6.3
+* Add compatibility for Shopware 6.3
# 0.1.2
-* Add compability for Shopware 6.2
+* Add compatibility for Shopware 6.2
# 0.1.1
diff --git a/composer.json b/composer.json
index bfcaeca..9a1d12c 100644
--- a/composer.json
+++ b/composer.json
@@ -1,6 +1,6 @@
{
"name": "frosh/mail-platform-archive",
- "version": "0.2.2",
+ "version": "0.3.0",
"description": "Mail Archive",
"type": "shopware-platform-plugin",
"license": "MIT",
@@ -40,6 +40,6 @@
}
},
"require": {
- "shopware/core": "~6.3"
+ "shopware/core": "~6.4.0"
}
}
diff --git a/src/Content/MailArchive/MailArchiveDefinition.php b/src/Content/MailArchive/MailArchiveDefinition.php
index 2abbded..3587c76 100644
--- a/src/Content/MailArchive/MailArchiveDefinition.php
+++ b/src/Content/MailArchive/MailArchiveDefinition.php
@@ -44,7 +44,7 @@ protected function defineFields(): FieldCollection
(new JsonField('receiver', 'receiver'))->addFlags(new Required())->addFlags(new SearchRanking(SearchRanking::HIGH_SEARCH_RANKING)),
(new StringField('subject', 'subject'))->addFlags(new Required())->addFlags(new SearchRanking(SearchRanking::HIGH_SEARCH_RANKING)),
(new LongTextField('plainText', 'plainText'))->addFlags(new AllowHtml()),
- (new LongTextField('htmlText', 'htmlText'))->addFlags(new AllowHtml(), new SearchRanking(SearchRanking::LOW_SEARCH_RAKING)),
+ (new LongTextField('htmlText', 'htmlText'))->addFlags(new AllowHtml(), new SearchRanking(SearchRanking::LOW_SEARCH_RANKING)),
(new LongTextField('eml', 'eml'))->addFlags(new AllowHtml()),
new FkField('salesChannelId', 'salesChannelId', SalesChannelDefinition::class),
diff --git a/src/Controller/Api/MailResendController.php b/src/Controller/Api/MailResendController.php
index cb297b3..74d005b 100644
--- a/src/Controller/Api/MailResendController.php
+++ b/src/Controller/Api/MailResendController.php
@@ -3,7 +3,7 @@
namespace Frosh\MailArchive\Controller\Api;
use Frosh\MailArchive\Content\MailArchive\MailArchiveEntity;
-use Shopware\Core\Content\MailTemplate\Service\MailSender;
+use Frosh\MailArchive\Services\MailSender;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
@@ -13,24 +13,17 @@
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
+use Symfony\Component\Mime\Address;
+use Symfony\Component\Mime\Email;
use Symfony\Component\Routing\Annotation\Route;
class MailResendController extends AbstractController
{
- /**
- * @var EntityRepositoryInterface
- */
- private $mailArchiveRepository;
+ private EntityRepositoryInterface $mailArchiveRepository;
- /**
- * @var MailSender
- */
- private $mailSender;
+ private MailSender $mailSender;
- /**
- * @var RequestStack
- */
- private $requestStack;
+ private RequestStack $requestStack;
public function __construct(EntityRepositoryInterface $mailArchiveRepository, MailSender $mailSender, RequestStack $requestStack)
{
@@ -41,7 +34,7 @@ public function __construct(EntityRepositoryInterface $mailArchiveRepository, Ma
/**
* @RouteScope(scopes={"api"})
- * @Route(path="/api/v{version}/_action/frosh-mail-archive/resend-mail")
+ * @Route(path="/api/_action/frosh-mail-archive/resend-mail")
*/
public function resend(Request $request)
{
@@ -60,22 +53,20 @@ public function resend(Request $request)
$this->requestStack->getMasterRequest()->attributes->set(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_ID, $mailArchive->getSalesChannelId());
- $message = new \Swift_Message();
+ $message = new Email();
foreach ($mailArchive->getReceiver() as $mail => $name) {
- $message->addTo($mail, $name);
+ $message->addTo(new Address($mail, $name));
}
- $message->setFrom($mailArchive->getSender());
- $message->setSubject($mailArchive->getSubject());
-
- if (!empty($mailArchive->getPlainText())) {
- $message->addPart($mailArchive->getPlainText(), 'text/plain');
+ foreach ($mailArchive->getSender() as $mail => $name) {
+ $message->from(new Address($mail, $name));
}
- if (!empty($mailArchive->getHtmlText())) {
- $message->addPart($mailArchive->getHtmlText(), 'text/html');
- }
+ $message->subject($mailArchive->getSubject());
+
+ $message->html($mailArchive->getHtmlText());
+ $message->text($mailArchive->getPlainText());
$this->mailSender->send($message);
diff --git a/src/Migration/Migration1575569953createTable.php b/src/Migration/Migration1575569953createTable.php
index afce0b0..8b4fe77 100644
--- a/src/Migration/Migration1575569953createTable.php
+++ b/src/Migration/Migration1575569953createTable.php
@@ -14,7 +14,7 @@ public function getCreationTimestamp(): int
public function update(Connection $connection): void
{
- $connection->executeQuery('CREATE TABLE `frosh_mail_archive` (
+ $connection->executeStatement('CREATE TABLE `frosh_mail_archive` (
`id` BINARY(16) NOT NULL,
`sender` VARCHAR(255) NOT NULL,
`receiver` JSON NOT NULL,
diff --git a/src/Migration/Migration1598204175SenderToJson.php b/src/Migration/Migration1598204175SenderToJson.php
index 18fde6c..59ca108 100644
--- a/src/Migration/Migration1598204175SenderToJson.php
+++ b/src/Migration/Migration1598204175SenderToJson.php
@@ -14,8 +14,8 @@ public function getCreationTimestamp(): int
public function update(Connection $connection): void
{
- $connection->executeUpdate('UPDATE frosh_mail_archive SET sender = JSON_OBJECT(sender, \'\')');
- $connection->executeUpdate('ALTER TABLE `frosh_mail_archive`
+ $connection->executeStatement('UPDATE frosh_mail_archive SET sender = JSON_OBJECT(sender, \'\')');
+ $connection->executeStatement('ALTER TABLE `frosh_mail_archive`
CHANGE `sender` `sender` json NOT NULL AFTER `id`;');
}
diff --git a/src/Resources/app/administration/src/module/frosh-mail-archive/index.js b/src/Resources/app/administration/src/module/frosh-mail-archive/index.js
index 78b26d7..454d3c0 100644
--- a/src/Resources/app/administration/src/module/frosh-mail-archive/index.js
+++ b/src/Resources/app/administration/src/module/frosh-mail-archive/index.js
@@ -6,7 +6,7 @@ Shopware.Module.register('frosh-mail-archive', {
name: 'frosh-mail-archive.title',
title: 'frosh-mail-archive.title',
description: '',
- color: '#62ff80',
+ color: '#243758',
icon: 'default-communication-envelope',
routes: {
diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml
index 2bfcc91..450be80 100644
--- a/src/Resources/config/services.xml
+++ b/src/Resources/config/services.xml
@@ -11,7 +11,7 @@
-
+
diff --git a/src/Services/MailSender.php b/src/Services/MailSender.php
index dd032a6..ff693f2 100644
--- a/src/Services/MailSender.php
+++ b/src/Services/MailSender.php
@@ -2,79 +2,58 @@
namespace Frosh\MailArchive\Services;
-use Shopware\Core\Content\MailTemplate\Service\MailSender as ShopwareMailSender;
+use Shopware\Core\Checkout\Customer\CustomerEntity;
+use Shopware\Core\Content\Mail\Service\AbstractMailSender;
+use Shopware\Core\Content\Mail\Service\AbstractMailService;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsAnyFilter;
use Shopware\Core\Framework\Uuid\Uuid;
use Symfony\Component\HttpFoundation\RequestStack;
+use Symfony\Component\Mailer\Envelope;
+use Symfony\Component\Mime\Address;
+use Symfony\Component\Mime\Email;
-class MailSender extends ShopwareMailSender
+class MailSender extends AbstractMailSender
{
- /**
- * @var MailSender
- */
- private $mailSender;
+ private AbstractMailSender $mailSender;
- /**
- * @var RequestStack
- */
- private $requestStack;
+ private RequestStack $requestStack;
- /**
- * @var EntityRepositoryInterface
- */
- private $mailArchiveRepository;
+ private EntityRepositoryInterface $mailArchiveRepository;
- /**
- * @var EntityRepositoryInterface
- */
- private $customerRepository;
+ private EntityRepositoryInterface $customerRepository;
public function __construct(
- ShopwareMailSender $mailSender,
+ AbstractMailSender $mailSender,
RequestStack $requestStack,
EntityRepositoryInterface $mailArchiveRepository,
EntityRepositoryInterface $customerRepository
- )
- {
+ ) {
$this->mailSender = $mailSender;
$this->requestStack = $requestStack;
$this->mailArchiveRepository = $mailArchiveRepository;
$this->customerRepository = $customerRepository;
}
- public function send(\Swift_Message $message): void
+ public function send(Email $email, ?Envelope $envelope = null): void
{
- $this->saveMail($message);
+ $this->saveMail($email);
- $this->mailSender->send($message);
+ $this->mailSender->send($email, $envelope);
}
- private function saveMail(\Swift_Message $message): void
+ private function saveMail(Email $message): void
{
- $plain = null;
- $html = null;
-
- foreach ($message->getChildren() as $child) {
- if ($child->getBodyContentType() === 'text/html') {
- $html = $child->getBody();
- continue;
- }
- if ($child->getBodyContentType() === 'text/plain') {
- $plain = $child->getBody();
- }
- }
-
$this->mailArchiveRepository->create([
[
'id' => Uuid::randomHex(),
- 'sender' => $message->getFrom(),
- 'receiver' => $message->getTo(),
+ 'sender' => [$message->getFrom()[0]->getAddress() => $message->getFrom()[0]->getName()],
+ 'receiver' => $this->convertAddress($message->getTo()),
'subject' => $message->getSubject(),
- 'plainText' => nl2br($plain),
- 'htmlText' => $html,
+ 'plainText' => nl2br($message->getTextBody()),
+ 'htmlText' => $message->getHtmlBody(),
'eml' => $message->toString(),
'salesChannelId' => $this->getCurrentSalesChannelId(),
'customerId' => $this->getCustomerIdByMail(array_keys($message->getTo()))
@@ -91,11 +70,31 @@ private function getCurrentSalesChannelId(): ?string
return $this->requestStack->getMasterRequest()->attributes->get('sw-sales-channel-id');
}
- private function getCustomerIdByMail(array $mails)
+ private function getCustomerIdByMail(array $mails): ?string
{
$criteria = new Criteria();
$criteria->addFilter(new EqualsAnyFilter('email', $mails));
return $this->customerRepository->searchIds($criteria, Context::createDefaultContext())->firstId();
}
+
+ public function getDecorated(): AbstractMailSender
+ {
+ return $this->mailSender;
+ }
+
+ /**
+ * @param Address[] $addresses
+ * @return array
+ */
+ private function convertAddress(array $addresses): array
+ {
+ $list = [];
+
+ foreach ($addresses as $address) {
+ $list[$address->getAddress()] = $address->getName();
+ }
+
+ return $list;
+ }
}