|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Shopware\Storefront\Page\Account\Order; |
|
4
|
|
|
|
|
5
|
|
|
use Shopware\Core\Checkout\Cart\Exception\CustomerNotLoggedInException; |
|
6
|
|
|
use Shopware\Core\Checkout\Order\OrderEntity; |
|
7
|
|
|
use Shopware\Core\Checkout\Order\SalesChannel\AbstractOrderRoute; |
|
8
|
|
|
use Shopware\Core\Checkout\Order\SalesChannel\OrderRouteResponseStruct; |
|
9
|
|
|
use Shopware\Core\Content\Category\Exception\CategoryNotFoundException; |
|
10
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Exception\InconsistentCriteriaIdsException; |
|
11
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; |
|
12
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Search\Sorting\FieldSorting; |
|
13
|
|
|
use Shopware\Core\Framework\Routing\Exception\MissingRequestParameterException; |
|
14
|
|
|
use Shopware\Core\System\SalesChannel\SalesChannelContext; |
|
15
|
|
|
use Shopware\Storefront\Event\RouteRequest\OrderRouteRequestEvent; |
|
16
|
|
|
use Shopware\Storefront\Page\GenericPageLoaderInterface; |
|
17
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
18
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
19
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
20
|
|
|
|
|
21
|
|
|
class AccountOrderDetailPageLoader |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @var GenericPageLoaderInterface |
|
25
|
|
|
*/ |
|
26
|
|
|
private $genericLoader; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var EventDispatcherInterface |
|
30
|
|
|
*/ |
|
31
|
|
|
private $eventDispatcher; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var AbstractOrderRoute |
|
35
|
|
|
*/ |
|
36
|
|
|
private $orderRoute; |
|
37
|
|
|
|
|
38
|
|
|
public function __construct( |
|
39
|
|
|
GenericPageLoaderInterface $genericLoader, |
|
40
|
|
|
EventDispatcherInterface $eventDispatcher, |
|
41
|
|
|
AbstractOrderRoute $orderRoute |
|
42
|
|
|
) { |
|
43
|
|
|
$this->genericLoader = $genericLoader; |
|
44
|
|
|
$this->eventDispatcher = $eventDispatcher; |
|
45
|
|
|
$this->orderRoute = $orderRoute; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @throws CategoryNotFoundException |
|
50
|
|
|
* @throws CustomerNotLoggedInException |
|
51
|
|
|
* @throws InconsistentCriteriaIdsException |
|
52
|
|
|
* @throws MissingRequestParameterException |
|
53
|
|
|
*/ |
|
54
|
|
|
public function load(Request $request, SalesChannelContext $salesChannelContext): AccountOrderDetailPage |
|
55
|
|
|
{ |
|
56
|
|
|
if (!$salesChannelContext->getCustomer()) { |
|
57
|
|
|
throw new CustomerNotLoggedInException(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
$orderId = (string) $request->get('id'); |
|
61
|
|
|
|
|
62
|
|
|
if ($orderId === '') { |
|
63
|
|
|
throw new MissingRequestParameterException('id'); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
$criteria = new Criteria([$orderId]); |
|
67
|
|
|
$criteria |
|
68
|
|
|
->addAssociation('lineItems') |
|
69
|
|
|
->addAssociation('orderCustomer') |
|
70
|
|
|
->addAssociation('transactions.paymentMethod') |
|
71
|
|
|
->addAssociation('deliveries.shippingMethod') |
|
72
|
|
|
->addAssociation('lineItems.cover'); |
|
73
|
|
|
|
|
74
|
|
|
$criteria->getAssociation('transactions') |
|
75
|
|
|
->addSorting(new FieldSorting('createdAt')); |
|
76
|
|
|
|
|
77
|
|
|
$apiRequest = new Request(); |
|
78
|
|
|
|
|
79
|
|
|
$event = new OrderRouteRequestEvent($request, $apiRequest, $salesChannelContext, $criteria); |
|
80
|
|
|
$this->eventDispatcher->dispatch($event); |
|
81
|
|
|
|
|
82
|
|
|
/** @var OrderRouteResponseStruct $result */ |
|
83
|
|
|
$result = $this->orderRoute |
|
|
|
|
|
|
84
|
|
|
->load($event->getStoreApiRequest(), $salesChannelContext, $criteria) |
|
|
|
|
|
|
85
|
|
|
->getObject(); |
|
86
|
|
|
|
|
87
|
|
|
$order = $result->getOrders()->first(); |
|
88
|
|
|
|
|
89
|
|
|
if (!$order instanceof OrderEntity) { |
|
90
|
|
|
throw new NotFoundHttpException(); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
$page = AccountOrderDetailPage::createFrom($this->genericLoader->load($request, $salesChannelContext)); |
|
94
|
|
|
$page->setLineItems($order->getNestedLineItems()); |
|
95
|
|
|
$page->setOrder($order); |
|
96
|
|
|
|
|
97
|
|
|
$this->eventDispatcher->dispatch( |
|
98
|
|
|
new AccountOrderDetailPageLoadedEvent($page, $salesChannelContext, $request) |
|
99
|
|
|
); |
|
100
|
|
|
|
|
101
|
|
|
return $page; |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.