1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of EC-CUBE |
5
|
|
|
* |
6
|
|
|
* Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved. |
7
|
|
|
* |
8
|
|
|
* http://www.lockon.co.jp/ |
9
|
|
|
* |
10
|
|
|
* This program is free software; you can redistribute it and/or |
11
|
|
|
* modify it under the terms of the GNU General Public License |
12
|
|
|
* as published by the Free Software Foundation; either version 2 |
13
|
|
|
* of the License, or (at your option) any later version. |
14
|
|
|
* |
15
|
|
|
* This program is distributed in the hope that it will be useful, |
16
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18
|
|
|
* GNU General Public License for more details. |
19
|
|
|
* |
20
|
|
|
* You should have received a copy of the GNU General Public License |
21
|
|
|
* along with this program; if not, write to the Free Software |
22
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
namespace Eccube\Controller\Mypage; |
26
|
|
|
|
27
|
|
|
use Eccube\Application; |
28
|
|
|
use Eccube\Common\Constant; |
29
|
|
|
use Eccube\Controller\AbstractController; |
30
|
|
|
use Eccube\Event\EccubeEvents; |
31
|
|
|
use Eccube\Event\EventArgs; |
32
|
|
|
use Eccube\Exception\CartException; |
33
|
|
|
use Symfony\Component\HttpFoundation\Request; |
34
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
35
|
|
|
|
36
|
2 |
|
class MypageController extends AbstractController |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
/** |
39
|
|
|
* ログイン画面. |
40
|
|
|
* |
41
|
|
|
* @param Application $app |
42
|
|
|
* @param Request $request |
|
|
|
|
43
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response |
44
|
|
|
*/ |
45
|
|
|
public function login(Application $app, Request $request) |
46
|
|
|
{ |
47
|
|
|
if ($app->isGranted('IS_AUTHENTICATED_FULLY')) { |
48
|
|
|
return $app->redirect($app->url('mypage')); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/* @var $form \Symfony\Component\Form\FormInterface */ |
52
|
|
|
$builder = $app['form.factory'] |
53
|
|
|
->createNamedBuilder('', 'customer_login'); |
54
|
|
|
|
55
|
1 |
View Code Duplication |
if ($app->isGranted('IS_AUTHENTICATED_REMEMBERED')) { |
|
|
|
|
56
|
|
|
$Customer = $app->user(); |
57
|
1 |
|
if ($Customer) { |
58
|
|
|
$builder->get('login_email')->setData($Customer->getEmail()); |
59
|
2 |
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$event = new EventArgs( |
63
|
|
|
array( |
64
|
|
|
'builder' => $builder, |
65
|
|
|
), |
66
|
|
|
$request |
67
|
1 |
|
); |
68
|
|
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_MYPAGE_MYPAGE_LOGIN_INITIALIZE, $event); |
69
|
|
|
|
70
|
|
|
$form = $builder->getForm(); |
71
|
|
|
|
72
|
|
|
return $app->render('Mypage/login.twig', array( |
73
|
|
|
'error' => $app['security.last_error']($request), |
74
|
|
|
'form' => $form->createView(), |
75
|
|
|
)); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
1 |
|
* マイページ |
80
|
1 |
|
* |
81
|
|
|
* @param Application $app |
82
|
|
|
* @param Request $request |
|
|
|
|
83
|
1 |
|
* @return \Symfony\Component\HttpFoundation\Response |
84
|
|
|
*/ |
85
|
|
|
public function index(Application $app, Request $request) |
86
|
1 |
|
{ |
87
|
|
|
$Customer = $app['user']; |
88
|
|
|
|
89
|
|
|
// 購入処理中/決済処理中ステータスの受注を非表示にする. |
90
|
|
|
$app['orm.em'] |
91
|
|
|
->getFilters() |
92
|
|
|
->enable('incomplete_order_status_hidden'); |
93
|
|
|
|
94
|
2 |
|
// paginator |
95
|
|
|
$qb = $app['eccube.repository.order']->getQueryBuilderByCustomer($Customer); |
96
|
|
|
|
97
|
|
|
$event = new EventArgs( |
98
|
|
|
array( |
99
|
|
|
'qb' => $qb, |
100
|
|
|
'Customer' => $Customer, |
101
|
|
|
), |
102
|
|
|
$request |
103
|
|
|
); |
104
|
2 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_MYPAGE_MYPAGE_INDEX_SEARCH, $event); |
105
|
|
|
|
106
|
2 |
|
$pagination = $app['paginator']()->paginate( |
107
|
|
|
$qb, |
108
|
|
|
$request->get('pageno', 1), |
109
|
|
|
$app['config']['search_pmax'] |
110
|
1 |
|
); |
111
|
|
|
|
112
|
|
|
return $app->render('Mypage/index.twig', array( |
113
|
2 |
|
'pagination' => $pagination, |
114
|
|
|
)); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
|
|
|
|
118
|
|
|
* 購入履歴詳細を表示する. |
119
|
|
|
* |
120
|
|
|
* @param Application $app |
121
|
|
|
* @param Request $request |
|
|
|
|
122
|
1 |
|
* @param $id |
|
|
|
|
123
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
124
|
|
|
*/ |
125
|
|
|
public function history(Application $app, Request $request, $id) |
126
|
|
|
{ |
127
|
|
|
/* @var $softDeleteFilter \Eccube\Doctrine\Filter\SoftDeleteFilter */ |
128
|
|
|
$softDeleteFilter = $app['orm.em']->getFilters()->getFilter('soft_delete'); |
129
|
|
|
$softDeleteFilter->setExcludes(array( |
130
|
|
|
'Eccube\Entity\ProductClass', |
131
|
|
|
)); |
132
|
|
|
|
133
|
1 |
|
$Order = $app['eccube.repository.order']->findOneBy(array( |
134
|
|
|
'id' => $id, |
135
|
|
|
'Customer' => $app->user(), |
136
|
|
|
)); |
137
|
1 |
|
|
138
|
|
|
$event = new EventArgs( |
139
|
|
|
array( |
140
|
|
|
'Order' => $Order, |
141
|
|
|
), |
142
|
|
|
$request |
143
|
1 |
|
); |
144
|
|
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_MYPAGE_MYPAGE_HISTORY_INITIALIZE, $event); |
145
|
|
|
|
146
|
1 |
|
$Order = $event->getArgument('Order'); |
147
|
|
|
|
148
|
|
|
if (!$Order) { |
149
|
|
|
throw new NotFoundHttpException(); |
150
|
1 |
|
} |
151
|
|
|
|
152
|
|
|
return $app->render('Mypage/history.twig', array( |
153
|
|
|
'Order' => $Order, |
154
|
|
|
)); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
|
|
|
|
158
|
1 |
|
* 再購入を行う. |
159
|
|
|
* |
160
|
|
|
* @param Application $app |
161
|
|
|
* @param Request $request |
|
|
|
|
162
|
|
|
* @param $id |
|
|
|
|
163
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
164
|
|
|
*/ |
165
|
|
|
public function order(Application $app, Request $request, $id) |
166
|
|
|
{ |
167
|
|
|
$this->isTokenValid($app); |
168
|
|
|
|
169
|
1 |
|
$Customer = $app->user(); |
170
|
1 |
|
|
171
|
|
|
/* @var $Order \Eccube\Entity\Order */ |
172
|
|
|
$Order = $app['eccube.repository.order']->findOneBy(array( |
173
|
1 |
|
'id' => $id, |
174
|
|
|
'Customer' => $Customer, |
175
|
|
|
)); |
176
|
|
|
|
177
|
|
|
$event = new EventArgs( |
178
|
|
|
array( |
179
|
1 |
|
'Order' => $Order, |
180
|
|
|
'Customer' => $Customer, |
181
|
|
|
), |
182
|
|
|
$request |
183
|
|
|
); |
184
|
|
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_MYPAGE_MYPAGE_ORDER_INITIALIZE, $event); |
185
|
|
|
|
186
|
|
|
if (!$Order) { |
187
|
1 |
|
throw new NotFoundHttpException(); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
foreach ($Order->getOrderDetails() as $OrderDetail) { |
191
|
|
|
try { |
192
|
|
|
if ($OrderDetail->getProduct()) { |
193
|
|
|
$app['eccube.service.cart']->addProduct($OrderDetail->getProductClass()->getId(), $OrderDetail->getQuantity())->save(); |
194
|
1 |
|
} else { |
195
|
|
|
$app->addRequestError('cart.product.delete'); |
196
|
|
|
} |
197
|
|
|
} catch (CartException $e) { |
198
|
|
|
$app->addRequestError($e->getMessage()); |
199
|
1 |
|
} |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
$event = new EventArgs( |
203
|
|
|
array( |
204
|
|
|
'Order' => $Order, |
205
|
|
|
'Customer' => $Customer, |
206
|
|
|
), |
207
|
|
|
$request |
208
|
|
|
); |
209
|
|
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_MYPAGE_MYPAGE_ORDER_COMPLETE, $event); |
210
|
|
|
|
211
|
|
|
if ($event->getResponse() !== null) { |
212
|
|
|
return $event->getResponse(); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
return $app->redirect($app->url('cart')); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* お気に入り商品を表示する. |
220
|
|
|
* |
221
|
|
|
* @param Application $app |
222
|
|
|
* @param Request $request |
|
|
|
|
223
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
224
|
|
|
*/ |
225
|
|
|
public function favorite(Application $app, Request $request) |
226
|
|
|
{ |
227
|
|
|
$BaseInfo = $app['eccube.repository.base_info']->get(); |
228
|
|
|
|
229
|
|
|
if ($BaseInfo->getOptionFavoriteProduct() == Constant::ENABLED) { |
230
|
|
|
$Customer = $app->user(); |
231
|
|
|
|
232
|
|
|
// paginator |
233
|
|
|
$qb = $app['eccube.repository.product']->getFavoriteProductQueryBuilderByCustomer($Customer); |
234
|
|
|
|
235
|
|
|
$event = new EventArgs( |
236
|
|
|
array( |
237
|
|
|
'qb' => $qb, |
238
|
|
|
'Customer' => $Customer, |
239
|
|
|
), |
240
|
|
|
$request |
241
|
|
|
); |
242
|
|
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_MYPAGE_MYPAGE_FAVORITE_SEARCH, $event); |
243
|
|
|
|
244
|
|
|
$pagination = $app['paginator']()->paginate( |
245
|
|
|
$qb, |
246
|
|
|
$request->get('pageno', 1), |
247
|
|
|
$app['config']['search_pmax'] |
248
|
|
|
); |
249
|
|
|
|
250
|
|
|
return $app->render('Mypage/favorite.twig', array( |
251
|
|
|
'pagination' => $pagination, |
252
|
|
|
)); |
253
|
|
|
} else { |
254
|
|
|
throw new NotFoundHttpException(); |
255
|
|
|
} |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
|
|
|
|
259
|
|
|
* お気に入り商品を削除する. |
260
|
|
|
* |
261
|
|
|
* @param Application $app |
262
|
|
|
* @param Request $request |
|
|
|
|
263
|
|
|
* @param $id |
|
|
|
|
264
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
265
|
|
|
*/ |
266
|
|
|
public function delete(Application $app, Request $request, $id) |
267
|
|
|
{ |
268
|
|
|
$this->isTokenValid($app); |
269
|
|
|
|
270
|
|
|
$Customer = $app->user(); |
271
|
|
|
|
272
|
|
|
$Product = $app['eccube.repository.product']->find($id); |
273
|
|
|
|
274
|
|
|
$event = new EventArgs( |
275
|
|
|
array( |
276
|
|
|
'Customer' => $Customer, |
277
|
|
|
'Product' => $Product, |
278
|
|
|
), $request |
279
|
|
|
); |
280
|
|
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_MYPAGE_MYPAGE_DELETE_INITIALIZE, $event); |
281
|
|
|
|
282
|
|
|
if ($Product) { |
283
|
|
|
$app['eccube.repository.customer_favorite_product']->deleteFavorite($Customer, $Product); |
284
|
|
|
|
285
|
|
|
$event = new EventArgs( |
286
|
|
|
array( |
287
|
|
|
'Customer' => $Customer, |
288
|
|
|
'Product' => $Product, |
289
|
|
|
), $request |
290
|
|
|
); |
291
|
|
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_MYPAGE_MYPAGE_DELETE_COMPLETE, $event); |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
return $app->redirect($app->url('mypage_favorite')); |
295
|
|
|
} |
296
|
|
|
} |
297
|
|
|
|