forked from Hevelop/magento2-patches
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Patch-Magento-Framework-MSI-Email-Issue.patch
147 lines (137 loc) · 4.87 KB
/
Patch-Magento-Framework-MSI-Email-Issue.patch
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
diff --git a/Mail/Message.php b/Mail/Message.php
index 6f156e42dfdb..bc7193f107bb 100644
--- a/Mail/Message.php
+++ b/Mail/Message.php
@@ -89,10 +89,23 @@ public function getBody()
/**
* {@inheritdoc}
+ *
+ * @deprecated This function is missing the from name. The
+ * setFromAddress() function sets both from address and from name.
+ * @see setFromAddress()
*/
public function setFrom($fromAddress)
{
- $this->zendMessage->setFrom($fromAddress);
+ $this->setFromAddress($fromAddress, null);
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setFromAddress($fromAddress, $fromName = null)
+ {
+ $this->zendMessage->setFrom($fromAddress, $fromName);
return $this;
}
diff --git a/Mail/Template/TransportBuilder.php b/Mail/Template/TransportBuilder.php
index eac5d74c6e3d..a7bb96122a84 100644
--- a/Mail/Template/TransportBuilder.php
+++ b/Mail/Template/TransportBuilder.php
@@ -17,6 +17,8 @@
use Magento\Framework\Phrase;
/**
+ * TransportBuilder
+ *
* @api
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
@@ -175,13 +177,30 @@ public function setReplyTo($email, $name = null)
/**
* Set mail from address
*
+ * @deprecated This function sets the from address for the first store only.
+ * new function setFromByStore introduced to allow setting of from address
+ * based on store.
+ * @see setFromByStore()
+ *
* @param string|array $from
* @return $this
*/
public function setFrom($from)
{
- $result = $this->_senderResolver->resolve($from);
- $this->message->setFrom($result['email'], $result['name']);
+ return $this->setFromByStore($from, null);
+ }
+
+ /**
+ * Set mail from address by store
+ *
+ * @param string|array $from
+ * @param string|int $store
+ * @return $this
+ */
+ public function setFromByStore($from, $store = null)
+ {
+ $result = $this->_senderResolver->resolve($from, $store);
+ $this->message->setFromAddress($result['email'], $result['name']);
return $this;
}
diff --git a/Mail/Template/TransportBuilderByStore.php b/Mail/Template/TransportBuilderByStore.php
index 785c93824a57..85b1b181d4f9 100644
--- a/Mail/Template/TransportBuilderByStore.php
+++ b/Mail/Template/TransportBuilderByStore.php
@@ -8,6 +8,13 @@
use Magento\Framework\Mail\MessageInterface;
+/**
+ * Class TransportBuilderByStore
+ *
+ * @deprecated The ability to set From address based on store is now available
+ * in the \Magento\Framework\Mail\Template\TransportBuilder class
+ * @see \Magento\Framework\Mail\Template\TransportBuilder::setFromByStore
+ */
class TransportBuilderByStore
{
/**
@@ -47,7 +54,7 @@ public function __construct(
public function setFromByStore($from, $store)
{
$result = $this->senderResolver->resolve($from, $store);
- $this->message->setFrom($result['email'], $result['name']);
+ $this->message->setFromAddress($result['email'], $result['name']);
return $this;
}
diff --git a/Mail/Test/Unit/Template/TransportBuilderByStoreTest.php b/Mail/Test/Unit/Template/TransportBuilderByStoreTest.php
index 80df2887a3a9..a28dbcd291ba 100644
--- a/Mail/Test/Unit/Template/TransportBuilderByStoreTest.php
+++ b/Mail/Test/Unit/Template/TransportBuilderByStoreTest.php
@@ -55,8 +55,8 @@ public function testSetFromByStore()
->with($sender, $store)
->willReturn($sender);
$this->messageMock->expects($this->once())
- ->method('setFrom')
- ->with('from@example.com', 'name')
+ ->method('setFromAddress')
+ ->with($sender['email'], $sender['name'])
->willReturnSelf();
$this->model->setFromByStore($sender, $store);
diff --git a/Mail/Test/Unit/Template/TransportBuilderTest.php b/Mail/Test/Unit/Template/TransportBuilderTest.php
index 596640480c82..b476eecd7f59 100644
--- a/Mail/Test/Unit/Template/TransportBuilderTest.php
+++ b/Mail/Test/Unit/Template/TransportBuilderTest.php
@@ -167,19 +167,20 @@ public function getTransportDataProvider()
/**
* @return void
*/
- public function testSetFrom()
+ public function testSetFromByStore()
{
$sender = ['email' => 'from@example.com', 'name' => 'name'];
+ $store = 1;
$this->senderResolverMock->expects($this->once())
->method('resolve')
- ->with($sender)
+ ->with($sender, $store)
->willReturn($sender);
$this->messageMock->expects($this->once())
- ->method('setFrom')
- ->with('from@example.com', 'name')
+ ->method('setFromAddress')
+ ->with($sender['email'], $sender['name'])
->willReturnSelf();
- $this->builder->setFrom($sender);
+ $this->builder->setFromByStore($sender, $store);
}
/**