Completed
Push — sf/fix-multi-browser-carts ( 96a945 )
by Kiyotaka
167:03 queued 103:04
created

CartController::execPurchaseFlow()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
ccs 0
cts 4
cp 0
crap 2
1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Eccube\Controller\Block;
15
16
use Eccube\Controller\AbstractController;
17
use Eccube\Entity\Cart;
18
use Eccube\Service\CartService;
19
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
20
use Symfony\Component\HttpFoundation\Request;
21
22
class CartController extends AbstractController
23
{
24
    /**
25
     * @var CartService
26
     */
27
    protected $cartService;
28
29
    public function __construct(
30
        CartService $cartService
31
    ) {
32
        $this->cartService = $cartService;
33
    }
34
35
    /**
36
     * @Route("/block/cart", name="block_cart")
37
     * @Route("/block/cart_sp", name="block_cart_sp")
38
     */
39
    public function index(Request $request)
40
    {
41
        $Carts = $this->cartService->getCarts();
42
43
        // 二重に実行され, 注文画面でのエラーハンドリングができないので
44
        // ここではpurchaseFlowは実行しない
45
46
        $totalQuantity = array_reduce($Carts, function ($total, $Cart) {
47
            /* @var Cart $Cart */
48
            $total += $Cart->getTotalQuantity();
49
50
            return $total;
51
        }, 0);
52
        $totalPrice = array_reduce($Carts, function ($total, $Cart) {
53
            /* @var Cart $Cart */
54
            $total += $Cart->getTotalPrice();
55
56
            return $total;
57
        }, 0);
58
59
        $route = $request->attributes->get('_route');
60
61
        if ($route == 'block_cart_sp') {
62
            return $this->render('Block/nav_sp.twig', [
63
                'totalQuantity' => $totalQuantity,
64
                'totalPrice' => $totalPrice,
65
                'Carts' => $Carts,
66
            ]);
67
        } else {
68
            return $this->render('Block/cart.twig', [
69
                'totalQuantity' => $totalQuantity,
70
                'totalPrice' => $totalPrice,
71
                'Carts' => $Carts,
72
            ]);
73
        }
74
    }
75
}
76