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; |
15
|
|
|
|
16
|
|
|
use Eccube\Entity\ItemHolderInterface; |
17
|
|
|
use Eccube\Service\PurchaseFlow\PurchaseContext; |
18
|
|
|
use Eccube\Service\PurchaseFlow\PurchaseFlow; |
19
|
|
|
use Eccube\Service\PurchaseFlow\PurchaseFlowResult; |
20
|
|
|
|
21
|
|
|
class AbstractShoppingController extends AbstractController |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var PurchaseFlow |
25
|
|
|
*/ |
26
|
|
|
protected $purchaseFlow; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param PurchaseFlow $shoppingPurchaseFlow |
30
|
|
|
* @required |
31
|
|
|
*/ |
32
|
|
|
public function setPurchaseFlow(PurchaseFlow $shoppingPurchaseFlow) |
33
|
|
|
{ |
34
|
|
|
$this->purchaseFlow = $shoppingPurchaseFlow; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param ItemHolderInterface $itemHolder |
39
|
|
|
* @param bool $returnResponse レスポンスを返すかどうか. falseの場合はPurchaseFlowResultを返す. |
40
|
|
|
* |
41
|
|
|
* @return PurchaseFlowResult|\Symfony\Component\HttpFoundation\RedirectResponse |
42
|
|
|
*/ |
43
|
|
|
protected function executePurchaseFlow(ItemHolderInterface $itemHolder, $returnResponse = true) |
44
|
|
|
{ |
45
|
|
|
/** @var PurchaseFlowResult $flowResult */ |
46
|
|
|
$flowResult = $this->purchaseFlow->validate($itemHolder, new PurchaseContext(clone $itemHolder, $itemHolder->getCustomer())); |
47
|
|
|
foreach ($flowResult->getWarning() as $warning) { |
48
|
|
|
$this->addWarning($warning->getMessage()); |
49
|
|
|
} |
50
|
|
|
foreach ($flowResult->getErrors() as $error) { |
51
|
|
|
$this->addError($error->getMessage()); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
if (!$returnResponse) { |
55
|
|
|
return $flowResult; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
if ($flowResult->hasError()) { |
59
|
|
|
log_info('Errorが発生したため購入エラー画面へ遷移します.', [$flowResult->getErrors()]); |
60
|
|
|
|
61
|
|
|
return $this->redirectToRoute('shopping_error'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
if ($flowResult->hasWarning()) { |
65
|
|
|
log_info('Warningが発生したため注文手続き画面へ遷移します.', [$flowResult->getWarning()]); |
66
|
|
|
|
67
|
|
|
return $this->redirectToRoute('shopping'); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|