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 Eccube\Service\PurchaseFlow\PurchaseContext; |
20
|
|
|
use Eccube\Service\PurchaseFlow\PurchaseFlow; |
21
|
|
|
use Eccube\Service\PurchaseFlow\PurchaseFlowResult; |
22
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
23
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
24
|
|
|
|
25
|
|
|
class CartController extends AbstractController |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var CartService |
29
|
|
|
*/ |
30
|
|
|
protected $cartService; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var PurchaseFlow |
34
|
|
|
*/ |
35
|
|
|
protected $purchaseFlow; |
36
|
|
|
|
37
|
114 |
|
public function __construct( |
38
|
|
|
CartService $cartService, |
39
|
|
|
PurchaseFlow $cartPurchaseFlow |
40
|
|
|
) { |
41
|
114 |
|
$this->cartService = $cartService; |
42
|
114 |
|
$this->purchaseFlow = $cartPurchaseFlow; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @Route("/block/cart", name="block_cart") |
47
|
|
|
* @Template("Block/cart.twig") |
48
|
|
|
*/ |
|
|
|
|
49
|
114 |
|
public function index() |
50
|
|
|
{ |
51
|
114 |
|
$Carts = $this->cartService->getCarts(); |
52
|
|
|
|
53
|
|
|
// 二重に実行され, 注文画面でのエラーハンドリングができないので |
54
|
|
|
// ここではpurchaseFlowは実行しない |
55
|
|
|
|
56
|
114 |
|
$totalQuantity = array_reduce($Carts, function ($total, $Cart) { |
57
|
|
|
/* @var Cart $Cart */ |
58
|
71 |
|
$total += $Cart->getTotalQuantity(); |
59
|
|
|
|
60
|
71 |
|
return $total; |
61
|
114 |
|
}, 0); |
62
|
114 |
|
$totalPrice = array_reduce($Carts, function ($total, $Cart) { |
63
|
|
|
/* @var Cart $Cart */ |
64
|
71 |
|
$total += $Cart->getTotalPrice(); |
65
|
|
|
|
66
|
71 |
|
return $total; |
67
|
114 |
|
}, 0); |
68
|
|
|
|
69
|
|
|
return [ |
70
|
114 |
|
'totalQuantity' => $totalQuantity, |
71
|
114 |
|
'totalPrice' => $totalPrice, |
72
|
114 |
|
'Carts' => $Carts, |
73
|
|
|
]; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
protected function execPurchaseFlow($Carts) |
77
|
|
|
{ |
78
|
|
|
/** @var PurchaseFlowResult[] $flowResults */ |
79
|
|
|
$flowResults = array_map(function ($Cart) { |
|
|
|
|
80
|
|
|
$purchaseContext = new PurchaseContext($Cart, $this->getUser()); |
81
|
|
|
|
82
|
|
|
return $this->purchaseFlow->calculate($Cart, $purchaseContext); |
83
|
|
|
}, $Carts); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|