Skip to content

Commit

Permalink
Show customer and order info in admin (#105)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
schneider-felix authored Feb 17, 2025
1 parent fbfa0ea commit f5b0786
Show file tree
Hide file tree
Showing 16 changed files with 396 additions and 23 deletions.
20 changes: 19 additions & 1 deletion src/Content/MailArchive/MailArchiveDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
namespace Frosh\MailArchive\Content\MailArchive;

use Shopware\Core\Checkout\Customer\CustomerDefinition;
use Shopware\Core\Checkout\Order\OrderDefinition;
use Shopware\Core\Content\Flow\FlowDefinition;
use Shopware\Core\Defaults;
use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\Field\FkField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\AllowHtml;
Expand All @@ -17,6 +20,7 @@
use Shopware\Core\Framework\DataAbstractionLayer\Field\LongTextField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\ManyToOneAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\OneToManyAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\ReferenceVersionField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\StringField;
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection;
use Shopware\Core\System\SalesChannel\SalesChannelDefinition;
Expand All @@ -37,6 +41,13 @@ public function getEntityClass(): string
return MailArchiveEntity::class;
}

public function getDefaults(): array
{
return [
'orderVersionId' => Defaults::LIVE_VERSION,
];
}

protected function defineFields(): FieldCollection
{
return new FieldCollection([
Expand All @@ -55,7 +66,14 @@ protected function defineFields(): FieldCollection
new ManyToOneAssociationField('salesChannel', 'salesChannelId', SalesChannelDefinition::class, 'id', true),

new FkField('customerId', 'customerId', CustomerDefinition::class),
new ManyToOneAssociationField('customer', 'customerId', CustomerDefinition::class, 'id', true),
new ManyToOneAssociationField('customer', 'customerId', CustomerDefinition::class, 'id', false),

new FkField('order_id', 'orderId', OrderDefinition::class),
new ReferenceVersionField(OrderDefinition::class, 'order_version_id'),
new ManyToOneAssociationField('order', 'order_id', OrderDefinition::class, 'id', false),

new FkField('flow_id', 'flowId', FlowDefinition::class),
new ManyToOneAssociationField('flow', 'flow_id', FlowDefinition::class, 'id', false),

new FkField('source_mail_id', 'sourceMailId', self::class),
new ManyToOneAssociationField('sourceMail', 'source_mail_id', self::class, 'id', false),
Expand Down
63 changes: 63 additions & 0 deletions src/Content/MailArchive/MailArchiveEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace Frosh\MailArchive\Content\MailArchive;

use Shopware\Core\Checkout\Customer\CustomerEntity;
use Shopware\Core\Checkout\Order\OrderEntity;
use Shopware\Core\Content\Flow\FlowEntity;
use Shopware\Core\Framework\DataAbstractionLayer\Entity;
use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;
use Shopware\Core\Framework\DataAbstractionLayer\EntityIdTrait;
Expand Down Expand Up @@ -38,6 +40,16 @@ class MailArchiveEntity extends Entity

protected ?CustomerEntity $customer;

protected ?string $orderId;

protected ?string $orderVersionId;

protected ?OrderEntity $order;

protected ?string $flowId;

protected ?FlowEntity $flow;

/**
* @var EntityCollection<MailArchiveAttachmentEntity>|null
*/
Expand Down Expand Up @@ -226,4 +238,55 @@ public function setSourceMails(EntityCollection $sourceMails): void
{
$this->sourceMails = $sourceMails;
}

public function getOrderId(): ?string
{
return $this->orderId;
}

public function setOrderId(?string $orderId): void
{
$this->orderId = $orderId;
}

public function getOrder(): ?OrderEntity
{
return $this->order;
}

public function setOrder(?OrderEntity $order): void
{
$this->order = $order;
}

public function getFlowId(): ?string
{
return $this->flowId;
}

public function setFlowId(?string $flowId): void
{
$this->flowId = $flowId;
}

public function getFlow(): ?FlowEntity
{
return $this->flow;
}

public function setFlow(?FlowEntity $flow): void
{
$this->flow = $flow;
}

public function getOrderVersionId(): ?string
{
return $this->orderVersionId;
}

public function setOrderVersionId(?string $orderVersionId): void
{
$this->orderVersionId = $orderVersionId;
}

}
5 changes: 3 additions & 2 deletions src/Extension/Checkout/Customer/CustomerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Frosh\MailArchive\Content\MailArchive\MailArchiveDefinition;
use Shopware\Core\Checkout\Customer\CustomerDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\EntityExtension;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\SetNullOnDelete;
use Shopware\Core\Framework\DataAbstractionLayer\Field\OneToManyAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection;
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
Expand All @@ -17,11 +18,11 @@ class CustomerExtension extends EntityExtension
public function extendFields(FieldCollection $collection): void
{
$collection->add(
new OneToManyAssociationField(
(new OneToManyAssociationField(
'froshMailArchive',
MailArchiveDefinition::class,
'customerId',
),
))->addFlags(new SetNullOnDelete(false)),
);
}

Expand Down
29 changes: 29 additions & 0 deletions src/Extension/Checkout/Order/OrderExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Frosh\MailArchive\Extension\Checkout\Order;

use Frosh\MailArchive\Content\MailArchive\MailArchiveDefinition;
use Shopware\Core\Checkout\Order\OrderDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\EntityExtension;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\SetNullOnDelete;
use Shopware\Core\Framework\DataAbstractionLayer\Field\OneToManyAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection;

class OrderExtension extends EntityExtension
{
public function getDefinitionClass(): string
{
return OrderDefinition::class;
}

public function extendFields(FieldCollection $collection): void
{
$collection->add(
(new OneToManyAssociationField(
'froshMailArchive',
MailArchiveDefinition::class,
'order_id',
))->addFlags(new SetNullOnDelete(false)),
);
}
}
29 changes: 29 additions & 0 deletions src/Extension/Content/Flow/FlowExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Frosh\MailArchive\Extension\Content\Flow;

use Frosh\MailArchive\Content\MailArchive\MailArchiveDefinition;
use Shopware\Core\Content\Flow\FlowDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\EntityExtension;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\SetNullOnDelete;
use Shopware\Core\Framework\DataAbstractionLayer\Field\OneToManyAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection;

class FlowExtension extends EntityExtension
{
public function getDefinitionClass(): string
{
return FlowDefinition::class;
}

public function extendFields(FieldCollection $collection): void
{
$collection->add(
(new OneToManyAssociationField(
'froshMailArchive',
MailArchiveDefinition::class,
'flow_id',
))->addFlags(new SetNullOnDelete(false)),
);
}
}
28 changes: 28 additions & 0 deletions src/Migration/Migration1739730285AddOrderId.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Frosh\MailArchive\Migration;

use Doctrine\DBAL\Connection;
use Shopware\Core\Framework\Migration\MigrationStep;

class Migration1739730285AddOrderId extends MigrationStep
{
public function getCreationTimestamp(): int
{
return 1739730285;
}

public function update(Connection $connection): void
{
$connection->executeStatement('
ALTER TABLE `frosh_mail_archive`
ADD COLUMN `order_id` BINARY(16) NULL,
ADD COLUMN `order_version_id` BINARY(16) NULL
;
');
}

public function updateDestructive(Connection $connection): void {}
}
26 changes: 26 additions & 0 deletions src/Migration/Migration1739731953DropCustomerFK.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Frosh\MailArchive\Migration;

use Doctrine\DBAL\Connection;
use Shopware\Core\Framework\Migration\MigrationStep;

class Migration1739731953DropCustomerFK extends MigrationStep
{
public function getCreationTimestamp(): int
{
return 1739731953;
}

public function update(Connection $connection): void
{
$connection->executeStatement('
ALTER TABLE `frosh_mail_archive`
DROP FOREIGN KEY `fk.frosh_mail_archive.customerId`;
');
}

public function updateDestructive(Connection $connection): void {}
}
25 changes: 25 additions & 0 deletions src/Migration/Migration1739741754AddFlowId.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Frosh\MailArchive\Migration;

use Doctrine\DBAL\Connection;
use Shopware\Core\Framework\Migration\MigrationStep;

class Migration1739741754AddFlowId extends MigrationStep
{
public function getCreationTimestamp(): int
{
return 1739741754;
}

public function update(Connection $connection): void
{
$connection->executeStatement("
ALTER TABLE `frosh_mail_archive`
ADD COLUMN `flow_id` BINARY(16) NULL;");
}

public function updateDestructive(Connection $connection): void {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,13 @@
.frosh-mail-archive__detail-alert {
max-width: 960px;
}

.frosh-mail-archive__detail-metadata {
dt {
padding: 21px 4px 4px;
}

dd {
padding: 1px 4px;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
</template>

<template #smart-bar-actions>
<sw-button variant="ghost" v-if="archive && archive.customer" @click="openCustomer">
{{ $t('frosh-mail-archive.detail.toolbar.customer') }}
</sw-button>

<sw-button-process :isLoading="downloadIsLoading" :process-success="downloadIsSuccessful" @click="downloadMail"
@update:process-success="downloadFinish">
{{ $t('frosh-mail-archive.detail.toolbar.downloadEml') }}
Expand All @@ -32,17 +28,62 @@
:title="$t('frosh-mail-archive.detail.metadata.title')"
position-identifier="frosh-mail-archive-metadata"
>
<sw-text-field :label="$tc('frosh-mail-archive.detail.metadata.sentDate')" :disabled="true"
v-model="createdAtDate"></sw-text-field>
<sw-text-field :label="$tc('frosh-mail-archive.detail.metadata.sender')" :disabled="true"
v-model="senderText"></sw-text-field>
<sw-text-field :label="$tc('frosh-mail-archive.detail.metadata.receiver')" :disabled="true"
v-model="receiverText"></sw-text-field>
<sw-text-field :label="$tc('frosh-mail-archive.detail.metadata.subject')" :disabled="true"
v-model="archive.subject"></sw-text-field>
<sw-text-field :label="$tc('frosh-mail-archive.detail.metadata.salesChannel')"
v-if="archive.salesChannel" :disabled="true"
v-model="archive.salesChannel.name"></sw-text-field>
<sw-container
columns="1fr 1fr"
gap="0px 15px"
class="frosh-mail-archive__detail-metadata"
>
<sw-description-list>
<dt>{{ $tc('frosh-mail-archive.detail.metadata.receiver') }}</dt>
<dd>{{ receiverText }}</dd>
</sw-description-list>
<sw-description-list>
<dt>{{ $tc('frosh-mail-archive.detail.metadata.sender') }}</dt>
<dd>{{ senderText }}</dd>
</sw-description-list>
<sw-description-list>
<dt>{{ $tc('frosh-mail-archive.detail.metadata.subject') }}</dt>
<dd>{{ archive.subject }}</dd>
</sw-description-list>
<sw-description-list>
<dt>{{ $tc('frosh-mail-archive.detail.metadata.sentDate') }}</dt>
<dd>{{ createdAtDate }}</dd>
</sw-description-list>
<sw-description-list>
<dt>{{ $tc('frosh-mail-archive.detail.metadata.salesChannel') }}</dt>
<dd v-if="archive.salesChannel">
{{ archive.salesChannel.name }}
</dd>
<dd v-else>-</dd>
</sw-description-list>
<sw-description-list>
<dt>{{ $tc('frosh-mail-archive.detail.metadata.customer') }}</dt>
<dd v-if="archive.customer">
<router-link :to="{ name: 'sw.customer.detail', params: {id: archive.customerId} }">
{{ archive.customer.customerNumber }} - {{ archive.customer.firstName }} {{ archive.customer.lastName }}
</router-link>
</dd>
<dd v-else>-</dd>
</sw-description-list>
<sw-description-list>
<dt>{{ $tc('frosh-mail-archive.detail.metadata.order') }}</dt>
<dd v-if="archive.order">
<router-link :to="{ name: 'sw.order.detail', params: {id: archive.orderId}}">
{{ archive.order.orderNumber }}
</router-link>
</dd>
<dd v-else>-</dd>
</sw-description-list>
<sw-description-list>
<dt>{{ $tc('frosh-mail-archive.detail.metadata.flow') }}</dt>
<dd v-if="archive.flow">
<router-link :to="{ name: 'sw.flow.detail', params: {id: archive.flowId}}">
{{ archive.flow.name }}
</router-link>
</dd>
<dd v-else>-</dd>
</sw-description-list>
</sw-container>
</sw-card>
<frosh-mail-resend-history :key="resendKey" :currentMailId="archive.id"
:sourceMailId="archive.sourceMailId ?? archive.id"/>
Expand Down
Loading

0 comments on commit f5b0786

Please sign in to comment.