|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sylius package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Paweł Jędrzejewski |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace Sylius\Bundle\CoreBundle\Controller; |
|
15
|
|
|
|
|
16
|
|
|
use FOS\RestBundle\View\View; |
|
17
|
|
|
use Sylius\Bundle\OrderBundle\Controller\OrderController as BaseOrderController; |
|
18
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
19
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
20
|
|
|
use Webmozart\Assert\Assert; |
|
21
|
|
|
|
|
22
|
|
|
class OrderController extends BaseOrderController |
|
23
|
|
|
{ |
|
24
|
|
|
public function summaryAction(Request $request): Response |
|
25
|
|
|
{ |
|
26
|
|
|
$configuration = $this->requestConfigurationFactory->create($this->metadata, $request); |
|
27
|
|
|
|
|
28
|
|
|
$cart = $this->getCurrentCart(); |
|
29
|
|
|
if (null !== $cart->getId()) { |
|
30
|
|
|
$cart = $this->getOrderRepository()->findCartForSummary($cart->getId()); |
|
|
|
|
|
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
if (!$configuration->isHtmlRequest()) { |
|
34
|
|
|
return $this->viewHandler->handle($configuration, View::create($cart)); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
$form = $this->resourceFormFactory->create($configuration, $cart); |
|
38
|
|
|
|
|
39
|
|
|
$view = View::create() |
|
40
|
|
|
->setTemplate($configuration->getTemplate('summary.html')) |
|
41
|
|
|
->setData([ |
|
42
|
|
|
'cart' => $cart, |
|
43
|
|
|
'form' => $form->createView(), |
|
44
|
|
|
]) |
|
45
|
|
|
; |
|
46
|
|
|
|
|
47
|
|
|
return $this->viewHandler->handle($configuration, $view); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function thankYouAction(Request $request): Response |
|
51
|
|
|
{ |
|
52
|
|
|
$configuration = $this->requestConfigurationFactory->create($this->metadata, $request); |
|
53
|
|
|
|
|
54
|
|
|
$orderId = $request->getSession()->get('sylius_order_id', null); |
|
55
|
|
|
|
|
56
|
|
|
if (null === $orderId) { |
|
57
|
|
|
$options = $configuration->getParameters()->get('after_failure'); |
|
58
|
|
|
|
|
59
|
|
|
return $this->redirectHandler->redirectToRoute( |
|
60
|
|
|
$configuration, |
|
61
|
|
|
$options['route'] ?? 'sylius_shop_homepage', |
|
62
|
|
|
$options['parameters'] ?? [] |
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
$request->getSession()->remove('sylius_order_id'); |
|
67
|
|
|
$order = $this->repository->find($orderId); |
|
68
|
|
|
Assert::notNull($order); |
|
69
|
|
|
|
|
70
|
|
|
$view = View::create() |
|
71
|
|
|
->setData([ |
|
72
|
|
|
'order' => $order, |
|
73
|
|
|
]) |
|
74
|
|
|
->setTemplate($configuration->getParameters()->get('template')) |
|
75
|
|
|
; |
|
76
|
|
|
|
|
77
|
|
|
return $this->viewHandler->handle($configuration, $view); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: