1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Shopware\Core\Checkout\Customer\SalesChannel; |
4
|
|
|
|
5
|
|
|
use OpenApi\Annotations as OA; |
6
|
|
|
use Shopware\Core\Checkout\Cart\Exception\CustomerNotLoggedInException; |
7
|
|
|
use Shopware\Core\Checkout\Customer\Event\CustomerDeletedEvent; |
8
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface; |
9
|
|
|
use Shopware\Core\Framework\Feature; |
10
|
|
|
use Shopware\Core\Framework\Plugin\Exception\DecorationPatternException; |
11
|
|
|
use Shopware\Core\Framework\Routing\Annotation\RouteScope; |
12
|
|
|
use Shopware\Core\System\SalesChannel\NoContentResponse; |
13
|
|
|
use Shopware\Core\System\SalesChannel\SalesChannelContext; |
14
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
15
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @RouteScope(scopes={"store-api"}) |
19
|
|
|
*/ |
20
|
|
|
class DeleteCustomerRoute extends AbstractDeleteCustomerRoute |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var EntityRepositoryInterface |
24
|
|
|
*/ |
25
|
|
|
private $customerRepository; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var EventDispatcherInterface |
29
|
|
|
*/ |
30
|
|
|
private $eventDispatcher; |
31
|
|
|
|
32
|
|
|
public function __construct( |
33
|
|
|
EntityRepositoryInterface $customerRepository, |
34
|
|
|
EventDispatcherInterface $eventDispatcher |
35
|
|
|
) { |
36
|
|
|
$this->customerRepository = $customerRepository; |
37
|
|
|
$this->eventDispatcher = $eventDispatcher; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function getDecorated(): AbstractDeleteCustomerRoute |
41
|
|
|
{ |
42
|
|
|
throw new DecorationPatternException(self::class); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @OA\Delete( |
47
|
|
|
* path="/account/customer", |
48
|
|
|
* description="Delete customer profile", |
49
|
|
|
* operationId="deleteCustomer", |
50
|
|
|
* tags={"Store API", "Account"}, |
51
|
|
|
* @OA\Parameter(name="Api-Basic-Parameters"), |
52
|
|
|
* @OA\Response( |
53
|
|
|
* response="200", |
54
|
|
|
* description="Loggedin customer", |
55
|
|
|
* @OA\JsonContent(ref="#/components/schemas/customer_flat") |
56
|
|
|
* ) |
57
|
|
|
* ) |
58
|
|
|
* @Route("/store-api/v{version}/account/customer", name="store-api.account.customer.delete", methods={"DELETE"}) |
59
|
|
|
*/ |
60
|
|
|
public function delete(SalesChannelContext $context): NoContentResponse |
61
|
|
|
{ |
62
|
|
|
if (!Feature::isActive('FEATURE_NEXT_10077')) { |
63
|
|
|
return new NoContentResponse(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$customer = $context->getCustomer(); |
67
|
|
|
if ($customer === null) { |
68
|
|
|
throw new CustomerNotLoggedInException(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$this->customerRepository->delete([['id' => $customer->getId()]], $context->getContext()); |
72
|
|
|
|
73
|
|
|
$event = new CustomerDeletedEvent($context, $customer); |
74
|
|
|
$this->eventDispatcher->dispatch($event); |
75
|
|
|
|
76
|
|
|
return new NoContentResponse(); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|