1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Sylius\ShopApiPlugin\Handler; |
6
|
|
|
|
7
|
|
|
use Sylius\Component\Core\Model\CustomerInterface; |
8
|
|
|
use Sylius\Component\Resource\Repository\RepositoryInterface; |
9
|
|
|
use Sylius\ShopApiPlugin\Command\UpdateCustomer; |
10
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class UpdateCustomerHandler |
14
|
|
|
*/ |
15
|
|
|
final class UpdateCustomerHandler |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var RepositoryInterface |
19
|
|
|
*/ |
20
|
|
|
private $customerRepository; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var TokenStorageInterface |
24
|
|
|
*/ |
25
|
|
|
private $tokenStorage; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* UpdateAddressBookAddressHandler constructor. |
29
|
|
|
* |
30
|
|
|
* @param RepositoryInterface $customerRepository |
31
|
|
|
* @param TokenStorageInterface $tokenStorage |
32
|
|
|
*/ |
33
|
|
|
public function __construct( |
34
|
|
|
RepositoryInterface $customerRepository, |
35
|
|
|
TokenStorageInterface $tokenStorage |
36
|
|
|
) { |
37
|
|
|
$this->customerRepository = $customerRepository; |
38
|
|
|
$this->tokenStorage = $tokenStorage; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function handle(UpdateCustomer $command): void |
42
|
|
|
{ |
43
|
|
|
/** @var CustomerInterface $customer */ |
44
|
|
|
$user = $this->tokenStorage->getToken()->getUser(); |
45
|
|
|
$customer = $user->getCustomer(); |
46
|
|
|
|
47
|
|
|
/** @var CustomerInterface $customer */ |
48
|
|
|
$customer->setFirstName($command->firstName()); |
49
|
|
|
$customer->setLastName($command->lastName()); |
50
|
|
|
|
51
|
|
|
$customer->setEmail($command->email()); |
52
|
|
|
$customer->setGender($command->gender()); |
53
|
|
|
$customer->setBirthday($command->birthday()); |
54
|
|
|
$customer->setPhoneNumber($command->phoneNumber()); |
55
|
|
|
$customer->setSubscribedToNewsletter($command->subscribedToNewsletter()); |
56
|
|
|
|
57
|
|
|
$this->customerRepository->add($customer); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|