Skip to content

Commit f5b0786

Browse files
Show customer and order info in admin (#105)
* feat: improve the retrieval of a mail's customer * feat: display customer and order in admin * feat: change order of metadata information * feat: show information about the triggering flow * fix: setup dal references correctly * fix: disable DAL autoloading for customer association
1 parent fbfa0ea commit f5b0786

File tree

16 files changed

+396
-23
lines changed

16 files changed

+396
-23
lines changed

src/Content/MailArchive/MailArchiveDefinition.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
namespace Frosh\MailArchive\Content\MailArchive;
66

77
use Shopware\Core\Checkout\Customer\CustomerDefinition;
8+
use Shopware\Core\Checkout\Order\OrderDefinition;
9+
use Shopware\Core\Content\Flow\FlowDefinition;
10+
use Shopware\Core\Defaults;
811
use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition;
912
use Shopware\Core\Framework\DataAbstractionLayer\Field\FkField;
1013
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\AllowHtml;
@@ -17,6 +20,7 @@
1720
use Shopware\Core\Framework\DataAbstractionLayer\Field\LongTextField;
1821
use Shopware\Core\Framework\DataAbstractionLayer\Field\ManyToOneAssociationField;
1922
use Shopware\Core\Framework\DataAbstractionLayer\Field\OneToManyAssociationField;
23+
use Shopware\Core\Framework\DataAbstractionLayer\Field\ReferenceVersionField;
2024
use Shopware\Core\Framework\DataAbstractionLayer\Field\StringField;
2125
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection;
2226
use Shopware\Core\System\SalesChannel\SalesChannelDefinition;
@@ -37,6 +41,13 @@ public function getEntityClass(): string
3741
return MailArchiveEntity::class;
3842
}
3943

44+
public function getDefaults(): array
45+
{
46+
return [
47+
'orderVersionId' => Defaults::LIVE_VERSION,
48+
];
49+
}
50+
4051
protected function defineFields(): FieldCollection
4152
{
4253
return new FieldCollection([
@@ -55,7 +66,14 @@ protected function defineFields(): FieldCollection
5566
new ManyToOneAssociationField('salesChannel', 'salesChannelId', SalesChannelDefinition::class, 'id', true),
5667

5768
new FkField('customerId', 'customerId', CustomerDefinition::class),
58-
new ManyToOneAssociationField('customer', 'customerId', CustomerDefinition::class, 'id', true),
69+
new ManyToOneAssociationField('customer', 'customerId', CustomerDefinition::class, 'id', false),
70+
71+
new FkField('order_id', 'orderId', OrderDefinition::class),
72+
new ReferenceVersionField(OrderDefinition::class, 'order_version_id'),
73+
new ManyToOneAssociationField('order', 'order_id', OrderDefinition::class, 'id', false),
74+
75+
new FkField('flow_id', 'flowId', FlowDefinition::class),
76+
new ManyToOneAssociationField('flow', 'flow_id', FlowDefinition::class, 'id', false),
5977

6078
new FkField('source_mail_id', 'sourceMailId', self::class),
6179
new ManyToOneAssociationField('sourceMail', 'source_mail_id', self::class, 'id', false),

src/Content/MailArchive/MailArchiveEntity.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
namespace Frosh\MailArchive\Content\MailArchive;
66

77
use Shopware\Core\Checkout\Customer\CustomerEntity;
8+
use Shopware\Core\Checkout\Order\OrderEntity;
9+
use Shopware\Core\Content\Flow\FlowEntity;
810
use Shopware\Core\Framework\DataAbstractionLayer\Entity;
911
use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;
1012
use Shopware\Core\Framework\DataAbstractionLayer\EntityIdTrait;
@@ -38,6 +40,16 @@ class MailArchiveEntity extends Entity
3840

3941
protected ?CustomerEntity $customer;
4042

43+
protected ?string $orderId;
44+
45+
protected ?string $orderVersionId;
46+
47+
protected ?OrderEntity $order;
48+
49+
protected ?string $flowId;
50+
51+
protected ?FlowEntity $flow;
52+
4153
/**
4254
* @var EntityCollection<MailArchiveAttachmentEntity>|null
4355
*/
@@ -226,4 +238,55 @@ public function setSourceMails(EntityCollection $sourceMails): void
226238
{
227239
$this->sourceMails = $sourceMails;
228240
}
241+
242+
public function getOrderId(): ?string
243+
{
244+
return $this->orderId;
245+
}
246+
247+
public function setOrderId(?string $orderId): void
248+
{
249+
$this->orderId = $orderId;
250+
}
251+
252+
public function getOrder(): ?OrderEntity
253+
{
254+
return $this->order;
255+
}
256+
257+
public function setOrder(?OrderEntity $order): void
258+
{
259+
$this->order = $order;
260+
}
261+
262+
public function getFlowId(): ?string
263+
{
264+
return $this->flowId;
265+
}
266+
267+
public function setFlowId(?string $flowId): void
268+
{
269+
$this->flowId = $flowId;
270+
}
271+
272+
public function getFlow(): ?FlowEntity
273+
{
274+
return $this->flow;
275+
}
276+
277+
public function setFlow(?FlowEntity $flow): void
278+
{
279+
$this->flow = $flow;
280+
}
281+
282+
public function getOrderVersionId(): ?string
283+
{
284+
return $this->orderVersionId;
285+
}
286+
287+
public function setOrderVersionId(?string $orderVersionId): void
288+
{
289+
$this->orderVersionId = $orderVersionId;
290+
}
291+
229292
}

src/Extension/Checkout/Customer/CustomerExtension.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Frosh\MailArchive\Content\MailArchive\MailArchiveDefinition;
88
use Shopware\Core\Checkout\Customer\CustomerDefinition;
99
use Shopware\Core\Framework\DataAbstractionLayer\EntityExtension;
10+
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\SetNullOnDelete;
1011
use Shopware\Core\Framework\DataAbstractionLayer\Field\OneToManyAssociationField;
1112
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection;
1213
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
@@ -17,11 +18,11 @@ class CustomerExtension extends EntityExtension
1718
public function extendFields(FieldCollection $collection): void
1819
{
1920
$collection->add(
20-
new OneToManyAssociationField(
21+
(new OneToManyAssociationField(
2122
'froshMailArchive',
2223
MailArchiveDefinition::class,
2324
'customerId',
24-
),
25+
))->addFlags(new SetNullOnDelete(false)),
2526
);
2627
}
2728

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Frosh\MailArchive\Extension\Checkout\Order;
4+
5+
use Frosh\MailArchive\Content\MailArchive\MailArchiveDefinition;
6+
use Shopware\Core\Checkout\Order\OrderDefinition;
7+
use Shopware\Core\Framework\DataAbstractionLayer\EntityExtension;
8+
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\SetNullOnDelete;
9+
use Shopware\Core\Framework\DataAbstractionLayer\Field\OneToManyAssociationField;
10+
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection;
11+
12+
class OrderExtension extends EntityExtension
13+
{
14+
public function getDefinitionClass(): string
15+
{
16+
return OrderDefinition::class;
17+
}
18+
19+
public function extendFields(FieldCollection $collection): void
20+
{
21+
$collection->add(
22+
(new OneToManyAssociationField(
23+
'froshMailArchive',
24+
MailArchiveDefinition::class,
25+
'order_id',
26+
))->addFlags(new SetNullOnDelete(false)),
27+
);
28+
}
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Frosh\MailArchive\Extension\Content\Flow;
4+
5+
use Frosh\MailArchive\Content\MailArchive\MailArchiveDefinition;
6+
use Shopware\Core\Content\Flow\FlowDefinition;
7+
use Shopware\Core\Framework\DataAbstractionLayer\EntityExtension;
8+
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\SetNullOnDelete;
9+
use Shopware\Core\Framework\DataAbstractionLayer\Field\OneToManyAssociationField;
10+
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection;
11+
12+
class FlowExtension extends EntityExtension
13+
{
14+
public function getDefinitionClass(): string
15+
{
16+
return FlowDefinition::class;
17+
}
18+
19+
public function extendFields(FieldCollection $collection): void
20+
{
21+
$collection->add(
22+
(new OneToManyAssociationField(
23+
'froshMailArchive',
24+
MailArchiveDefinition::class,
25+
'flow_id',
26+
))->addFlags(new SetNullOnDelete(false)),
27+
);
28+
}
29+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Frosh\MailArchive\Migration;
6+
7+
use Doctrine\DBAL\Connection;
8+
use Shopware\Core\Framework\Migration\MigrationStep;
9+
10+
class Migration1739730285AddOrderId extends MigrationStep
11+
{
12+
public function getCreationTimestamp(): int
13+
{
14+
return 1739730285;
15+
}
16+
17+
public function update(Connection $connection): void
18+
{
19+
$connection->executeStatement('
20+
ALTER TABLE `frosh_mail_archive`
21+
ADD COLUMN `order_id` BINARY(16) NULL,
22+
ADD COLUMN `order_version_id` BINARY(16) NULL
23+
;
24+
');
25+
}
26+
27+
public function updateDestructive(Connection $connection): void {}
28+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Frosh\MailArchive\Migration;
6+
7+
use Doctrine\DBAL\Connection;
8+
use Shopware\Core\Framework\Migration\MigrationStep;
9+
10+
class Migration1739731953DropCustomerFK extends MigrationStep
11+
{
12+
public function getCreationTimestamp(): int
13+
{
14+
return 1739731953;
15+
}
16+
17+
public function update(Connection $connection): void
18+
{
19+
$connection->executeStatement('
20+
ALTER TABLE `frosh_mail_archive`
21+
DROP FOREIGN KEY `fk.frosh_mail_archive.customerId`;
22+
');
23+
}
24+
25+
public function updateDestructive(Connection $connection): void {}
26+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Frosh\MailArchive\Migration;
6+
7+
use Doctrine\DBAL\Connection;
8+
use Shopware\Core\Framework\Migration\MigrationStep;
9+
10+
class Migration1739741754AddFlowId extends MigrationStep
11+
{
12+
public function getCreationTimestamp(): int
13+
{
14+
return 1739741754;
15+
}
16+
17+
public function update(Connection $connection): void
18+
{
19+
$connection->executeStatement("
20+
ALTER TABLE `frosh_mail_archive`
21+
ADD COLUMN `flow_id` BINARY(16) NULL;");
22+
}
23+
24+
public function updateDestructive(Connection $connection): void {}
25+
}

src/Resources/app/administration/src/module/frosh-mail-archive/page/frosh-mail-archive-detail/frosh-mail-archive-detail.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,13 @@
1313
.frosh-mail-archive__detail-alert {
1414
max-width: 960px;
1515
}
16+
17+
.frosh-mail-archive__detail-metadata {
18+
dt {
19+
padding: 21px 4px 4px;
20+
}
21+
22+
dd {
23+
padding: 1px 4px;
24+
}
25+
}

src/Resources/app/administration/src/module/frosh-mail-archive/page/frosh-mail-archive-detail/frosh-mail-archive-detail.twig

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
</template>
55

66
<template #smart-bar-actions>
7-
<sw-button variant="ghost" v-if="archive && archive.customer" @click="openCustomer">
8-
{{ $t('frosh-mail-archive.detail.toolbar.customer') }}
9-
</sw-button>
10-
117
<sw-button-process :isLoading="downloadIsLoading" :process-success="downloadIsSuccessful" @click="downloadMail"
128
@update:process-success="downloadFinish">
139
{{ $t('frosh-mail-archive.detail.toolbar.downloadEml') }}
@@ -32,17 +28,62 @@
3228
:title="$t('frosh-mail-archive.detail.metadata.title')"
3329
position-identifier="frosh-mail-archive-metadata"
3430
>
35-
<sw-text-field :label="$tc('frosh-mail-archive.detail.metadata.sentDate')" :disabled="true"
36-
v-model="createdAtDate"></sw-text-field>
37-
<sw-text-field :label="$tc('frosh-mail-archive.detail.metadata.sender')" :disabled="true"
38-
v-model="senderText"></sw-text-field>
39-
<sw-text-field :label="$tc('frosh-mail-archive.detail.metadata.receiver')" :disabled="true"
40-
v-model="receiverText"></sw-text-field>
41-
<sw-text-field :label="$tc('frosh-mail-archive.detail.metadata.subject')" :disabled="true"
42-
v-model="archive.subject"></sw-text-field>
43-
<sw-text-field :label="$tc('frosh-mail-archive.detail.metadata.salesChannel')"
44-
v-if="archive.salesChannel" :disabled="true"
45-
v-model="archive.salesChannel.name"></sw-text-field>
31+
<sw-container
32+
columns="1fr 1fr"
33+
gap="0px 15px"
34+
class="frosh-mail-archive__detail-metadata"
35+
>
36+
<sw-description-list>
37+
<dt>{{ $tc('frosh-mail-archive.detail.metadata.receiver') }}</dt>
38+
<dd>{{ receiverText }}</dd>
39+
</sw-description-list>
40+
<sw-description-list>
41+
<dt>{{ $tc('frosh-mail-archive.detail.metadata.sender') }}</dt>
42+
<dd>{{ senderText }}</dd>
43+
</sw-description-list>
44+
<sw-description-list>
45+
<dt>{{ $tc('frosh-mail-archive.detail.metadata.subject') }}</dt>
46+
<dd>{{ archive.subject }}</dd>
47+
</sw-description-list>
48+
<sw-description-list>
49+
<dt>{{ $tc('frosh-mail-archive.detail.metadata.sentDate') }}</dt>
50+
<dd>{{ createdAtDate }}</dd>
51+
</sw-description-list>
52+
<sw-description-list>
53+
<dt>{{ $tc('frosh-mail-archive.detail.metadata.salesChannel') }}</dt>
54+
<dd v-if="archive.salesChannel">
55+
{{ archive.salesChannel.name }}
56+
</dd>
57+
<dd v-else>-</dd>
58+
</sw-description-list>
59+
<sw-description-list>
60+
<dt>{{ $tc('frosh-mail-archive.detail.metadata.customer') }}</dt>
61+
<dd v-if="archive.customer">
62+
<router-link :to="{ name: 'sw.customer.detail', params: {id: archive.customerId} }">
63+
{{ archive.customer.customerNumber }} - {{ archive.customer.firstName }} {{ archive.customer.lastName }}
64+
</router-link>
65+
</dd>
66+
<dd v-else>-</dd>
67+
</sw-description-list>
68+
<sw-description-list>
69+
<dt>{{ $tc('frosh-mail-archive.detail.metadata.order') }}</dt>
70+
<dd v-if="archive.order">
71+
<router-link :to="{ name: 'sw.order.detail', params: {id: archive.orderId}}">
72+
{{ archive.order.orderNumber }}
73+
</router-link>
74+
</dd>
75+
<dd v-else>-</dd>
76+
</sw-description-list>
77+
<sw-description-list>
78+
<dt>{{ $tc('frosh-mail-archive.detail.metadata.flow') }}</dt>
79+
<dd v-if="archive.flow">
80+
<router-link :to="{ name: 'sw.flow.detail', params: {id: archive.flowId}}">
81+
{{ archive.flow.name }}
82+
</router-link>
83+
</dd>
84+
<dd v-else>-</dd>
85+
</sw-description-list>
86+
</sw-container>
4687
</sw-card>
4788
<frosh-mail-resend-history :key="resendKey" :currentMailId="archive.id"
4889
:sourceMailId="archive.sourceMailId ?? archive.id"/>

0 commit comments

Comments
 (0)