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