|
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\Admin\Order; |
|
26
|
|
|
|
|
27
|
|
|
use Eccube\Application; |
|
28
|
|
|
use Eccube\Entity\MailHistory; |
|
29
|
|
|
use Eccube\Event\EccubeEvents; |
|
30
|
|
|
use Eccube\Event\EventArgs; |
|
31
|
|
|
use Eccube\Form\Type\Admin\MailType; |
|
32
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
33
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
34
|
|
|
|
|
35
|
|
|
class MailController |
|
|
|
|
|
|
36
|
|
|
{ |
|
37
|
6 |
|
public function index(Application $app, Request $request, $id) |
|
|
|
|
|
|
38
|
|
|
{ |
|
39
|
6 |
|
$Order = $app['eccube.repository.order']->find($id); |
|
40
|
|
|
|
|
41
|
6 |
|
if (is_null($Order)) { |
|
42
|
|
|
throw new NotFoundHttpException('order not found.'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
6 |
|
$MailHistories = $app['eccube.repository.mail_history']->findBy(array('Order' => $id)); |
|
46
|
|
|
|
|
47
|
6 |
|
$builder = $app['form.factory']->createBuilder(MailType::class); |
|
48
|
|
|
|
|
49
|
6 |
|
$event = new EventArgs( |
|
50
|
|
|
array( |
|
51
|
6 |
|
'builder' => $builder, |
|
52
|
6 |
|
'Order' => $Order, |
|
53
|
6 |
|
'MailHistories' => $MailHistories, |
|
54
|
|
|
), |
|
55
|
|
|
$request |
|
56
|
|
|
); |
|
57
|
6 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_MAIL_INDEX_INITIALIZE, $event); |
|
58
|
|
|
|
|
59
|
6 |
|
$form = $builder->getForm(); |
|
60
|
|
|
|
|
61
|
6 |
|
if ('POST' === $request->getMethod()) { |
|
|
|
|
|
|
62
|
|
|
|
|
63
|
4 |
|
$form->handleRequest($request); |
|
64
|
|
|
|
|
65
|
4 |
|
$mode = $request->get('mode'); |
|
66
|
|
|
|
|
67
|
|
|
// テンプレート変更の場合は. バリデーション前に内容差し替え. |
|
68
|
4 |
|
if ($mode == 'change') { |
|
69
|
|
View Code Duplication |
if ($form->get('template')->isValid()) { |
|
|
|
|
|
|
70
|
|
|
/** @var $data \Eccube\Entity\MailTemplate */ |
|
71
|
|
|
$MailTemplate = $form->get('template')->getData(); |
|
72
|
|
|
$form = $builder->getForm(); |
|
73
|
|
|
$event = new EventArgs( |
|
74
|
|
|
array( |
|
75
|
|
|
'form' => $form, |
|
76
|
|
|
'Order' => $Order, |
|
77
|
|
|
'MailTemplate' => $MailTemplate, |
|
78
|
|
|
), |
|
79
|
|
|
$request |
|
80
|
|
|
); |
|
81
|
|
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_MAIL_INDEX_CHANGE, $event); |
|
82
|
|
|
$form->get('template')->setData($MailTemplate); |
|
83
|
|
|
$form->get('subject')->setData($MailTemplate->getSubject()); |
|
84
|
|
|
$form->get('header')->setData($MailTemplate->getHeader()); |
|
85
|
|
|
$form->get('footer')->setData($MailTemplate->getFooter()); |
|
86
|
|
|
} |
|
87
|
4 |
|
} else if ($form->isValid()) { |
|
88
|
|
|
switch ($mode) { |
|
89
|
4 |
|
case 'confirm': |
|
90
|
|
|
// フォームをFreezeして再生成. |
|
91
|
|
|
|
|
92
|
2 |
|
$builder->setAttribute('freeze', true); |
|
93
|
2 |
|
$builder->setAttribute('freeze_display_text', true); |
|
94
|
|
|
|
|
95
|
2 |
|
$data = $form->getData(); |
|
96
|
2 |
|
$body = $this->createBody($app, $data['header'], $data['footer'], $Order); |
|
97
|
|
|
|
|
98
|
2 |
|
$MailTemplate = $form->get('template')->getData(); |
|
99
|
|
|
|
|
100
|
2 |
|
$form = $builder->getForm(); |
|
101
|
|
|
|
|
102
|
2 |
|
$event = new EventArgs( |
|
103
|
|
|
array( |
|
104
|
2 |
|
'form' => $form, |
|
105
|
2 |
|
'Order' => $Order, |
|
106
|
2 |
|
'MailTemplate' => $MailTemplate, |
|
107
|
|
|
), |
|
108
|
|
|
$request |
|
109
|
|
|
); |
|
110
|
2 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_MAIL_INDEX_CONFIRM, $event); |
|
111
|
|
|
|
|
112
|
2 |
|
$form->setData($data); |
|
113
|
2 |
|
$form->get('template')->setData($MailTemplate); |
|
114
|
|
|
|
|
115
|
|
|
|
|
116
|
2 |
|
return $app->render('Order/mail_confirm.twig', array( |
|
117
|
2 |
|
'form' => $form->createView(), |
|
118
|
2 |
|
'body' => $body, |
|
119
|
2 |
|
'Order' => $Order, |
|
120
|
|
|
)); |
|
121
|
|
|
break; |
|
|
|
|
|
|
122
|
2 |
|
case 'complete': |
|
|
|
|
|
|
123
|
|
|
|
|
124
|
2 |
|
$data = $form->getData(); |
|
125
|
2 |
|
$body = $this->createBody($app, $data['header'], $data['footer'], $Order); |
|
126
|
|
|
|
|
127
|
|
|
// メール送信 |
|
128
|
2 |
|
$app['eccube.service.mail']->sendAdminOrderMail($Order, $data); |
|
129
|
|
|
|
|
130
|
|
|
// 送信履歴を保存. |
|
131
|
2 |
|
$MailTemplate = $form->get('template')->getData(); |
|
132
|
2 |
|
$MailHistory = new MailHistory(); |
|
133
|
|
|
$MailHistory |
|
134
|
2 |
|
->setSubject($data['subject']) |
|
135
|
2 |
|
->setMailBody($body) |
|
136
|
2 |
|
->setMailTemplate($MailTemplate) |
|
137
|
2 |
|
->setSendDate(new \DateTime()) |
|
138
|
2 |
|
->setOrder($Order); |
|
139
|
|
|
|
|
140
|
2 |
|
$app['orm.em']->persist($MailHistory); |
|
141
|
2 |
|
$app['orm.em']->flush($MailHistory); |
|
142
|
|
|
|
|
143
|
2 |
|
$event = new EventArgs( |
|
144
|
|
|
array( |
|
145
|
2 |
|
'form' => $form, |
|
146
|
2 |
|
'Order' => $Order, |
|
147
|
2 |
|
'MailTemplate' => $MailTemplate, |
|
148
|
2 |
|
'MailHistory' => $MailHistory, |
|
149
|
|
|
), |
|
150
|
|
|
$request |
|
151
|
|
|
); |
|
152
|
2 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_MAIL_INDEX_COMPLETE, $event); |
|
153
|
|
|
|
|
154
|
|
|
|
|
155
|
2 |
|
return $app->redirect($app->url('admin_order_mail_complete')); |
|
156
|
|
|
break; |
|
|
|
|
|
|
157
|
|
|
default: |
|
158
|
|
|
break; |
|
159
|
|
|
} |
|
160
|
|
|
} |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
2 |
|
return $app->render('Order/mail.twig', array( |
|
|
|
|
|
|
164
|
2 |
|
'form' => $form->createView(), |
|
165
|
2 |
|
'Order' => $Order, |
|
166
|
2 |
|
'MailHistories' => $MailHistories |
|
167
|
|
|
)); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
|
|
171
|
1 |
|
public function complete(Application $app) |
|
|
|
|
|
|
172
|
|
|
{ |
|
173
|
1 |
|
return $app->render('Order/mail_complete.twig'); |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
|
|
177
|
2 |
|
public function view(Application $app, Request $request) |
|
|
|
|
|
|
178
|
|
|
{ |
|
179
|
|
|
|
|
180
|
2 |
|
if ($request->isXmlHttpRequest()) { |
|
181
|
2 |
|
$id = $request->get('id'); |
|
182
|
2 |
|
$MailHistory = $app['eccube.repository.mail_history']->find($id); |
|
183
|
|
|
|
|
184
|
2 |
|
if (is_null($MailHistory)) { |
|
185
|
|
|
throw new NotFoundHttpException('history not found.'); |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
2 |
|
$event = new EventArgs( |
|
189
|
|
|
array( |
|
190
|
2 |
|
'MailHistory' => $MailHistory, |
|
191
|
|
|
), |
|
192
|
|
|
$request |
|
193
|
|
|
); |
|
194
|
2 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_MAIL_VIEW_COMPLETE, $event); |
|
195
|
|
|
|
|
196
|
2 |
|
return $app->render('Order/mail_view.twig', array( |
|
|
|
|
|
|
197
|
2 |
|
'subject' => $MailHistory->getSubject(), |
|
198
|
2 |
|
'body' => $MailHistory->getMailBody() |
|
199
|
|
|
)); |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
|
|
205
|
|
|
|
|
206
|
6 |
|
public function mailAll(Application $app, Request $request) |
|
|
|
|
|
|
207
|
|
|
{ |
|
208
|
|
|
|
|
209
|
6 |
|
$builder = $app['form.factory']->createBuilder(MailType::class); |
|
210
|
|
|
|
|
211
|
6 |
|
$event = new EventArgs( |
|
212
|
|
|
array( |
|
213
|
6 |
|
'builder' => $builder, |
|
214
|
|
|
), |
|
215
|
|
|
$request |
|
216
|
|
|
); |
|
217
|
6 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_MAIL_MAIL_ALL_INITIALIZE, $event); |
|
218
|
|
|
|
|
219
|
6 |
|
$form = $builder->getForm(); |
|
220
|
|
|
|
|
221
|
6 |
|
$ids = ''; |
|
|
|
|
|
|
222
|
6 |
|
if ('POST' === $request->getMethod()) { |
|
|
|
|
|
|
223
|
|
|
|
|
224
|
4 |
|
$form->handleRequest($request); |
|
225
|
|
|
|
|
226
|
4 |
|
$mode = $request->get('mode'); |
|
227
|
|
|
|
|
228
|
4 |
|
$ids = $request->get('ids'); |
|
229
|
|
|
|
|
230
|
|
|
// テンプレート変更の場合は. バリデーション前に内容差し替え. |
|
231
|
4 |
|
if ($mode == 'change') { |
|
232
|
|
View Code Duplication |
if ($form->get('template')->isValid()) { |
|
|
|
|
|
|
233
|
|
|
/** @var $data \Eccube\Entity\MailTemplate */ |
|
234
|
|
|
$MailTemplate = $form->get('template')->getData(); |
|
235
|
|
|
$form = $builder->getForm(); |
|
236
|
|
|
|
|
237
|
|
|
$event = new EventArgs( |
|
238
|
|
|
array( |
|
239
|
|
|
'form' => $form, |
|
240
|
|
|
'MailTemplate' => $MailTemplate, |
|
241
|
|
|
), |
|
242
|
|
|
$request |
|
243
|
|
|
); |
|
244
|
|
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_MAIL_MAIL_ALL_CHANGE, $event); |
|
245
|
|
|
|
|
246
|
|
|
$form->get('template')->setData($MailTemplate); |
|
247
|
|
|
$form->get('subject')->setData($MailTemplate->getSubject()); |
|
248
|
|
|
$form->get('header')->setData($MailTemplate->getHeader()); |
|
249
|
|
|
$form->get('footer')->setData($MailTemplate->getFooter()); |
|
250
|
|
|
} |
|
251
|
4 |
|
} else if ($form->isValid()) { |
|
252
|
|
|
switch ($mode) { |
|
253
|
4 |
|
case 'confirm': |
|
254
|
|
|
// フォームをFreezeして再生成. |
|
255
|
|
|
|
|
256
|
2 |
|
$builder->setAttribute('freeze', true); |
|
257
|
2 |
|
$builder->setAttribute('freeze_display_text', true); |
|
258
|
|
|
|
|
259
|
2 |
|
$data = $form->getData(); |
|
260
|
|
|
|
|
261
|
2 |
|
$tmp = explode(',', $ids); |
|
262
|
|
|
|
|
263
|
2 |
|
$Order = $app['eccube.repository.order']->find($tmp[0]); |
|
264
|
|
|
|
|
265
|
2 |
|
if (is_null($Order)) { |
|
266
|
|
|
throw new NotFoundHttpException('order not found.'); |
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
2 |
|
$body = $this->createBody($app, $data['header'], $data['footer'], $Order); |
|
270
|
|
|
|
|
271
|
2 |
|
$MailTemplate = $form->get('template')->getData(); |
|
272
|
|
|
|
|
273
|
2 |
|
$form = $builder->getForm(); |
|
274
|
|
|
|
|
275
|
2 |
|
$event = new EventArgs( |
|
276
|
|
|
array( |
|
277
|
2 |
|
'form' => $form, |
|
278
|
2 |
|
'MailTemplate' => $MailTemplate, |
|
279
|
2 |
|
'Order' => $Order, |
|
280
|
|
|
), |
|
281
|
|
|
$request |
|
282
|
|
|
); |
|
283
|
2 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_MAIL_MAIL_ALL_CONFIRM, $event); |
|
284
|
|
|
|
|
285
|
2 |
|
$form->setData($data); |
|
286
|
2 |
|
$form->get('template')->setData($MailTemplate); |
|
287
|
|
|
|
|
288
|
2 |
|
return $app->render('Order/mail_all_confirm.twig', array( |
|
289
|
2 |
|
'form' => $form->createView(), |
|
290
|
2 |
|
'body' => $body, |
|
291
|
2 |
|
'ids' => $ids, |
|
292
|
|
|
)); |
|
293
|
|
|
break; |
|
|
|
|
|
|
294
|
|
|
|
|
295
|
2 |
|
case 'complete': |
|
|
|
|
|
|
296
|
|
|
|
|
297
|
2 |
|
$data = $form->getData(); |
|
298
|
|
|
|
|
299
|
2 |
|
$ids = explode(',', $ids); |
|
300
|
|
|
|
|
301
|
2 |
|
foreach ($ids as $value) { |
|
|
|
|
|
|
302
|
|
|
|
|
303
|
2 |
|
$Order = $app['eccube.repository.order']->find($value); |
|
304
|
|
|
|
|
305
|
2 |
|
$body = $this->createBody($app, $data['header'], $data['footer'], $Order); |
|
306
|
|
|
|
|
307
|
|
|
// メール送信 |
|
308
|
2 |
|
$app['eccube.service.mail']->sendAdminOrderMail($Order, $data); |
|
309
|
|
|
|
|
310
|
|
|
// 送信履歴を保存. |
|
311
|
2 |
|
$MailTemplate = $form->get('template')->getData(); |
|
312
|
2 |
|
$MailHistory = new MailHistory(); |
|
313
|
|
|
$MailHistory |
|
314
|
2 |
|
->setSubject($data['subject']) |
|
315
|
2 |
|
->setMailBody($body) |
|
316
|
2 |
|
->setMailTemplate($MailTemplate) |
|
317
|
2 |
|
->setSendDate(new \DateTime()) |
|
318
|
2 |
|
->setOrder($Order); |
|
319
|
2 |
|
$app['orm.em']->persist($MailHistory); |
|
320
|
|
|
} |
|
321
|
|
|
|
|
322
|
2 |
|
$app['orm.em']->flush($MailHistory); |
|
|
|
|
|
|
323
|
|
|
|
|
324
|
2 |
|
$event = new EventArgs( |
|
325
|
|
|
array( |
|
326
|
2 |
|
'form' => $form, |
|
327
|
2 |
|
'MailHistory' => $MailHistory, |
|
328
|
|
|
), |
|
329
|
|
|
$request |
|
330
|
|
|
); |
|
331
|
2 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_MAIL_MAIL_ALL_COMPLETE, $event); |
|
332
|
|
|
|
|
333
|
2 |
|
return $app->redirect($app->url('admin_order_mail_complete')); |
|
334
|
|
|
break; |
|
|
|
|
|
|
335
|
|
|
default: |
|
336
|
|
|
break; |
|
337
|
|
|
} |
|
338
|
|
|
} |
|
339
|
|
|
} else { |
|
340
|
|
|
$filter = function ($v) { |
|
341
|
|
|
return preg_match('/^ids\d+$/', $v); |
|
342
|
2 |
|
}; |
|
343
|
2 |
|
$map = function ($v) { |
|
344
|
|
|
return preg_replace('/[^\d+]/', '', $v); |
|
345
|
2 |
|
}; |
|
346
|
2 |
|
$keys = array_keys($request->query->all()); |
|
347
|
2 |
|
$idArray = array_map($map, array_filter($keys, $filter)); |
|
348
|
2 |
|
$ids = implode(',', $idArray); |
|
349
|
|
|
} |
|
350
|
|
|
|
|
351
|
2 |
|
return $app->render('Order/mail_all.twig', array( |
|
352
|
2 |
|
'form' => $form->createView(), |
|
353
|
2 |
|
'ids' => $ids, |
|
354
|
|
|
)); |
|
355
|
|
|
} |
|
356
|
|
|
|
|
357
|
|
|
|
|
358
|
8 |
|
private function createBody($app, $header, $footer, $Order) |
|
359
|
|
|
{ |
|
360
|
8 |
|
return $app->renderView('Mail/order.twig', array( |
|
361
|
8 |
|
'header' => $header, |
|
362
|
8 |
|
'footer' => $footer, |
|
363
|
8 |
|
'Order' => $Order, |
|
364
|
|
|
)); |
|
365
|
|
|
} |
|
366
|
|
|
} |
|
367
|
|
|
|