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 Doctrine\ORM\EntityManager; |
28
|
|
|
use Eccube\Annotation\Component; |
29
|
|
|
use Eccube\Annotation\Inject; |
30
|
|
|
use Eccube\Application; |
31
|
|
|
use Eccube\Common\Constant; |
32
|
|
|
use Eccube\Controller\AbstractController; |
33
|
|
|
use Eccube\Entity\BaseInfo; |
34
|
|
|
use Eccube\Event\EccubeEvents; |
35
|
|
|
use Eccube\Event\EventArgs; |
36
|
|
|
use Eccube\Exception\CartException; |
37
|
|
|
use Eccube\Form\Type\Front\CustomerLoginType; |
38
|
|
|
use Eccube\Repository\CustomerFavoriteProductRepository; |
39
|
|
|
use Eccube\Repository\OrderRepository; |
40
|
|
|
use Eccube\Repository\ProductRepository; |
41
|
|
|
use Eccube\Service\CartService; |
42
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
43
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
44
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
45
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher; |
46
|
|
|
use Symfony\Component\Form\FormFactory; |
47
|
|
|
use Symfony\Component\HttpFoundation\Request; |
48
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @Component |
52
|
|
|
* @Route(service=MypageController::class) |
53
|
|
|
*/ |
54
|
|
|
class MypageController extends AbstractController |
55
|
|
|
{ |
56
|
|
|
/** |
57
|
|
|
* @Inject(ProductRepository::class) |
58
|
|
|
* @var ProductRepository |
59
|
|
|
*/ |
60
|
|
|
protected $productRepository; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @Inject(CustomerFavoriteProductRepository::class) |
64
|
|
|
* @var CustomerFavoriteProductRepository |
65
|
|
|
*/ |
66
|
|
|
protected $customerFavoriteProductRepository; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @Inject(BaseInfo::class) |
70
|
|
|
* @var BaseInfo |
71
|
|
|
*/ |
72
|
|
|
protected $BaseInfo; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @Inject(CartService::class) |
76
|
|
|
* @var CartService |
77
|
|
|
*/ |
78
|
|
|
protected $cartService; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @Inject("config") |
82
|
|
|
* @var array |
83
|
|
|
*/ |
84
|
|
|
protected $appConfig; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @Inject(OrderRepository::class) |
88
|
|
|
* @var OrderRepository |
89
|
|
|
*/ |
90
|
|
|
protected $orderRepository; |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @Inject("orm.em") |
94
|
|
|
* @var EntityManager |
95
|
|
|
*/ |
96
|
|
|
protected $entityManager; |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @Inject("eccube.event.dispatcher") |
100
|
|
|
* @var EventDispatcher |
101
|
|
|
*/ |
102
|
|
|
protected $eventDispatcher; |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @Inject("form.factory") |
106
|
|
|
* @var FormFactory |
107
|
|
|
*/ |
108
|
|
|
protected $formFactory; |
109
|
|
|
|
110
|
|
|
/** |
|
|
|
|
111
|
|
|
* ログイン画面. |
112
|
|
|
* |
113
|
|
|
* @Route("/mypage/login", name="mypage_login") |
114
|
|
|
* @Template("Mypage/login.twig") |
115
|
|
|
*/ |
|
|
|
|
116
|
2 |
|
public function login(Application $app, Request $request) |
117
|
|
|
{ |
118
|
2 |
|
if ($app->isGranted('IS_AUTHENTICATED_FULLY')) { |
119
|
1 |
|
log_info('認証済のためログイン処理をスキップ'); |
120
|
|
|
|
121
|
1 |
|
return $app->redirect($app->url('mypage')); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/* @var $form \Symfony\Component\Form\FormInterface */ |
125
|
1 |
|
$builder = $this->formFactory |
126
|
1 |
|
->createNamedBuilder('', CustomerLoginType::class); |
127
|
|
|
|
128
|
1 |
View Code Duplication |
if ($app->isGranted('IS_AUTHENTICATED_REMEMBERED')) { |
129
|
|
|
$Customer = $app->user(); |
130
|
|
|
if ($Customer) { |
131
|
|
|
$builder->get('login_email')->setData($Customer->getEmail()); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
135
|
1 |
|
$event = new EventArgs( |
136
|
|
|
array( |
137
|
1 |
|
'builder' => $builder, |
138
|
|
|
), |
139
|
1 |
|
$request |
140
|
|
|
); |
141
|
1 |
|
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_MYPAGE_MYPAGE_LOGIN_INITIALIZE, $event); |
142
|
|
|
|
143
|
1 |
|
$form = $builder->getForm(); |
144
|
|
|
|
145
|
|
|
return [ |
146
|
1 |
|
'error' => $app['security.last_error']($request), |
147
|
1 |
|
'form' => $form->createView(), |
148
|
|
|
]; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
|
|
|
|
152
|
|
|
* マイページ. |
153
|
|
|
* |
154
|
|
|
* @Route("/mypage", name="mypage") |
155
|
|
|
* @Template("Mypage/index.twig") |
156
|
|
|
*/ |
|
|
|
|
157
|
1 |
|
public function index(Application $app, Request $request) |
158
|
|
|
{ |
159
|
1 |
|
$Customer = $app['user']; |
160
|
|
|
|
161
|
|
|
// 購入処理中/決済処理中ステータスの受注を非表示にする. |
162
|
1 |
|
$this->entityManager |
163
|
1 |
|
->getFilters() |
164
|
1 |
|
->enable('incomplete_order_status_hidden'); |
165
|
|
|
|
166
|
|
|
// paginator |
167
|
1 |
|
$qb = $this->orderRepository->getQueryBuilderByCustomer($Customer); |
168
|
|
|
|
169
|
1 |
|
$event = new EventArgs( |
170
|
|
|
array( |
171
|
1 |
|
'qb' => $qb, |
172
|
1 |
|
'Customer' => $Customer, |
173
|
|
|
), |
174
|
1 |
|
$request |
175
|
|
|
); |
176
|
1 |
|
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_MYPAGE_MYPAGE_INDEX_SEARCH, $event); |
177
|
|
|
|
178
|
1 |
|
$pagination = $app['paginator']()->paginate( |
179
|
1 |
|
$qb, |
180
|
1 |
|
$request->get('pageno', 1), |
181
|
1 |
|
$this->appConfig['search_pmax'] |
182
|
|
|
); |
183
|
|
|
|
184
|
|
|
return [ |
185
|
1 |
|
'pagination' => $pagination, |
186
|
|
|
]; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
|
|
|
|
190
|
|
|
* 購入履歴詳細を表示する. |
191
|
|
|
* |
192
|
|
|
* @Route("/mypage/history/{id}", name="mypage_history", requirements={"id" = "\d+"}) |
193
|
|
|
* @Template("Mypage/history.twig") |
194
|
|
|
*/ |
|
|
|
|
195
|
2 |
View Code Duplication |
public function history(Application $app, Request $request, $id) |
|
|
|
|
196
|
|
|
{ |
197
|
2 |
|
$this->entityManager->getFilters()->enable('incomplete_order_status_hidden'); |
198
|
2 |
|
$Order = $this->orderRepository->findOneBy( |
199
|
|
|
array( |
200
|
2 |
|
'id' => $id, |
201
|
2 |
|
'Customer' => $app->user(), |
202
|
|
|
) |
203
|
|
|
); |
204
|
|
|
|
205
|
2 |
|
$event = new EventArgs( |
206
|
|
|
array( |
207
|
2 |
|
'Order' => $Order, |
208
|
|
|
), |
209
|
2 |
|
$request |
210
|
|
|
); |
211
|
2 |
|
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_MYPAGE_MYPAGE_HISTORY_INITIALIZE, $event); |
212
|
|
|
|
213
|
2 |
|
$Order = $event->getArgument('Order'); |
214
|
|
|
|
215
|
2 |
|
if (!$Order) { |
216
|
2 |
|
throw new NotFoundHttpException(); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
return [ |
220
|
|
|
'Order' => $Order, |
221
|
|
|
]; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
|
|
|
|
225
|
|
|
* 再購入を行う. |
226
|
|
|
* |
227
|
|
|
* @Route("/mypage/order/{id}", name="mypage_order", requirements={"id" = "\d+"}) |
228
|
|
|
* @Method("PUT") |
229
|
|
|
*/ |
|
|
|
|
230
|
|
|
public function order(Application $app, Request $request, $id) |
231
|
|
|
{ |
232
|
|
|
$this->isTokenValid($app); |
233
|
|
|
|
234
|
|
|
log_info('再注文開始', array($id)); |
235
|
|
|
|
236
|
|
|
$Customer = $app->user(); |
237
|
|
|
|
238
|
|
|
/* @var $Order \Eccube\Entity\Order */ |
239
|
|
|
$Order = $this->orderRepository->findOneBy( |
240
|
|
|
array( |
241
|
|
|
'id' => $id, |
242
|
|
|
'Customer' => $Customer, |
243
|
|
|
) |
244
|
|
|
); |
245
|
|
|
|
246
|
|
|
$event = new EventArgs( |
247
|
|
|
array( |
248
|
|
|
'Order' => $Order, |
249
|
|
|
'Customer' => $Customer, |
250
|
|
|
), |
251
|
|
|
$request |
252
|
|
|
); |
253
|
|
|
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_MYPAGE_MYPAGE_ORDER_INITIALIZE, $event); |
254
|
|
|
|
255
|
|
|
if (!$Order) { |
256
|
|
|
log_info('対象の注文が見つかりません', array($id)); |
257
|
|
|
throw new NotFoundHttpException(); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
foreach ($Order->getOrderDetails() as $OrderDetail) { |
261
|
|
|
try { |
262
|
|
|
if ($OrderDetail->getProduct() && |
263
|
|
|
$OrderDetail->getProductClass() |
264
|
|
|
) { |
265
|
|
|
$this->cartService->addProduct( |
|
|
|
|
266
|
|
|
$OrderDetail->getProductClass()->getId(), |
267
|
|
|
$OrderDetail->getQuantity() |
268
|
|
|
)->save(); |
269
|
|
|
} else { |
270
|
|
|
log_info($app->trans('cart.product.delete'), array($id)); |
271
|
|
|
$app->addRequestError('cart.product.delete'); |
272
|
|
|
} |
273
|
|
|
} catch (CartException $e) { |
274
|
|
|
log_info($e->getMessage(), array($id)); |
275
|
|
|
$app->addRequestError($e->getMessage()); |
276
|
|
|
} |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
$event = new EventArgs( |
280
|
|
|
array( |
281
|
|
|
'Order' => $Order, |
282
|
|
|
'Customer' => $Customer, |
283
|
|
|
), |
284
|
|
|
$request |
285
|
|
|
); |
286
|
|
|
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_MYPAGE_MYPAGE_ORDER_COMPLETE, $event); |
287
|
|
|
|
288
|
|
|
if ($event->getResponse() !== null) { |
289
|
|
|
return $event->getResponse(); |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
log_info('再注文完了', array($id)); |
293
|
|
|
|
294
|
|
|
return $app->redirect($app->url('cart')); |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/** |
|
|
|
|
298
|
|
|
* お気に入り商品を表示する. |
299
|
|
|
* |
300
|
|
|
* @Route("/mypage/favorite", name="mypage_favorite") |
301
|
|
|
* @Template("Mypage/favorite.twig") |
302
|
|
|
*/ |
|
|
|
|
303
|
2 |
|
public function favorite(Application $app, Request $request) |
304
|
|
|
{ |
305
|
2 |
|
if ($this->BaseInfo->getOptionFavoriteProduct() == Constant::DISABLED) { |
306
|
|
|
throw new NotFoundHttpException(); |
307
|
|
|
} |
308
|
2 |
|
$Customer = $app->user(); |
309
|
|
|
|
310
|
|
|
// paginator |
311
|
2 |
|
$qb = $this->customerFavoriteProductRepository->getQueryBuilderByCustomer($Customer); |
312
|
|
|
|
313
|
2 |
|
$event = new EventArgs( |
314
|
|
|
array( |
315
|
2 |
|
'qb' => $qb, |
316
|
2 |
|
'Customer' => $Customer, |
317
|
|
|
), |
318
|
2 |
|
$request |
319
|
|
|
); |
320
|
2 |
|
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_MYPAGE_MYPAGE_FAVORITE_SEARCH, $event); |
321
|
|
|
|
322
|
2 |
|
$pagination = $app['paginator']()->paginate( |
323
|
2 |
|
$qb, |
324
|
2 |
|
$request->get('pageno', 1), |
325
|
2 |
|
$this->appConfig['search_pmax'], |
326
|
2 |
|
array('wrap-queries' => true) |
327
|
|
|
); |
328
|
|
|
|
329
|
|
|
return [ |
330
|
2 |
|
'pagination' => $pagination, |
331
|
|
|
]; |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
/** |
|
|
|
|
335
|
|
|
* お気に入り商品を削除する. |
336
|
|
|
* |
337
|
|
|
* @Route("/mypage/favorite/{id}/delete", name="mypage_favorite_delete", requirements={"id" = "\d+"}) |
338
|
|
|
* @Method("DELETE") |
339
|
|
|
*/ |
|
|
|
|
340
|
1 |
|
public function delete(Application $app, Request $request, $id) |
341
|
|
|
{ |
342
|
1 |
|
$this->isTokenValid($app); |
343
|
|
|
|
344
|
1 |
|
$Customer = $app->user(); |
345
|
|
|
|
346
|
1 |
|
$Product = $this->productRepository->find($id); |
347
|
|
|
|
348
|
1 |
|
$event = new EventArgs( |
349
|
|
|
array( |
350
|
1 |
|
'Customer' => $Customer, |
351
|
1 |
|
'Product' => $Product, |
352
|
1 |
|
), $request |
353
|
|
|
); |
354
|
1 |
|
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_MYPAGE_MYPAGE_DELETE_INITIALIZE, $event); |
355
|
|
|
|
356
|
1 |
|
if ($Product) { |
357
|
|
|
log_info('お気に入り商品削除開始'); |
358
|
|
|
|
359
|
|
|
$this->customerFavoriteProductRepository->deleteFavorite($Customer, $Product); |
360
|
|
|
|
361
|
|
|
$event = new EventArgs( |
362
|
|
|
array( |
363
|
|
|
'Customer' => $Customer, |
364
|
|
|
'Product' => $Product, |
365
|
|
|
), $request |
366
|
|
|
); |
367
|
|
|
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_MYPAGE_MYPAGE_DELETE_COMPLETE, $event); |
368
|
|
|
|
369
|
|
|
log_info('お気に入り商品削除完了'); |
370
|
|
|
} |
371
|
|
|
|
372
|
1 |
|
return $app->redirect($app->url('mypage_favorite')); |
373
|
|
|
} |
374
|
|
|
} |
375
|
|
|
|