1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of EC-CUBE |
5
|
|
|
* |
6
|
|
|
* Copyright(c) LOCKON CO.,LTD. All Rights Reserved. |
7
|
|
|
* |
8
|
|
|
* http://www.lockon.co.jp/ |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Eccube\Service; |
15
|
|
|
|
16
|
|
|
use Eccube\Common\EccubeConfig; |
17
|
|
|
use Eccube\Entity\BaseInfo; |
18
|
|
|
use Eccube\Entity\Customer; |
19
|
|
|
use Eccube\Entity\MailHistory; |
20
|
|
|
use Eccube\Entity\MailTemplate; |
21
|
|
|
use Eccube\Entity\Order; |
22
|
|
|
use Eccube\Entity\OrderItem; |
23
|
|
|
use Eccube\Entity\Shipping; |
24
|
|
|
use Eccube\Event\EccubeEvents; |
25
|
|
|
use Eccube\Event\EventArgs; |
26
|
|
|
use Eccube\Repository\BaseInfoRepository; |
27
|
|
|
use Eccube\Repository\MailHistoryRepository; |
28
|
|
|
use Eccube\Repository\MailTemplateRepository; |
29
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher; |
30
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
31
|
|
|
|
32
|
|
|
class MailService |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* @var \Swift_Mailer |
36
|
|
|
*/ |
37
|
|
|
protected $mailer; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var MailTemplateRepository |
41
|
|
|
*/ |
42
|
|
|
protected $mailTemplateRepository; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var MailHistoryRepository |
46
|
|
|
*/ |
47
|
|
|
private $mailHistoryRepository; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var EventDispatcher |
51
|
|
|
*/ |
52
|
|
|
protected $eventDispatcher; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var BaseInfo |
56
|
|
|
*/ |
57
|
|
|
protected $BaseInfo; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var EccubeConfig |
61
|
|
|
*/ |
62
|
|
|
protected $eccubeConfig; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @var \Twig_Environment |
66
|
|
|
*/ |
67
|
|
|
protected $twig; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* MailService constructor. |
71
|
|
|
* |
72
|
|
|
* @param \Swift_Mailer $mailer |
73
|
|
|
* @param MailTemplateRepository $mailTemplateRepository |
74
|
|
|
* @param MailHistoryRepository $mailHistoryRepository |
75
|
|
|
* @param BaseInfoRepository $baseInfoRepository |
76
|
|
|
* @param EventDispatcherInterface $eventDispatcher |
77
|
|
|
* @param \Twig_Environment $twig |
78
|
|
|
* @param EccubeConfig $eccubeConfig |
79
|
|
|
*/ |
80
|
140 |
|
public function __construct( |
81
|
|
|
\Swift_Mailer $mailer, |
82
|
|
|
MailTemplateRepository $mailTemplateRepository, |
83
|
|
|
MailHistoryRepository $mailHistoryRepository, |
84
|
|
|
BaseInfoRepository $baseInfoRepository, |
85
|
|
|
EventDispatcherInterface $eventDispatcher, |
86
|
|
|
\Twig_Environment $twig, |
87
|
|
|
EccubeConfig $eccubeConfig |
88
|
|
|
) { |
89
|
140 |
|
$this->mailer = $mailer; |
90
|
140 |
|
$this->mailTemplateRepository = $mailTemplateRepository; |
91
|
140 |
|
$this->mailHistoryRepository = $mailHistoryRepository; |
92
|
140 |
|
$this->BaseInfo = $baseInfoRepository->get(); |
93
|
140 |
|
$this->eventDispatcher = $eventDispatcher; |
|
|
|
|
94
|
140 |
|
$this->eccubeConfig = $eccubeConfig; |
95
|
140 |
|
$this->twig = $twig; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Send customer confirm mail. |
100
|
|
|
* |
101
|
|
|
* @param $Customer 会員情報 |
102
|
|
|
* @param string $activateUrl アクティベート用url |
103
|
|
|
*/ |
104
|
2 |
View Code Duplication |
public function sendCustomerConfirmMail(\Eccube\Entity\Customer $Customer, $activateUrl) |
|
|
|
|
105
|
|
|
{ |
106
|
2 |
|
log_info('仮会員登録メール送信開始'); |
107
|
|
|
|
108
|
2 |
|
$MailTemplate = $this->mailTemplateRepository->find($this->eccubeConfig['eccube_entry_confirm_mail_template_id']); |
109
|
|
|
|
110
|
2 |
|
$body = $this->twig->render($MailTemplate->getFileName(), [ |
111
|
2 |
|
'Customer' => $Customer, |
112
|
2 |
|
'BaseInfo' => $this->BaseInfo, |
113
|
2 |
|
'activateUrl' => $activateUrl, |
114
|
2 |
|
]); |
115
|
2 |
|
|
116
|
|
|
$message = (new \Swift_Message()) |
117
|
|
|
->setSubject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject()) |
118
|
2 |
|
->setFrom([$this->BaseInfo->getEmail01() => $this->BaseInfo->getShopName()]) |
119
|
2 |
|
->setTo([$Customer->getEmail()]) |
120
|
2 |
|
->setBcc($this->BaseInfo->getEmail01()) |
121
|
2 |
|
->setReplyTo($this->BaseInfo->getEmail03()) |
122
|
2 |
|
->setReturnPath($this->BaseInfo->getEmail04()); |
123
|
2 |
|
|
124
|
2 |
|
// HTMLテンプレートが存在する場合 |
125
|
2 |
|
$htmlFileName = $this->getHtmlTemplate($MailTemplate->getFileName()); |
126
|
|
|
if (!is_null($htmlFileName)) { |
127
|
2 |
|
$htmlBody = $this->twig->render($htmlFileName, [ |
128
|
|
|
'Customer' => $Customer, |
129
|
2 |
|
'BaseInfo' => $this->BaseInfo, |
130
|
2 |
|
'activateUrl' => $activateUrl, |
131
|
2 |
|
]); |
132
|
2 |
|
|
133
|
|
|
$message |
134
|
2 |
|
->setContentType('text/plain; charset=UTF-8') |
135
|
|
|
->setBody($body, 'text/plain') |
136
|
2 |
|
->addPart($htmlBody, 'text/html'); |
137
|
|
|
} else { |
138
|
2 |
|
$message->setBody($body); |
139
|
|
|
} |
140
|
2 |
|
|
141
|
|
|
$event = new EventArgs( |
142
|
2 |
|
[ |
143
|
|
|
'message' => $message, |
144
|
|
|
'Customer' => $Customer, |
145
|
|
|
'BaseInfo' => $this->BaseInfo, |
146
|
|
|
'activateUrl' => $activateUrl, |
147
|
|
|
], |
148
|
|
|
null |
149
|
|
|
); |
150
|
2 |
|
$this->eventDispatcher->dispatch(EccubeEvents::MAIL_CUSTOMER_CONFIRM, $event); |
151
|
|
|
|
152
|
2 |
|
$count = $this->mailer->send($message, $failures); |
153
|
|
|
|
154
|
2 |
|
log_info('仮会員登録メール送信完了', ['count' => $count]); |
155
|
|
|
|
156
|
2 |
|
return $count; |
157
|
2 |
|
} |
158
|
2 |
|
|
159
|
2 |
|
/** |
160
|
2 |
|
* Send customer complete mail. |
161
|
|
|
* |
162
|
|
|
* @param $Customer 会員情報 |
163
|
2 |
|
*/ |
164
|
2 |
View Code Duplication |
public function sendCustomerCompleteMail(\Eccube\Entity\Customer $Customer) |
|
|
|
|
165
|
2 |
|
{ |
166
|
2 |
|
log_info('会員登録完了メール送信開始'); |
167
|
2 |
|
|
168
|
2 |
|
$MailTemplate = $this->mailTemplateRepository->find($this->eccubeConfig['eccube_entry_complete_mail_template_id']); |
169
|
2 |
|
|
170
|
2 |
|
$body = $this->twig->render($MailTemplate->getFileName(), [ |
171
|
|
|
'Customer' => $Customer, |
172
|
2 |
|
'BaseInfo' => $this->BaseInfo, |
173
|
|
|
]); |
174
|
2 |
|
|
175
|
2 |
|
$message = (new \Swift_Message()) |
176
|
2 |
|
->setSubject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject()) |
177
|
|
|
->setFrom([$this->BaseInfo->getEmail01() => $this->BaseInfo->getShopName()]) |
178
|
2 |
|
->setTo([$Customer->getEmail()]) |
179
|
|
|
->setBcc($this->BaseInfo->getEmail01()) |
180
|
2 |
|
->setReplyTo($this->BaseInfo->getEmail03()) |
181
|
|
|
->setReturnPath($this->BaseInfo->getEmail04()); |
182
|
2 |
|
|
183
|
|
|
// HTMLテンプレートが存在する場合 |
184
|
2 |
|
$htmlFileName = $this->getHtmlTemplate($MailTemplate->getFileName()); |
185
|
|
|
if (!is_null($htmlFileName)) { |
186
|
2 |
|
$htmlBody = $this->twig->render($htmlFileName, [ |
187
|
|
|
'Customer' => $Customer, |
188
|
|
|
'BaseInfo' => $this->BaseInfo, |
189
|
|
|
]); |
190
|
|
|
|
191
|
|
|
$message |
192
|
|
|
->setContentType('text/plain; charset=UTF-8') |
193
|
|
|
->setBody($body, 'text/plain') |
194
|
|
|
->addPart($htmlBody, 'text/html'); |
195
|
2 |
|
} else { |
196
|
|
|
$message->setBody($body); |
197
|
2 |
|
} |
198
|
|
|
|
199
|
2 |
|
$event = new EventArgs( |
200
|
|
|
[ |
201
|
2 |
|
'message' => $message, |
202
|
2 |
|
'Customer' => $Customer, |
203
|
2 |
|
'BaseInfo' => $this->BaseInfo, |
204
|
2 |
|
], |
205
|
2 |
|
null |
206
|
|
|
); |
207
|
|
|
$this->eventDispatcher->dispatch(EccubeEvents::MAIL_CUSTOMER_COMPLETE, $event); |
208
|
2 |
|
|
209
|
2 |
|
$count = $this->mailer->send($message); |
210
|
2 |
|
|
211
|
2 |
|
log_info('会員登録完了メール送信完了', ['count' => $count]); |
212
|
2 |
|
|
213
|
2 |
|
return $count; |
214
|
2 |
|
} |
215
|
2 |
|
|
216
|
|
|
/** |
217
|
2 |
|
* Send withdraw mail. |
218
|
|
|
* |
219
|
2 |
|
* @param $Customer Customer |
220
|
2 |
|
* @param $email string |
221
|
2 |
|
*/ |
222
|
2 |
View Code Duplication |
public function sendCustomerWithdrawMail(Customer $Customer, string $email) |
|
|
|
|
223
|
|
|
{ |
224
|
2 |
|
log_info('退会手続き完了メール送信開始'); |
225
|
|
|
|
226
|
2 |
|
$MailTemplate = $this->mailTemplateRepository->find($this->eccubeConfig['eccube_customer_withdraw_mail_template_id']); |
227
|
|
|
|
228
|
2 |
|
$body = $this->twig->render($MailTemplate->getFileName(), [ |
229
|
|
|
'Customer' => $Customer, |
230
|
2 |
|
'BaseInfo' => $this->BaseInfo, |
231
|
|
|
]); |
232
|
2 |
|
|
233
|
|
|
$message = (new \Swift_Message()) |
234
|
|
|
->setSubject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject()) |
235
|
|
|
->setFrom([$this->BaseInfo->getEmail01() => $this->BaseInfo->getShopName()]) |
236
|
|
|
->setTo([$email]) |
237
|
|
|
->setBcc($this->BaseInfo->getEmail01()) |
238
|
|
|
->setReplyTo($this->BaseInfo->getEmail03()) |
239
|
|
|
->setReturnPath($this->BaseInfo->getEmail04()); |
240
|
4 |
|
|
241
|
|
|
// HTMLテンプレートが存在する場合 |
242
|
4 |
|
$htmlFileName = $this->getHtmlTemplate($MailTemplate->getFileName()); |
243
|
|
|
if (!is_null($htmlFileName)) { |
244
|
4 |
|
$htmlBody = $this->twig->render($htmlFileName, [ |
245
|
|
|
'Customer' => $Customer, |
246
|
4 |
|
'BaseInfo' => $this->BaseInfo, |
247
|
4 |
|
]); |
248
|
4 |
|
|
249
|
4 |
|
$message |
250
|
4 |
|
->setContentType('text/plain; charset=UTF-8') |
251
|
|
|
->setBody($body, 'text/plain') |
252
|
|
|
->addPart($htmlBody, 'text/html'); |
253
|
|
|
} else { |
254
|
4 |
|
$message->setBody($body); |
255
|
4 |
|
} |
256
|
4 |
|
|
257
|
4 |
|
$event = new EventArgs( |
258
|
4 |
|
[ |
259
|
4 |
|
'message' => $message, |
260
|
4 |
|
'Customer' => $Customer, |
261
|
4 |
|
'BaseInfo' => $this->BaseInfo, |
262
|
|
|
'email' => $email, |
263
|
4 |
|
], |
264
|
|
|
null |
265
|
4 |
|
); |
266
|
4 |
|
$this->eventDispatcher->dispatch(EccubeEvents::MAIL_CUSTOMER_WITHDRAW, $event); |
267
|
4 |
|
|
268
|
|
|
$count = $this->mailer->send($message); |
269
|
4 |
|
|
270
|
|
|
log_info('退会手続き完了メール送信完了', ['count' => $count]); |
271
|
4 |
|
|
272
|
|
|
return $count; |
273
|
4 |
|
} |
274
|
|
|
|
275
|
4 |
|
/** |
276
|
|
|
* Send contact mail. |
277
|
4 |
|
* |
278
|
|
|
* @param $formData お問い合わせ内容 |
279
|
|
|
*/ |
280
|
|
View Code Duplication |
public function sendContactMail($formData) |
|
|
|
|
281
|
|
|
{ |
282
|
|
|
log_info('お問い合わせ受付メール送信開始'); |
283
|
|
|
|
284
|
|
|
$MailTemplate = $this->mailTemplateRepository->find($this->eccubeConfig['eccube_contact_mail_template_id']); |
285
|
|
|
|
286
|
|
|
$body = $this->twig->render($MailTemplate->getFileName(), [ |
287
|
|
|
'data' => $formData, |
288
|
|
|
'BaseInfo' => $this->BaseInfo, |
289
|
|
|
]); |
290
|
|
|
|
291
|
|
|
// 問い合わせ者にメール送信 |
292
|
|
|
$message = (new \Swift_Message()) |
293
|
|
|
->setSubject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject()) |
294
|
|
|
->setFrom([$this->BaseInfo->getEmail02() => $this->BaseInfo->getShopName()]) |
295
|
|
|
->setTo([$formData['email']]) |
296
|
|
|
->setBcc($this->BaseInfo->getEmail02()) |
297
|
|
|
->setReplyTo($this->BaseInfo->getEmail02()) |
298
|
|
|
->setReturnPath($this->BaseInfo->getEmail04()); |
299
|
|
|
|
300
|
|
|
// HTMLテンプレートが存在する場合 |
301
|
7 |
|
$htmlFileName = $this->getHtmlTemplate($MailTemplate->getFileName()); |
302
|
|
|
if (!is_null($htmlFileName)) { |
303
|
7 |
|
$htmlBody = $this->twig->render($htmlFileName, [ |
304
|
|
|
'data' => $formData, |
305
|
7 |
|
'BaseInfo' => $this->BaseInfo, |
306
|
|
|
]); |
307
|
7 |
|
|
308
|
7 |
|
$message |
309
|
7 |
|
->setContentType('text/plain; charset=UTF-8') |
310
|
7 |
|
->setBody($body, 'text/plain') |
311
|
|
|
->addPart($htmlBody, 'text/html'); |
312
|
|
|
} else { |
313
|
7 |
|
$message->setBody($body); |
314
|
7 |
|
} |
315
|
7 |
|
|
316
|
7 |
|
$event = new EventArgs( |
317
|
7 |
|
[ |
318
|
7 |
|
'message' => $message, |
319
|
7 |
|
'formData' => $formData, |
320
|
7 |
|
'BaseInfo' => $this->BaseInfo, |
321
|
|
|
], |
322
|
7 |
|
null |
323
|
|
|
); |
324
|
7 |
|
$this->eventDispatcher->dispatch(EccubeEvents::MAIL_CONTACT, $event); |
325
|
7 |
|
|
326
|
7 |
|
$count = $this->mailer->send($message); |
327
|
7 |
|
|
328
|
|
|
log_info('お問い合わせ受付メール送信完了', ['count' => $count]); |
329
|
7 |
|
|
330
|
|
|
return $count; |
331
|
7 |
|
} |
332
|
|
|
|
333
|
7 |
|
/** |
334
|
|
|
* Send order mail. |
335
|
7 |
|
* |
336
|
|
|
* @param \Eccube\Entity\Order $Order 受注情報 |
337
|
7 |
|
* |
338
|
|
|
* @return \Swift_Message |
339
|
|
|
*/ |
340
|
|
|
public function sendOrderMail(\Eccube\Entity\Order $Order) |
341
|
|
|
{ |
342
|
|
|
log_info('受注メール送信開始'); |
343
|
|
|
|
344
|
|
|
$MailTemplate = $this->mailTemplateRepository->find($this->eccubeConfig['eccube_order_mail_template_id']); |
345
|
|
|
|
346
|
2 |
|
$body = $this->twig->render($MailTemplate->getFileName(), [ |
347
|
|
|
'Order' => $Order, |
348
|
2 |
|
]); |
349
|
|
|
|
350
|
|
|
$message = (new \Swift_Message()) |
351
|
2 |
|
->setSubject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject()) |
352
|
|
|
->setFrom([$this->BaseInfo->getEmail01() => $this->BaseInfo->getShopName()]) |
353
|
2 |
|
->setTo([$Order->getEmail()]) |
354
|
2 |
|
->setBcc($this->BaseInfo->getEmail01()) |
355
|
2 |
|
->setReplyTo($this->BaseInfo->getEmail03()) |
356
|
2 |
|
->setReturnPath($this->BaseInfo->getEmail04()); |
357
|
2 |
|
|
358
|
2 |
|
// HTMLテンプレートが存在する場合 |
359
|
|
|
$htmlFileName = $this->getHtmlTemplate($MailTemplate->getFileName()); |
360
|
|
|
if (!is_null($htmlFileName)) { |
361
|
2 |
|
$htmlBody = $this->twig->render($htmlFileName, [ |
362
|
2 |
|
'Order' => $Order, |
363
|
2 |
|
]); |
364
|
2 |
|
|
365
|
2 |
|
$message |
366
|
2 |
|
->setContentType('text/plain; charset=UTF-8') |
367
|
2 |
|
->setBody($body, 'text/plain') |
368
|
2 |
|
->addPart($htmlBody, 'text/html'); |
369
|
|
|
} else { |
370
|
2 |
|
$message->setBody($body); |
371
|
|
|
} |
372
|
2 |
|
|
373
|
2 |
|
$event = new EventArgs( |
374
|
2 |
|
[ |
375
|
2 |
|
'message' => $message, |
376
|
|
|
'Order' => $Order, |
377
|
2 |
|
'MailTemplate' => $MailTemplate, |
378
|
|
|
'BaseInfo' => $this->BaseInfo, |
379
|
2 |
|
], |
380
|
|
|
null |
381
|
2 |
|
); |
382
|
|
|
$this->eventDispatcher->dispatch(EccubeEvents::MAIL_ORDER, $event); |
383
|
2 |
|
|
384
|
|
|
$count = $this->mailer->send($message); |
385
|
2 |
|
|
386
|
|
|
$MailHistory = new MailHistory(); |
387
|
|
|
$MailHistory->setMailSubject($message->getSubject()) |
388
|
|
|
->setMailBody($message->getBody()) |
389
|
|
|
->setOrder($Order) |
390
|
|
|
->setSendDate(new \DateTime()); |
391
|
|
|
|
392
|
|
|
// HTML用メールの設定 |
393
|
|
|
$multipart = $message->getChildren(); |
394
|
|
|
if (count($multipart) > 0) { |
395
|
|
|
$MailHistory->setMailHtmlBody($multipart[0]->getBody()); |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
$this->mailHistoryRepository->save($MailHistory); |
399
|
|
|
|
400
|
|
|
log_info('受注メール送信完了', ['count' => $count]); |
401
|
3 |
|
|
402
|
|
|
return $message; |
403
|
3 |
|
} |
404
|
|
|
|
405
|
3 |
|
/** |
406
|
3 |
|
* Send admin customer confirm mail. |
407
|
3 |
|
* |
408
|
3 |
|
* @param $Customer 会員情報 |
409
|
|
|
* @param string $activateUrl アクティベート用url |
410
|
|
|
*/ |
411
|
3 |
View Code Duplication |
public function sendAdminCustomerConfirmMail(\Eccube\Entity\Customer $Customer, $activateUrl) |
|
|
|
|
412
|
3 |
|
{ |
413
|
3 |
|
log_info('仮会員登録再送メール送信開始'); |
414
|
3 |
|
|
415
|
3 |
|
/* @var $MailTemplate \Eccube\Entity\MailTemplate */ |
416
|
3 |
|
$MailTemplate = $this->mailTemplateRepository->find($this->eccubeConfig['eccube_entry_confirm_mail_template_id']); |
417
|
3 |
|
|
418
|
3 |
|
$body = $this->twig->render($MailTemplate->getFileName(), [ |
419
|
|
|
'BaseInfo' => $this->BaseInfo, |
420
|
3 |
|
'Customer' => $Customer, |
421
|
|
|
'activateUrl' => $activateUrl, |
422
|
3 |
|
]); |
423
|
3 |
|
|
424
|
3 |
|
$message = (new \Swift_Message()) |
425
|
3 |
|
->setSubject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject()) |
426
|
|
|
->setFrom([$this->BaseInfo->getEmail03() => $this->BaseInfo->getShopName()]) |
427
|
3 |
|
->setTo([$Customer->getEmail()]) |
428
|
|
|
->setBcc($this->BaseInfo->getEmail01()) |
429
|
3 |
|
->setReplyTo($this->BaseInfo->getEmail03()) |
430
|
|
|
->setReturnPath($this->BaseInfo->getEmail04()); |
431
|
3 |
|
|
432
|
|
|
// HTMLテンプレートが存在する場合 |
433
|
3 |
|
$htmlFileName = $this->getHtmlTemplate($MailTemplate->getFileName()); |
434
|
|
|
if (!is_null($htmlFileName)) { |
435
|
3 |
|
$htmlBody = $this->twig->render($htmlFileName, [ |
436
|
|
|
'BaseInfo' => $this->BaseInfo, |
437
|
|
|
'Customer' => $Customer, |
438
|
|
|
'activateUrl' => $activateUrl, |
439
|
|
|
]); |
440
|
|
|
|
441
|
|
|
$message |
442
|
|
|
->setContentType('text/plain; charset=UTF-8') |
443
|
|
|
->setBody($body, 'text/plain') |
444
|
1 |
|
->addPart($htmlBody, 'text/html'); |
445
|
|
|
} else { |
446
|
1 |
|
$message->setBody($body); |
447
|
|
|
} |
448
|
1 |
|
|
449
|
1 |
|
$event = new EventArgs( |
450
|
1 |
|
[ |
451
|
1 |
|
'message' => $message, |
452
|
1 |
|
'Customer' => $Customer, |
453
|
1 |
|
'BaseInfo' => $this->BaseInfo, |
454
|
1 |
|
'activateUrl' => $activateUrl, |
455
|
1 |
|
], |
456
|
|
|
null |
457
|
|
|
); |
458
|
1 |
|
$this->eventDispatcher->dispatch(EccubeEvents::MAIL_ADMIN_CUSTOMER_CONFIRM, $event); |
459
|
1 |
|
|
460
|
1 |
|
$count = $this->mailer->send($message); |
461
|
1 |
|
|
462
|
1 |
|
log_info('仮会員登録再送メール送信完了', ['count' => $count]); |
463
|
1 |
|
|
464
|
1 |
|
return $count; |
465
|
1 |
|
} |
466
|
|
|
|
467
|
1 |
|
/** |
468
|
|
|
* Send admin order mail. |
469
|
1 |
|
* |
470
|
1 |
|
* @param Order $Order 受注情報 |
471
|
1 |
|
* @param $formData 入力内容 |
472
|
1 |
|
* |
473
|
|
|
* @return \Swift_Message |
474
|
1 |
|
* |
475
|
|
|
* @throws \Twig_Error_Loader |
476
|
1 |
|
* @throws \Twig_Error_Runtime |
477
|
|
|
* @throws \Twig_Error_Syntax |
478
|
1 |
|
*/ |
479
|
|
|
public function sendAdminOrderMail(Order $Order, $formData) |
480
|
1 |
|
{ |
481
|
|
|
log_info('受注管理通知メール送信開始'); |
482
|
1 |
|
|
483
|
|
|
$message = (new \Swift_Message()) |
484
|
|
|
->setSubject('['.$this->BaseInfo->getShopName().'] '.$formData['mail_subject']) |
485
|
|
|
->setFrom([$this->BaseInfo->getEmail01() => $this->BaseInfo->getShopName()]) |
486
|
|
|
->setTo([$Order->getEmail()]) |
487
|
|
|
->setBcc($this->BaseInfo->getEmail01()) |
488
|
|
|
->setReplyTo($this->BaseInfo->getEmail03()) |
489
|
|
|
->setReturnPath($this->BaseInfo->getEmail04()) |
490
|
|
|
->setBody($formData['tpl_data']); |
491
|
1 |
|
|
492
|
|
|
$event = new EventArgs( |
493
|
1 |
|
[ |
494
|
|
|
'message' => $message, |
495
|
1 |
|
'Order' => $Order, |
496
|
|
|
'formData' => $formData, |
497
|
1 |
|
'BaseInfo' => $this->BaseInfo, |
498
|
1 |
|
], |
499
|
1 |
|
null |
500
|
1 |
|
); |
501
|
1 |
|
$this->eventDispatcher->dispatch(EccubeEvents::MAIL_ADMIN_ORDER, $event); |
502
|
1 |
|
|
503
|
|
|
$count = $this->mailer->send($message); |
504
|
|
|
|
505
|
1 |
|
log_info('受注管理通知メール送信完了', ['count' => $count]); |
506
|
1 |
|
|
507
|
1 |
|
return $message; |
508
|
1 |
|
} |
509
|
1 |
|
|
510
|
1 |
|
/** |
511
|
1 |
|
* Send password reset notification mail. |
512
|
1 |
|
* |
513
|
|
|
* @param $Customer 会員情報 |
514
|
1 |
|
* @param string $reset_url |
515
|
|
|
*/ |
516
|
1 |
|
public function sendPasswordResetNotificationMail(\Eccube\Entity\Customer $Customer, $reset_url) |
517
|
1 |
|
{ |
518
|
1 |
|
log_info('パスワード再発行メール送信開始'); |
519
|
1 |
|
|
520
|
|
|
$MailTemplate = $this->mailTemplateRepository->find($this->eccubeConfig['eccube_forgot_mail_template_id']); |
521
|
1 |
|
$body = $this->twig->render($MailTemplate->getFileName(), [ |
522
|
|
|
'BaseInfo' => $this->BaseInfo, |
523
|
1 |
|
'Customer' => $Customer, |
524
|
|
|
'expire' => $this->eccubeConfig['eccube_customer_reset_expire'], |
525
|
1 |
|
'reset_url' => $reset_url, |
526
|
|
|
]); |
527
|
1 |
|
|
528
|
|
|
$message = (new \Swift_Message()) |
529
|
1 |
|
->setSubject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject()) |
530
|
|
|
->setFrom([$this->BaseInfo->getEmail01() => $this->BaseInfo->getShopName()]) |
531
|
|
|
->setTo([$Customer->getEmail()]) |
532
|
|
|
->setReplyTo($this->BaseInfo->getEmail03()) |
533
|
|
|
->setReturnPath($this->BaseInfo->getEmail04()); |
534
|
|
|
|
535
|
|
|
// HTMLテンプレートが存在する場合 |
536
|
|
|
$htmlFileName = $this->getHtmlTemplate($MailTemplate->getFileName()); |
537
|
|
|
if (!is_null($htmlFileName)) { |
538
|
|
|
$htmlBody = $this->twig->render($htmlFileName, [ |
539
|
|
|
'BaseInfo' => $this->BaseInfo, |
540
|
|
|
'Customer' => $Customer, |
541
|
|
|
'expire' => $this->eccubeConfig['eccube_customer_reset_expire'], |
542
|
|
|
'reset_url' => $reset_url, |
543
|
|
|
]); |
544
|
|
|
|
545
|
|
|
$message |
546
|
|
|
->setContentType('text/plain; charset=UTF-8') |
547
|
|
|
->setBody($body, 'text/plain') |
548
|
|
|
->addPart($htmlBody, 'text/html'); |
549
|
|
|
} else { |
550
|
|
|
$message->setBody($body); |
551
|
|
|
} |
552
|
|
|
|
553
|
|
|
$event = new EventArgs( |
554
|
|
|
[ |
555
|
|
|
'message' => $message, |
556
|
|
|
'Customer' => $Customer, |
557
|
|
|
'BaseInfo' => $this->BaseInfo, |
558
|
|
|
'resetUrl' => $reset_url, |
559
|
|
|
], |
560
|
|
|
null |
561
|
|
|
); |
562
|
|
|
$this->eventDispatcher->dispatch(EccubeEvents::MAIL_PASSWORD_RESET, $event); |
563
|
|
|
|
564
|
|
|
$count = $this->mailer->send($message); |
565
|
|
|
|
566
|
|
|
log_info('パスワード再発行メール送信完了', ['count' => $count]); |
567
|
4 |
|
|
568
|
|
|
return $count; |
569
|
4 |
|
} |
570
|
|
|
|
571
|
4 |
|
/** |
572
|
|
|
* Send password reset notification mail. |
573
|
|
|
* |
574
|
4 |
|
* @param $Customer 会員情報 |
575
|
4 |
|
* @param string $password |
576
|
4 |
|
*/ |
577
|
4 |
View Code Duplication |
public function sendPasswordResetCompleteMail(\Eccube\Entity\Customer $Customer, $password) |
|
|
|
|
578
|
4 |
|
{ |
579
|
4 |
|
log_info('パスワード変更完了メール送信開始'); |
580
|
4 |
|
|
581
|
4 |
|
$MailTemplate = $this->mailTemplateRepository->find($this->eccubeConfig['eccube_reset_complete_mail_template_id']); |
582
|
4 |
|
|
583
|
|
|
$body = $this->twig->render($MailTemplate->getFileName(), [ |
584
|
4 |
|
'BaseInfo' => $this->BaseInfo, |
585
|
|
|
'Customer' => $Customer, |
586
|
4 |
|
'password' => $password, |
587
|
4 |
|
]); |
588
|
4 |
|
|
589
|
4 |
|
$message = (new \Swift_Message()) |
590
|
4 |
|
->setSubject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject()) |
591
|
|
|
->setFrom([$this->BaseInfo->getEmail01() => $this->BaseInfo->getShopName()]) |
592
|
4 |
|
->setTo([$Customer->getEmail()]) |
593
|
|
|
->setBcc($this->BaseInfo->getEmail01()) |
594
|
4 |
|
->setReplyTo($this->BaseInfo->getEmail03()) |
595
|
|
|
->setReturnPath($this->BaseInfo->getEmail04()); |
596
|
|
|
|
597
|
|
|
// HTMLテンプレートが存在する場合 |
598
|
|
|
$htmlFileName = $this->getHtmlTemplate($MailTemplate->getFileName()); |
599
|
|
|
if (!is_null($htmlFileName)) { |
600
|
|
|
$htmlBody = $this->twig->render($htmlFileName, [ |
601
|
|
|
'BaseInfo' => $this->BaseInfo, |
602
|
|
|
'Customer' => $Customer, |
603
|
|
|
'password' => $password, |
604
|
|
|
]); |
605
|
|
|
|
606
|
|
|
$message |
607
|
|
|
->setContentType('text/plain; charset=UTF-8') |
608
|
4 |
|
->setBody($body, 'text/plain') |
609
|
4 |
|
->addPart($htmlBody, 'text/html'); |
610
|
4 |
|
} else { |
611
|
|
|
$message->setBody($body); |
612
|
|
|
} |
613
|
4 |
|
|
614
|
|
|
$event = new EventArgs( |
615
|
4 |
|
[ |
616
|
4 |
|
'message' => $message, |
617
|
4 |
|
'Customer' => $Customer, |
618
|
4 |
|
'BaseInfo' => $this->BaseInfo, |
619
|
4 |
|
'password' => $password, |
620
|
|
|
], |
621
|
|
|
null |
622
|
|
|
); |
623
|
|
|
$this->eventDispatcher->dispatch(EccubeEvents::MAIL_PASSWORD_RESET_COMPLETE, $event); |
624
|
|
|
|
625
|
|
|
$count = $this->mailer->send($message); |
626
|
|
|
|
627
|
|
|
log_info('パスワード変更完了メール送信完了', ['count' => $count]); |
628
|
|
|
|
629
|
|
|
return $count; |
630
|
|
|
} |
631
|
|
|
|
632
|
|
|
/** |
633
|
|
|
* ポイントでマイナス発生時にメール通知する。 |
634
|
|
|
* |
635
|
|
|
* @param Order $Order |
636
|
|
|
* @param int $currentPoint |
637
|
|
|
* @param int $changePoint |
638
|
|
|
*/ |
639
|
|
|
public function sendPointNotifyMail(\Eccube\Entity\Order $Order, $currentPoint = 0, $changePoint = 0) |
640
|
|
|
{ |
641
|
|
|
$body = $this->twig->render('Mail/point_notify.twig', [ |
642
|
|
|
'Order' => $Order, |
643
|
|
|
'currentPoint' => $currentPoint, |
644
|
|
|
'changePoint' => $changePoint, |
645
|
|
|
]); |
646
|
|
|
|
647
|
|
|
$message = (new \Swift_Message()) |
648
|
|
|
->setSubject('['.$this->BaseInfo->getShopName().'] ポイント通知') |
649
|
|
|
->setFrom([$this->BaseInfo->getEmail01() => $this->BaseInfo->getShopName()]) |
650
|
|
|
->setTo([$this->BaseInfo->getEmail01()]) |
651
|
|
|
->setBcc($this->BaseInfo->getEmail01()) |
652
|
|
|
->setReplyTo($this->BaseInfo->getEmail03()) |
653
|
|
|
->setReturnPath($this->BaseInfo->getEmail04()); |
654
|
|
|
|
655
|
|
|
// HTMLテンプレートが存在する場合 |
656
|
|
|
$htmlFileName = $this->getHtmlTemplate('Mail/point_notify.twig'); |
657
|
|
|
if (!is_null($htmlFileName)) { |
658
|
|
|
$htmlBody = $this->twig->render($htmlFileName, [ |
659
|
|
|
'Order' => $Order, |
660
|
|
|
'currentPoint' => $currentPoint, |
661
|
|
|
'changePoint' => $changePoint, |
662
|
|
|
]); |
663
|
|
|
|
664
|
|
|
$message |
665
|
|
|
->setContentType('text/plain; charset=UTF-8') |
666
|
|
|
->setBody($body, 'text/plain') |
667
|
|
|
->addPart($htmlBody, 'text/html'); |
668
|
|
|
} else { |
669
|
|
|
$message->setBody($body); |
670
|
|
|
} |
671
|
|
|
|
672
|
|
|
$this->mailer->send($message); |
673
|
|
|
} |
674
|
|
|
|
675
|
|
|
/** |
676
|
|
|
* 発送通知メールを送信する. |
677
|
|
|
* 発送通知メールは受注ごとに送られる |
678
|
|
|
* |
679
|
|
|
* @param Shipping $Shipping |
680
|
|
|
* |
681
|
|
|
* @throws \Twig_Error |
682
|
|
|
*/ |
683
|
|
|
public function sendShippingNotifyMail(Shipping $Shipping) |
684
|
|
|
{ |
685
|
|
|
log_info('出荷通知メール送信処理開始', ['id' => $Shipping->getId()]); |
686
|
|
|
|
687
|
|
|
$MailTemplate = $this->mailTemplateRepository->find($this->eccubeConfig['eccube_shipping_notify_mail_template_id']); |
688
|
|
|
|
689
|
|
|
/** @var Order $Order */ |
690
|
|
|
$Order = $Shipping->getOrder(); |
691
|
|
|
$body = $this->getShippingNotifyMailBody($Shipping, $Order, $MailTemplate->getFileName()); |
692
|
|
|
|
693
|
|
|
$message = (new \Swift_Message()) |
694
|
|
|
->setSubject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject()) |
695
|
|
|
->setFrom([$this->BaseInfo->getEmail01() => $this->BaseInfo->getShopName()]) |
696
|
|
|
->setTo($Order->getEmail()) |
697
|
|
|
->setBcc($this->BaseInfo->getEmail01()) |
698
|
|
|
->setReplyTo($this->BaseInfo->getEmail03()) |
699
|
|
|
->setReturnPath($this->BaseInfo->getEmail04()); |
700
|
|
|
|
701
|
|
|
// HTMLテンプレートが存在する場合 |
702
|
|
|
$htmlFileName = $this->getHtmlTemplate($MailTemplate->getFileName()); |
703
|
|
|
if (!is_null($htmlFileName)) { |
704
|
|
|
$htmlBody = $this->getShippingNotifyMailBody($Shipping, $Order, $htmlFileName, true); |
705
|
|
|
|
706
|
|
|
$message |
707
|
|
|
->setContentType('text/plain; charset=UTF-8') |
708
|
|
|
->setBody($body, 'text/plain') |
709
|
|
|
->addPart($htmlBody, 'text/html'); |
710
|
|
|
} else { |
711
|
|
|
$message->setBody($body); |
712
|
|
|
} |
713
|
|
|
|
714
|
|
|
$this->mailer->send($message); |
715
|
|
|
|
716
|
|
|
$MailHistory = new MailHistory(); |
717
|
|
|
$MailHistory->setMailSubject($message->getSubject()) |
718
|
|
|
->setMailBody($message->getBody()) |
719
|
|
|
->setOrder($Order) |
720
|
|
|
->setSendDate(new \DateTime()); |
721
|
|
|
|
722
|
|
|
// HTML用メールの設定 |
723
|
|
|
$multipart = $message->getChildren(); |
724
|
|
|
if (count($multipart) > 0) { |
725
|
|
|
$MailHistory->setMailHtmlBody($multipart[0]->getBody()); |
726
|
|
|
} |
727
|
|
|
|
728
|
|
|
$this->mailHistoryRepository->save($MailHistory); |
729
|
|
|
|
730
|
|
|
log_info('出荷通知メール送信処理完了', ['id' => $Shipping->getId()]); |
731
|
|
|
} |
732
|
|
|
|
733
|
|
|
/** |
734
|
|
|
* @param Shipping $Shipping |
735
|
|
|
* @param Order $Order |
736
|
|
|
* @param string|null $templateName |
737
|
|
|
* @param boolean $is_html |
738
|
|
|
* |
739
|
|
|
* @return string |
740
|
|
|
* |
741
|
|
|
* @throws \Twig_Error |
742
|
|
|
*/ |
743
|
|
|
public function getShippingNotifyMailBody(Shipping $Shipping, Order $Order, $templateName = null, $is_html = false) |
744
|
|
|
{ |
745
|
|
|
$ShippingItems = array_filter($Shipping->getOrderItems()->toArray(), function (OrderItem $OrderItem) use ($Order) { |
746
|
|
|
return $OrderItem->getOrderId() === $Order->getId(); |
747
|
|
|
}); |
748
|
|
|
|
749
|
|
|
if (is_null($templateName)) { |
750
|
|
|
/** @var MailTemplate $MailTemplate */ |
751
|
|
|
$MailTemplate = $this->mailTemplateRepository->find($this->eccubeConfig['eccube_shipping_notify_mail_template_id']); |
752
|
|
|
$fileName = $MailTemplate->getFileName(); |
753
|
|
|
} else { |
754
|
|
|
$fileName = $templateName; |
755
|
|
|
} |
756
|
|
|
|
757
|
|
|
if ($is_html) { |
758
|
|
|
$htmlFileName = $this->getHtmlTemplate($fileName); |
759
|
|
|
$fileName = !is_null($htmlFileName) ? $htmlFileName : $fileName; |
760
|
|
|
} |
761
|
|
|
|
762
|
|
|
return $this->twig->render($fileName, [ |
763
|
|
|
'Shipping' => $Shipping, |
764
|
|
|
'ShippingItems' => $ShippingItems, |
765
|
|
|
]); |
766
|
|
|
} |
767
|
|
|
|
768
|
|
|
/** |
769
|
|
|
* [getHtmlTemplate description] |
770
|
|
|
* |
771
|
|
|
* @param string $templateName プレーンテキストメールのファイル名 |
772
|
|
|
* |
773
|
|
|
* @return string|null 存在する場合はファイル名を返す |
774
|
|
|
*/ |
775
|
|
|
public function getHtmlTemplate($templateName) |
776
|
|
|
{ |
777
|
|
|
// メールテンプレート名からHTMLメール用テンプレート名を生成 |
778
|
|
|
$fileName = explode('.', $templateName); |
779
|
|
|
$suffix = '.html'; |
780
|
|
|
$htmlFileName = $fileName[0].$suffix.'.'.$fileName[1]; |
781
|
|
|
|
782
|
|
|
// HTMLメール用テンプレートの存在チェック |
783
|
|
|
if ($this->twig->getLoader()->exists($htmlFileName)) { |
784
|
|
|
return $htmlFileName; |
785
|
|
|
} else { |
786
|
|
|
return null; |
787
|
|
|
} |
788
|
|
|
} |
789
|
|
|
} |
790
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.