Completed
Push — checkout-optimisation ( 4a6bfb...756f29 )
by Kamil
18:24
created

OrderController::thankYouAction()   B

Complexity

Conditions 4
Paths 2

Size

Total Lines 29
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 8.5806
c 0
b 0
f 0
cc 4
eloc 17
nc 2
nop 1
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
namespace Sylius\Bundle\CoreBundle\Controller;
13
14
use FOS\RestBundle\View\View;
15
use Sylius\Bundle\OrderBundle\Controller\OrderController as BaseOrderController;
16
use Symfony\Component\HttpFoundation\Request;
17
use Symfony\Component\HttpFoundation\Response;
18
use Webmozart\Assert\Assert;
19
20
class OrderController extends BaseOrderController
21
{
22
    /**
23
     * @param Request $request
24
     *
25
     * @return Response
26
     */
27
    public function thankYouAction(Request $request)
28
    {
29
        $configuration = $this->requestConfigurationFactory->create($this->metadata, $request);
30
31
        $orderId = $request->getSession()->get('sylius_order_id', null);
32
33
        if (null === $orderId) {
34
            $options = $configuration->getParameters()->get('after_failure');
35
36
            return $this->redirectHandler->redirectToRoute(
37
                $configuration,
38
                isset($options['route']) ? $options['route'] : 'sylius_shop_homepage',
39
                isset($options['parameters']) ? $options['parameters'] : []
40
            );
41
        }
42
43
        $request->getSession()->remove('sylius_order_id');
44
        $order = $this->repository->find($orderId);
45
        Assert::notNull($order);
46
47
        $view = View::create()
48
            ->setData([
49
                'order' => $order
50
            ])
51
            ->setTemplate($configuration->getParameters()->get('template'))
52
        ;
53
54
        return $this->viewHandler->handle($configuration, $view);
55
    }
56
}
57