|
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
|
114 |
|
* @Route("/block/cart_sp", name="block_cart_sp") |
|
38
|
|
|
*/ |
|
39
|
|
|
public function index(Request $request) |
|
40
|
|
|
{ |
|
41
|
114 |
|
$Carts = $this->cartService->getCarts(); |
|
42
|
114 |
|
|
|
43
|
|
|
// 二重に実行され, 注文画面でのエラーハンドリングができないので |
|
44
|
|
|
// ここではpurchaseFlowは実行しない |
|
45
|
|
|
|
|
46
|
|
|
$totalQuantity = array_reduce($Carts, function ($total, $Cart) { |
|
47
|
|
|
/* @var Cart $Cart */ |
|
48
|
|
|
$total += $Cart->getTotalQuantity(); |
|
49
|
114 |
|
|
|
50
|
|
|
return $total; |
|
51
|
114 |
|
}, 0); |
|
52
|
|
|
$totalPrice = array_reduce($Carts, function ($total, $Cart) { |
|
53
|
|
|
/* @var Cart $Cart */ |
|
54
|
|
|
$total += $Cart->getTotalPrice(); |
|
55
|
|
|
|
|
56
|
114 |
|
return $total; |
|
57
|
|
|
}, 0); |
|
58
|
71 |
|
|
|
59
|
|
|
$route = $request->attributes->get('_route'); |
|
60
|
71 |
|
|
|
61
|
114 |
|
if ($route == 'block_cart_sp') { |
|
62
|
114 |
|
return $this->render('Block/nav_sp.twig', [ |
|
63
|
|
|
'totalQuantity' => $totalQuantity, |
|
64
|
71 |
|
'totalPrice' => $totalPrice, |
|
65
|
|
|
'Carts' => $Carts, |
|
66
|
71 |
|
]); |
|
67
|
114 |
|
} else { |
|
68
|
|
|
return $this->render('Block/cart.twig', [ |
|
69
|
114 |
|
'totalQuantity' => $totalQuantity, |
|
70
|
|
|
'totalPrice' => $totalPrice, |
|
71
|
114 |
|
'Carts' => $Carts, |
|
72
|
113 |
|
]); |
|
73
|
113 |
|
} |
|
74
|
113 |
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|