-
Notifications
You must be signed in to change notification settings - Fork 976
/
ListAddressRoute.php
50 lines (43 loc) · 2.13 KB
/
ListAddressRoute.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php declare(strict_types=1);
namespace Shopware\Core\Checkout\Customer\SalesChannel;
use Shopware\Core\Checkout\Customer\Aggregate\CustomerAddress\CustomerAddressCollection;
use Shopware\Core\Checkout\Customer\CustomerEntity;
use Shopware\Core\Checkout\Customer\Event\AddressListingCriteriaEvent;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Plugin\Exception\DecorationPatternException;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
#[Route(defaults: ['_routeScope' => ['store-api']])]
#[Package('checkout')]
class ListAddressRoute extends AbstractListAddressRoute
{
/**
* @internal
*
* @param EntityRepository<CustomerAddressCollection> $addressRepository
*/
public function __construct(
private readonly EntityRepository $addressRepository,
private readonly EventDispatcherInterface $eventDispatcher
) {
}
public function getDecorated(): AbstractListAddressRoute
{
throw new DecorationPatternException(self::class);
}
#[Route(path: '/store-api/account/list-address', name: 'store-api.account.address.list.get', methods: ['GET', 'POST'], defaults: ['_loginRequired' => true, '_loginRequiredAllowGuest' => true, '_entity' => 'customer_address'])]
public function load(Criteria $criteria, SalesChannelContext $context, CustomerEntity $customer): ListAddressRouteResponse
{
$criteria
->addAssociation('salutation')
->addAssociation('country')
->addAssociation('countryState')
->addFilter(new EqualsFilter('customer_address.customerId', $customer->getId()));
$this->eventDispatcher->dispatch(new AddressListingCriteriaEvent($criteria, $context));
return new ListAddressRouteResponse($this->addressRepository->search($criteria, $context->getContext()));
}
}