-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfirmation.php
More file actions
86 lines (66 loc) · 1.99 KB
/
Confirmation.php
File metadata and controls
86 lines (66 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php namespace Octoshop\Checkout;
use Lang;
use Mail;
class Confirmation
{
protected $group;
protected $template;
protected $recipient;
protected $data = [];
public function forGroup($group)
{
if (!in_array($group, ['admin', 'customer'])) {
throw new ApplicationException(
sprintf(Lang::get('octoshop.checkout::lang.mail.invalid_group'), $group)
);
}
$this->group = $group;
$this->template = $group == 'admin'
? 'octoshop.checkout::mail.checkoutconfirm_admin'
: 'octoshop.checkout::mail.checkoutconfirm_customer';
return $this;
}
public function send()
{
return Mail::send(
$this->require('template'),
$data = $this->getData(),
function($message) use ($data) {
extract($data);
$customerName = $customer->name.' '.$customer->surname;
if ($this->group == 'admin') {
$message->to($email, $name);
$message->replyTo($customer->email, $customerName);
} else {
$message->to($customer->email, $customerName);
}
}
);
}
protected function getData()
{
$group = $this->require('group');
$data = $this->data['global'];
if (isset($this->data[$group])) {
$data = array_merge($data, $this->data[$group]);
}
return $data;
}
protected function require($var)
{
if (!$this->$var) {
throw new ApplicationException(
Lang::get('octoshop.checkout::lang.mail.missing_param')
);
}
return $this->$var;
}
public function with($group, array $data)
{
if (!array_key_exists($group, $this->data)) {
$this->data[$group] = [];
}
$this->data[$group] = array_merge($this->data[$group], $data);
return $this;
}
}