1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of EC-CUBE |
4
|
|
|
* |
5
|
|
|
* Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved. |
6
|
|
|
* |
7
|
|
|
* http://www.lockon.co.jp/ |
8
|
|
|
* |
9
|
|
|
* This program is free software; you can redistribute it and/or |
10
|
|
|
* modify it under the terms of the GNU General Public License |
11
|
|
|
* as published by the Free Software Foundation; either version 2 |
12
|
|
|
* of the License, or (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU General Public License |
20
|
|
|
* along with this program; if not, write to the Free Software |
21
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
namespace Eccube\Controller\Mypage; |
26
|
|
|
|
27
|
|
|
use Eccube\Application; |
28
|
|
|
use Eccube\Controller\AbstractController; |
29
|
|
|
use Eccube\Event\EccubeEvents; |
30
|
|
|
use Eccube\Event\EventArgs; |
31
|
|
|
use Symfony\Component\HttpFoundation\Request; |
32
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
33
|
|
|
|
34
|
|
|
class DeliveryController extends AbstractController |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* お届け先一覧画面. |
38
|
|
|
* |
39
|
|
|
* @param Application $app |
40
|
|
|
* @param Request $request |
|
|
|
|
41
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
42
|
|
|
*/ |
43
|
1 |
|
public function index(Application $app, Request $request) |
|
|
|
|
44
|
|
|
{ |
45
|
1 |
|
$Customer = $app['user']; |
46
|
|
|
|
47
|
1 |
|
return $app->render('Mypage/delivery.twig', array( |
48
|
1 |
|
'Customer' => $Customer, |
49
|
1 |
|
)); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
|
|
|
|
53
|
|
|
* お届け先編集画面. |
54
|
|
|
* |
55
|
|
|
* @param Application $app |
56
|
|
|
* @param Request $request |
|
|
|
|
57
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
58
|
|
|
*/ |
59
|
12 |
|
public function edit(Application $app, Request $request, $id = null) |
60
|
|
|
{ |
61
|
8 |
|
$Customer = $app['user']; |
62
|
|
|
|
63
|
|
|
// 配送先住所最大値判定 |
64
|
|
|
// $idが存在する際は、追加処理ではなく、編集の処理ため本ロジックスキップ |
65
|
12 |
View Code Duplication |
if (is_null($id)) { |
|
|
|
|
66
|
4 |
|
$addressCurrNum = count($Customer->getCustomerAddresses()); |
67
|
4 |
|
$addressMax = $app['config']['deliv_addr_max']; |
68
|
4 |
|
if ($addressCurrNum >= $addressMax) { |
69
|
|
|
throw new NotFoundHttpException(); |
70
|
|
|
} |
71
|
4 |
|
} |
72
|
|
|
|
73
|
8 |
|
$CustomerAddress = $app['eccube.repository.customer_address']->findOrCreateByCustomerAndId($Customer, $id); |
74
|
|
|
|
75
|
8 |
|
$parentPage = $request->get('parent_page', null); |
76
|
|
|
|
77
|
|
|
// 正しい遷移かをチェック |
78
|
|
|
$allowdParents = array( |
79
|
8 |
|
$app->url('mypage_delivery'), |
80
|
8 |
|
$app->url('shopping_delivery'), |
81
|
8 |
|
); |
82
|
|
|
|
83
|
|
|
// 遷移が正しくない場合、デフォルトであるマイページの配送先追加の画面を設定する |
84
|
8 |
|
if (!in_array($parentPage, $allowdParents)) { |
85
|
8 |
|
$parentPage = $app->url('mypage_delivery'); |
86
|
8 |
|
} |
87
|
|
|
|
88
|
8 |
|
$builder = $app['form.factory'] |
89
|
8 |
|
->createBuilder('customer_address', $CustomerAddress); |
90
|
|
|
|
91
|
8 |
|
$event = new EventArgs( |
92
|
|
|
array( |
93
|
8 |
|
'builder' => $builder, |
94
|
8 |
|
'Customer' => $Customer, |
95
|
8 |
|
'CustomerAddress' => $CustomerAddress, |
96
|
8 |
|
), |
97
|
|
|
$request |
98
|
8 |
|
); |
99
|
8 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_MYPAGE_DELIVERY_EDIT_INITIALIZE, $event); |
100
|
|
|
|
101
|
8 |
|
$form = $builder->getForm(); |
102
|
8 |
|
$form->handleRequest($request); |
103
|
|
|
|
104
|
8 |
|
if ($form->isSubmitted() && $form->isValid()) { |
105
|
4 |
|
$app['orm.em']->persist($CustomerAddress); |
106
|
4 |
|
$app['orm.em']->flush(); |
107
|
|
|
|
108
|
4 |
|
$event = new EventArgs( |
109
|
|
|
array( |
110
|
4 |
|
'form' => $form, |
111
|
4 |
|
'Customer' => $Customer, |
112
|
4 |
|
'CustomerAddress' => $CustomerAddress, |
113
|
4 |
|
), |
114
|
|
|
$request |
115
|
4 |
|
); |
116
|
4 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_MYPAGE_DELIVERY_EDIT_COMPLETE, $event); |
117
|
|
|
|
118
|
4 |
|
$app->addSuccess('mypage.delivery.add.complete'); |
119
|
|
|
|
120
|
4 |
|
return $app->redirect($app->url('mypage_delivery')); |
121
|
|
|
} |
122
|
|
|
|
123
|
4 |
|
$BaseInfo = $app['eccube.repository.base_info']->get(); |
124
|
|
|
|
125
|
4 |
|
return $app->render('Mypage/delivery_edit.twig', array( |
126
|
4 |
|
'form' => $form->createView(), |
127
|
4 |
|
'parentPage' => $parentPage, |
128
|
4 |
|
'BaseInfo' => $BaseInfo, |
129
|
4 |
|
)); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
|
|
|
|
133
|
|
|
* お届け先を削除する. |
134
|
|
|
* |
135
|
|
|
* @param Application $app |
136
|
|
|
* @param $id |
|
|
|
|
137
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
138
|
|
|
*/ |
139
|
4 |
|
public function delete(Application $app, Request $request, $id) |
140
|
|
|
{ |
141
|
4 |
|
$this->isTokenValid($app); |
142
|
|
|
|
143
|
4 |
|
$Customer = $app['user']; |
144
|
|
|
|
145
|
4 |
|
$status = $app['eccube.repository.customer_address']->deleteByCustomerAndId($Customer, $id); |
146
|
|
|
|
147
|
4 |
|
if ($status) { |
148
|
2 |
|
$event = new EventArgs( |
149
|
|
|
array( |
150
|
2 |
|
'id' => $id, |
151
|
2 |
|
'Customer' => $Customer, |
152
|
2 |
|
), $request |
153
|
2 |
|
); |
154
|
2 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_MYPAGE_DELIVERY_DELETE_COMPLETE, $event); |
155
|
|
|
|
156
|
2 |
|
$app->addSuccess('mypage.address.delete.complete'); |
157
|
|
|
|
|
|
|
|
158
|
2 |
|
} else { |
159
|
2 |
|
$app->addError('mypage.address.delete.failed'); |
160
|
|
|
} |
161
|
|
|
|
162
|
4 |
|
return $app->redirect($app->url('mypage_delivery')); |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
|