Skip to content

Commit a68362a

Browse files
feat: display customer and order in admin
1 parent a0a0d09 commit a68362a

File tree

15 files changed

+225
-40
lines changed

15 files changed

+225
-40
lines changed

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,8 @@
4747
"allow-plugins": {
4848
"symfony/runtime": true
4949
}
50+
},
51+
"scripts": {
52+
"cs-fix": "docker run --rm -v $(pwd):$(pwd) -w $(pwd) oskarstark/php-cs-fixer-ga --rules=@PER-CS2.0,no_unused_imports ."
5053
}
5154
}

src/Content/MailArchive/MailArchiveDefinition.php

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

77
use Shopware\Core\Checkout\Customer\CustomerDefinition;
8+
use Shopware\Core\Checkout\Order\OrderDefinition;
89
use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition;
910
use Shopware\Core\Framework\DataAbstractionLayer\Field\FkField;
1011
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\AllowHtml;
@@ -57,6 +58,9 @@ protected function defineFields(): FieldCollection
5758
new FkField('customerId', 'customerId', CustomerDefinition::class),
5859
new ManyToOneAssociationField('customer', 'customerId', CustomerDefinition::class, 'id', true),
5960

61+
new FkField('order_id', 'orderId', OrderDefinition::class),
62+
new ManyToOneAssociationField('order', 'order_id', OrderDefinition::class, 'id', false),
63+
6064
new FkField('source_mail_id', 'sourceMailId', self::class),
6165
new ManyToOneAssociationField('sourceMail', 'source_mail_id', self::class, 'id', false),
6266
new OneToManyAssociationField('sourceMails', self::class, 'sourceMailId'),

src/Content/MailArchive/MailArchiveEntity.php

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

77
use Shopware\Core\Checkout\Customer\CustomerEntity;
8+
use Shopware\Core\Checkout\Order\OrderEntity;
89
use Shopware\Core\Framework\DataAbstractionLayer\Entity;
910
use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;
1011
use Shopware\Core\Framework\DataAbstractionLayer\EntityIdTrait;
@@ -38,6 +39,9 @@ class MailArchiveEntity extends Entity
3839

3940
protected ?CustomerEntity $customer;
4041

42+
protected ?string $orderId;
43+
protected ?OrderEntity $order;
44+
4145
/**
4246
* @var EntityCollection<MailArchiveAttachmentEntity>|null
4347
*/
@@ -226,4 +230,25 @@ public function setSourceMails(EntityCollection $sourceMails): void
226230
{
227231
$this->sourceMails = $sourceMails;
228232
}
233+
234+
public function getOrderId(): ?string
235+
{
236+
return $this->orderId;
237+
}
238+
239+
public function setOrderId(?string $orderId): void
240+
{
241+
$this->orderId = $orderId;
242+
}
243+
244+
public function getOrder(): ?OrderEntity
245+
{
246+
return $this->order;
247+
}
248+
249+
public function setOrder(?OrderEntity $order): void
250+
{
251+
$this->order = $order;
252+
}
253+
229254
}

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()),
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()),
27+
);
28+
}
29+
}
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 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+
');
23+
}
24+
25+
public function updateDestructive(Connection $connection): void {}
26+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
DROP INDEX `fk.frosh_mail_archive.customerId`;
23+
');
24+
}
25+
26+
public function updateDestructive(Connection $connection): void {}
27+
}

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: 47 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,53 @@
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.sentDate') }}</dt>
38+
<dd>{{ createdAtDate }}</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.receiver') }}</dt>
46+
<dd>{{ receiverText }}</dd>
47+
</sw-description-list>
48+
<sw-description-list>
49+
<dt>{{ $tc('frosh-mail-archive.detail.metadata.subject') }}</dt>
50+
<dd>{{ archive.subject }}</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-container>
4678
</sw-card>
4779
<frosh-mail-resend-history :key="resendKey" :currentMailId="archive.id"
4880
:sourceMailId="archive.sourceMailId ?? archive.id"/>

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,12 @@ Component.register('frosh-mail-archive-detail', {
106106
loadMail() {
107107
const criteria = new Criteria();
108108
criteria.addAssociation('attachments');
109+
criteria.addAssociation('customer');
110+
criteria.addAssociation('order');
109111

110112
this.repository.get(this.archiveId, Shopware.Context.api, criteria).then(archive => {
113+
114+
console.log(archive)
111115
this.archive = archive;
112116
})
113117
},

0 commit comments

Comments
 (0)