Passed
Push — master ( c42b99...3c3598 )
by Christian
12:10 queued 10s
created

CustomerDeletedEvent::getMailStruct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 9
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Core\Checkout\Customer\Event;
4
5
use Shopware\Core\Checkout\Customer\CustomerDefinition;
6
use Shopware\Core\Checkout\Customer\CustomerEntity;
7
use Shopware\Core\Framework\Context;
8
use Shopware\Core\Framework\Event\EventData\EntityType;
9
use Shopware\Core\Framework\Event\EventData\EventDataCollection;
10
use Shopware\Core\Framework\Event\EventData\MailRecipientStruct;
11
use Shopware\Core\Framework\Event\MailActionInterface;
12
use Shopware\Core\System\SalesChannel\SalesChannelContext;
13
use Symfony\Contracts\EventDispatcher\Event;
14
15
class CustomerDeletedEvent extends Event implements MailActionInterface
16
{
17
    public const EVENT_NAME = 'checkout.customer.deleted';
18
19
    /**
20
     * @var CustomerEntity
21
     */
22
    private $customer;
23
24
    /**
25
     * @var SalesChannelContext
26
     */
27
    private $salesChannelContext;
28
29
    /**
30
     * @var MailRecipientStruct|null
31
     */
32
    private $mailRecipientStruct;
33
34
    public function __construct(SalesChannelContext $salesChannelContext, CustomerEntity $customer)
35
    {
36
        $this->customer = $customer;
37
        $this->salesChannelContext = $salesChannelContext;
38
    }
39
40
    public function getName(): string
41
    {
42
        return self::EVENT_NAME;
43
    }
44
45
    public function getCustomer(): CustomerEntity
46
    {
47
        return $this->customer;
48
    }
49
50
    public function getSalesChannelContext(): SalesChannelContext
51
    {
52
        return $this->salesChannelContext;
53
    }
54
55
    public function getContext(): Context
56
    {
57
        return $this->salesChannelContext->getContext();
58
    }
59
60
    public function getSalesChannelId(): ?string
61
    {
62
        return $this->salesChannelContext->getSalesChannel()->getId();
63
    }
64
65
    public function getMailStruct(): MailRecipientStruct
66
    {
67
        if (!$this->mailRecipientStruct instanceof MailRecipientStruct) {
68
            $this->mailRecipientStruct = new MailRecipientStruct([
69
                $this->customer->getEmail() => $this->customer->getFirstName() . ' ' . $this->customer->getLastName(),
70
            ]);
71
        }
72
73
        return $this->mailRecipientStruct;
74
    }
75
76
    public static function getAvailableData(): EventDataCollection
77
    {
78
        return (new EventDataCollection())
79
            ->add('customer', new EntityType(CustomerDefinition::class));
80
    }
81
}
82