|
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
|
|
|
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
|
4 |
|
public function login(Application $app, Request $request) |
|
46
|
|
|
{ |
|
47
|
4 |
|
if ($app->isGranted('IS_AUTHENTICATED_FULLY')) { |
|
48
|
2 |
|
log_info('認証済のためログイン処理をスキップ'); |
|
49
|
|
|
|
|
50
|
2 |
|
return $app->redirect($app->url('mypage')); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/* @var $form \Symfony\Component\Form\FormInterface */ |
|
54
|
2 |
|
$builder = $app['form.factory'] |
|
55
|
2 |
|
->createNamedBuilder('', 'customer_login'); |
|
56
|
|
|
|
|
57
|
2 |
View Code Duplication |
if ($app->isGranted('IS_AUTHENTICATED_REMEMBERED')) { |
|
|
|
|
|
|
58
|
|
|
$Customer = $app->user(); |
|
59
|
|
|
if ($Customer) { |
|
60
|
|
|
$builder->get('login_email')->setData($Customer->getEmail()); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
2 |
|
$event = new EventArgs( |
|
65
|
|
|
array( |
|
66
|
2 |
|
'builder' => $builder, |
|
67
|
|
|
), |
|
68
|
|
|
$request |
|
69
|
|
|
); |
|
70
|
2 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_MYPAGE_MYPAGE_LOGIN_INITIALIZE, $event); |
|
71
|
|
|
|
|
72
|
2 |
|
$form = $builder->getForm(); |
|
73
|
|
|
|
|
74
|
2 |
|
return $app->render('Mypage/login.twig', array( |
|
75
|
2 |
|
'error' => $app['security.last_error']($request), |
|
76
|
2 |
|
'form' => $form->createView(), |
|
77
|
|
|
)); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* マイページ |
|
82
|
|
|
* |
|
83
|
|
|
* @param Application $app |
|
84
|
|
|
* @param Request $request |
|
|
|
|
|
|
85
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
|
86
|
|
|
*/ |
|
87
|
2 |
|
public function index(Application $app, Request $request) |
|
88
|
|
|
{ |
|
89
|
2 |
|
$Customer = $app['user']; |
|
90
|
|
|
|
|
91
|
|
|
/* @var $softDeleteFilter \Eccube\Doctrine\Filter\SoftDeleteFilter */ |
|
92
|
2 |
|
$softDeleteFilter = $app['orm.em']->getFilters()->getFilter('soft_delete'); |
|
93
|
2 |
|
$softDeleteFilter->setExcludes(array( |
|
94
|
2 |
|
'Eccube\Entity\ProductClass', |
|
95
|
|
|
)); |
|
96
|
|
|
|
|
97
|
|
|
// 購入処理中/決済処理中ステータスの受注を非表示にする. |
|
98
|
2 |
|
$app['orm.em'] |
|
99
|
2 |
|
->getFilters() |
|
100
|
2 |
|
->enable('incomplete_order_status_hidden'); |
|
101
|
|
|
|
|
102
|
|
|
// paginator |
|
103
|
2 |
|
$qb = $app['eccube.repository.order']->getQueryBuilderByCustomer($Customer); |
|
104
|
|
|
|
|
105
|
2 |
|
$event = new EventArgs( |
|
106
|
|
|
array( |
|
107
|
2 |
|
'qb' => $qb, |
|
108
|
2 |
|
'Customer' => $Customer, |
|
109
|
|
|
), |
|
110
|
|
|
$request |
|
111
|
|
|
); |
|
112
|
2 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_MYPAGE_MYPAGE_INDEX_SEARCH, $event); |
|
113
|
|
|
|
|
114
|
2 |
|
$pagination = $app['paginator']()->paginate( |
|
115
|
|
|
$qb, |
|
116
|
2 |
|
$request->get('pageno', 1), |
|
117
|
2 |
|
$app['config']['search_pmax'], |
|
118
|
2 |
|
array('wrap-queries' => true) |
|
119
|
|
|
); |
|
120
|
|
|
|
|
121
|
2 |
|
return $app->render('Mypage/index.twig', array( |
|
122
|
2 |
|
'pagination' => $pagination, |
|
123
|
|
|
)); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
|
|
|
|
|
127
|
|
|
* 購入履歴詳細を表示する. |
|
128
|
|
|
* |
|
129
|
|
|
* @param Application $app |
|
130
|
|
|
* @param Request $request |
|
|
|
|
|
|
131
|
|
|
* @param $id |
|
|
|
|
|
|
132
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
|
133
|
|
|
*/ |
|
134
|
4 |
|
public function history(Application $app, Request $request, $id) |
|
135
|
|
|
{ |
|
136
|
|
|
/* @var $softDeleteFilter \Eccube\Doctrine\Filter\SoftDeleteFilter */ |
|
137
|
4 |
|
$softDeleteFilter = $app['orm.em']->getFilters()->getFilter('soft_delete'); |
|
138
|
4 |
|
$softDeleteFilter->setExcludes(array( |
|
139
|
4 |
|
'Eccube\Entity\ProductClass', |
|
140
|
|
|
)); |
|
141
|
|
|
|
|
142
|
4 |
|
$app['orm.em']->getFilters()->enable('incomplete_order_status_hidden'); |
|
143
|
4 |
|
$Order = $app['eccube.repository.order']->findOneBy(array( |
|
144
|
4 |
|
'id' => $id, |
|
145
|
4 |
|
'Customer' => $app->user(), |
|
146
|
|
|
)); |
|
147
|
|
|
|
|
|
|
|
|
|
148
|
4 |
|
$event = new EventArgs( |
|
149
|
|
|
array( |
|
150
|
4 |
|
'Order' => $Order, |
|
151
|
|
|
), |
|
152
|
|
|
$request |
|
153
|
|
|
); |
|
154
|
4 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_MYPAGE_MYPAGE_HISTORY_INITIALIZE, $event); |
|
155
|
|
|
|
|
156
|
4 |
|
$Order = $event->getArgument('Order'); |
|
157
|
|
|
|
|
158
|
4 |
|
if (!$Order) { |
|
159
|
2 |
|
throw new NotFoundHttpException(); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
2 |
|
return $app->render('Mypage/history.twig', array( |
|
163
|
2 |
|
'Order' => $Order, |
|
164
|
|
|
)); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
|
|
|
|
|
168
|
|
|
* 再購入を行う. |
|
169
|
|
|
* |
|
170
|
|
|
* @param Application $app |
|
171
|
|
|
* @param Request $request |
|
|
|
|
|
|
172
|
|
|
* @param $id |
|
|
|
|
|
|
173
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
|
174
|
|
|
*/ |
|
175
|
2 |
|
public function order(Application $app, Request $request, $id) |
|
176
|
|
|
{ |
|
177
|
2 |
|
$this->isTokenValid($app); |
|
178
|
|
|
|
|
179
|
2 |
|
log_info('再注文開始', array($id)); |
|
180
|
|
|
|
|
181
|
2 |
|
$Customer = $app->user(); |
|
182
|
|
|
|
|
183
|
|
|
/* @var $Order \Eccube\Entity\Order */ |
|
184
|
2 |
|
$Order = $app['eccube.repository.order']->findOneBy(array( |
|
185
|
2 |
|
'id' => $id, |
|
186
|
2 |
|
'Customer' => $Customer, |
|
187
|
|
|
)); |
|
188
|
|
|
|
|
189
|
2 |
|
$event = new EventArgs( |
|
190
|
|
|
array( |
|
191
|
2 |
|
'Order' => $Order, |
|
192
|
2 |
|
'Customer' => $Customer, |
|
193
|
|
|
), |
|
194
|
|
|
$request |
|
195
|
|
|
); |
|
196
|
2 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_MYPAGE_MYPAGE_ORDER_INITIALIZE, $event); |
|
197
|
|
|
|
|
198
|
2 |
|
if (!$Order) { |
|
199
|
|
|
log_info('対象の注文が見つかりません', array($id)); |
|
200
|
|
|
throw new NotFoundHttpException(); |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
2 |
|
foreach ($Order->getOrderDetails() as $OrderDetail) { |
|
204
|
|
|
try { |
|
205
|
2 |
|
if ($OrderDetail->getProduct() && |
|
206
|
2 |
|
$OrderDetail->getProductClass()) { |
|
207
|
2 |
|
$app['eccube.service.cart']->addProduct($OrderDetail->getProductClass()->getId(), $OrderDetail->getQuantity())->save(); |
|
208
|
|
|
} else { |
|
209
|
|
|
log_info($app->trans('cart.product.delete'), array($id)); |
|
210
|
2 |
|
$app->addRequestError('cart.product.delete'); |
|
211
|
|
|
} |
|
212
|
|
|
} catch (CartException $e) { |
|
213
|
|
|
log_info($e->getMessage(), array($id)); |
|
214
|
2 |
|
$app->addRequestError($e->getMessage()); |
|
215
|
|
|
} |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
2 |
|
$event = new EventArgs( |
|
219
|
|
|
array( |
|
220
|
2 |
|
'Order' => $Order, |
|
221
|
2 |
|
'Customer' => $Customer, |
|
222
|
|
|
), |
|
223
|
|
|
$request |
|
224
|
|
|
); |
|
225
|
2 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_MYPAGE_MYPAGE_ORDER_COMPLETE, $event); |
|
226
|
|
|
|
|
227
|
2 |
|
if ($event->getResponse() !== null) { |
|
228
|
|
|
return $event->getResponse(); |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
2 |
|
log_info('再注文完了', array($id)); |
|
232
|
|
|
|
|
233
|
2 |
|
return $app->redirect($app->url('cart')); |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
|
|
/** |
|
237
|
|
|
* お気に入り商品を表示する. |
|
238
|
|
|
* |
|
239
|
|
|
* @param Application $app |
|
240
|
|
|
* @param Request $request |
|
|
|
|
|
|
241
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
|
242
|
|
|
*/ |
|
243
|
3 |
|
public function favorite(Application $app, Request $request) |
|
244
|
|
|
{ |
|
245
|
3 |
|
$BaseInfo = $app['eccube.repository.base_info']->get(); |
|
246
|
|
|
|
|
247
|
3 |
|
if ($BaseInfo->getOptionFavoriteProduct() == Constant::ENABLED) { |
|
248
|
3 |
|
$Customer = $app->user(); |
|
249
|
|
|
|
|
250
|
|
|
// paginator |
|
251
|
3 |
|
$qb = $app['eccube.repository.customer_favorite_product']->getQueryBuilderByCustomer($Customer); |
|
252
|
|
|
|
|
253
|
3 |
|
$event = new EventArgs( |
|
254
|
|
|
array( |
|
255
|
3 |
|
'qb' => $qb, |
|
256
|
3 |
|
'Customer' => $Customer, |
|
257
|
|
|
), |
|
258
|
|
|
$request |
|
259
|
|
|
); |
|
260
|
3 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_MYPAGE_MYPAGE_FAVORITE_SEARCH, $event); |
|
261
|
|
|
|
|
262
|
3 |
|
$pagination = $app['paginator']()->paginate( |
|
263
|
|
|
$qb, |
|
264
|
3 |
|
$request->get('pageno', 1), |
|
265
|
3 |
|
$app['config']['search_pmax'], |
|
266
|
3 |
|
array('wrap-queries' => true) |
|
267
|
|
|
); |
|
268
|
|
|
|
|
269
|
3 |
|
return $app->render('Mypage/favorite.twig', array( |
|
270
|
3 |
|
'pagination' => $pagination, |
|
271
|
|
|
)); |
|
272
|
|
|
} else { |
|
273
|
|
|
throw new NotFoundHttpException(); |
|
274
|
|
|
} |
|
275
|
|
|
} |
|
276
|
|
|
|
|
277
|
|
|
/** |
|
|
|
|
|
|
278
|
|
|
* お気に入り商品を削除する. |
|
279
|
|
|
* |
|
280
|
|
|
* @param Application $app |
|
281
|
|
|
* @param Request $request |
|
|
|
|
|
|
282
|
|
|
* @param $id |
|
|
|
|
|
|
283
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
|
284
|
|
|
*/ |
|
285
|
2 |
|
public function delete(Application $app, Request $request, $id) |
|
286
|
|
|
{ |
|
287
|
2 |
|
$this->isTokenValid($app); |
|
288
|
|
|
|
|
289
|
2 |
|
$Customer = $app->user(); |
|
290
|
|
|
|
|
291
|
2 |
|
$Product = $app['eccube.repository.product']->find($id); |
|
292
|
|
|
|
|
293
|
2 |
|
$event = new EventArgs( |
|
294
|
|
|
array( |
|
295
|
2 |
|
'Customer' => $Customer, |
|
296
|
2 |
|
'Product' => $Product, |
|
297
|
|
|
), $request |
|
298
|
|
|
); |
|
299
|
2 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_MYPAGE_MYPAGE_DELETE_INITIALIZE, $event); |
|
300
|
|
|
|
|
301
|
2 |
View Code Duplication |
if ($Product) { |
|
|
|
|
|
|
302
|
1 |
|
log_info('お気に入り商品削除開始'); |
|
303
|
|
|
|
|
304
|
1 |
|
$app['eccube.repository.customer_favorite_product']->deleteFavorite($Customer, $Product); |
|
305
|
|
|
|
|
306
|
1 |
|
$event = new EventArgs( |
|
307
|
|
|
array( |
|
308
|
1 |
|
'Customer' => $Customer, |
|
309
|
1 |
|
'Product' => $Product, |
|
310
|
|
|
), $request |
|
311
|
|
|
); |
|
312
|
1 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_MYPAGE_MYPAGE_DELETE_COMPLETE, $event); |
|
313
|
|
|
|
|
314
|
1 |
|
log_info('お気に入り商品削除完了'); |
|
315
|
|
|
} |
|
316
|
|
|
|
|
317
|
2 |
|
return $app->redirect($app->url('mypage_favorite')); |
|
318
|
|
|
} |
|
319
|
|
|
} |
|
320
|
|
|
|