Skip to content

Commit 5392538

Browse files
authored
ENGCOM-9381: 33310 fix unsubscribe url in newsletter email template #33753
2 parents 1d1614b + 9ceb1f0 commit 5392538

File tree

6 files changed

+49
-20
lines changed

6 files changed

+49
-20
lines changed

app/code/Magento/Newsletter/Block/Adminhtml/Template/Preview.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ protected function _toHtml()
7575
if ($this->getRequest()->getParam('subscriber')) {
7676
$vars['subscriber']->load($this->getRequest()->getParam('subscriber'));
7777
}
78+
$vars['subscriber_data']['unsubscription_link'] = $vars['subscriber'] ?
79+
$vars['subscriber']->getUnsubscriptionLink() :
80+
null;
7881

7982
$template->emulateDesign($this->getStoreId());
8083
$templateProcessed = $this->_appState->emulateAreaCode(

app/code/Magento/Newsletter/Model/Queue.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ class Queue extends \Magento\Framework\Model\AbstractModel implements TemplateTy
4848
protected $_template;
4949

5050
/**
51-
* Subscribers collection
51+
* Subscriber collection
5252
*
5353
* @var \Magento\Newsletter\Model\ResourceModel\Subscriber\Collection
5454
*/
5555
protected $_subscribersCollection;
5656

5757
/**
58-
* Save stores flag.
58+
* Flag for Save Stores.
5959
*
6060
* @var boolean
6161
*/
@@ -68,15 +68,15 @@ class Queue extends \Magento\Framework\Model\AbstractModel implements TemplateTy
6868
*/
6969
protected $_stores = [];
7070

71-
const STATUS_NEVER = 0;
71+
public const STATUS_NEVER = 0;
7272

73-
const STATUS_SENDING = 1;
73+
public const STATUS_SENDING = 1;
7474

75-
const STATUS_CANCEL = 2;
75+
public const STATUS_CANCEL = 2;
7676

77-
const STATUS_SENT = 3;
77+
public const STATUS_SENT = 3;
7878

79-
const STATUS_PAUSE = 4;
79+
public const STATUS_PAUSE = 4;
8080

8181
/**
8282
* Filter for newsletter text
@@ -86,21 +86,21 @@ class Queue extends \Magento\Framework\Model\AbstractModel implements TemplateTy
8686
protected $_templateFilter;
8787

8888
/**
89-
* Date
89+
* Datetime
9090
*
9191
* @var \Magento\Framework\Stdlib\DateTime\DateTime
9292
*/
9393
protected $_date;
9494

9595
/**
96-
* Problem factory
96+
* Factory of Problem
9797
*
9898
* @var \Magento\Newsletter\Model\ProblemFactory
9999
*/
100100
protected $_problemFactory;
101101

102102
/**
103-
* Template factory
103+
* Factory of Template
104104
*
105105
* @var \Magento\Newsletter\Model\TemplateFactory
106106
*/
@@ -259,7 +259,12 @@ public function sendPerSubscriber($count = 20)
259259
$transport = $this->_transportBuilder->setTemplateOptions(
260260
['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $item->getStoreId()]
261261
)->setTemplateVars(
262-
['subscriber' => $item]
262+
[
263+
'subscriber' => $item,
264+
'subscriber_data' => [
265+
'unsubscription_link' => $item->getUnsubscriptionLink()
266+
]
267+
]
263268
)->setFrom(
264269
['name' => $this->getNewsletterSenderName(), 'email' => $this->getNewsletterSenderEmail()]
265270
)->addTo(

app/code/Magento/Newsletter/Model/Template.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Template extends \Magento\Email\Model\AbstractTemplate
4141
* Mail object
4242
*
4343
* @deprecated 100.3.0 Unused property
44-
*
44+
* @var string
4545
*/
4646
protected $_mail;
4747

@@ -60,7 +60,7 @@ class Template extends \Magento\Email\Model\AbstractTemplate
6060
protected $_request;
6161

6262
/**
63-
* Filter factory
63+
* Factory of Filter class
6464
*
6565
* @var \Magento\Newsletter\Model\Template\FilterFactory
6666
*/
@@ -224,7 +224,8 @@ public function getTemplateText()
224224
'template_text',
225225
__(
226226
'Follow this link to unsubscribe <!-- This tag is for unsubscribe link -->' .
227-
'<a href="{{var subscriber.getUnsubscriptionLink()}}">{{var subscriber.getUnsubscriptionLink()}}' .
227+
'<a href="{{var subscriber_data.unsubscription_link}}">
228+
{{var subscriber_data.unsubscription_link}}' .
228229
'</a>'
229230
)
230231
);

app/code/Magento/Newsletter/Test/Unit/Block/Adminhtml/Template/PreviewTest.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,14 @@ public function testToHtml()
100100
->with(
101101
Template::DEFAULT_DESIGN_AREA,
102102
[$this->templateMock, 'getProcessedTemplate'],
103-
[['subscriber' => null]]
103+
[
104+
[
105+
'subscriber' => null,
106+
'subscriber_data' => [
107+
'unsubscription_link' => null
108+
]
109+
]
110+
]
104111
)
105112
->willReturn('Processed Template');
106113

@@ -141,7 +148,10 @@ public function testToHtmlForNewTemplate()
141148
],
142149
[
143150
[
144-
'subscriber' => null
151+
'subscriber' => null,
152+
'subscriber_data' => [
153+
'unsubscription_link' => null
154+
]
145155
]
146156
]
147157
)
@@ -162,7 +172,9 @@ public function testToHtmlWithSubscriber()
162172
$subscriber = $this->createMock(Subscriber::class);
163173
$subscriber->expects($this->atLeastOnce())->method('load')->with(3)->willReturnSelf();
164174
$this->subscriberFactoryMock->expects($this->atLeastOnce())->method('create')->willReturn($subscriber);
165-
175+
$subscriber->expects($this->exactly(2))
176+
->method('getUnsubscriptionLink')
177+
->willReturn('http://example.com/newsletter/subscriber/unsubscribe/');
166178
$this->templateMock->expects($this->atLeastOnce())->method('emulateDesign')->with(1);
167179
$this->templateMock->expects($this->atLeastOnce())->method('revertDesign');
168180

@@ -175,7 +187,10 @@ public function testToHtmlWithSubscriber()
175187
],
176188
[
177189
[
178-
'subscriber' => $subscriber
190+
'subscriber' => $subscriber,
191+
'subscriber_data' => [
192+
'unsubscription_link' => $subscriber->getUnsubscriptionLink()
193+
]
179194
]
180195
]
181196
)

app/code/Magento/Newsletter/Test/Unit/Model/QueueTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ public function testSendPerSubscriber2()
169169
->getMock();
170170
$item = $this->getMockBuilder(Subscriber::class)
171171
->disableOriginalConstructor()
172-
->setMethods(['getStoreId', 'getSubscriberEmail', 'getSubscriberFullName', 'received'])
172+
->setMethods(
173+
['getStoreId', 'getSubscriberEmail', 'getSubscriberFullName', 'received', 'getUnsubscriptionLink']
174+
)
173175
->getMock();
174176
$transport = $this->getMockForAbstractClass(TransportInterface::class);
175177
$this->subscribersCollectionMock->expects($this->once())->method('getQueueJoinedFlag')->willReturn(false);
@@ -188,6 +190,9 @@ public function testSendPerSubscriber2()
188190
$item->expects($this->once())->method('getStoreId')->willReturn('store_id');
189191
$item->expects($this->once())->method('getSubscriberEmail')->willReturn('email');
190192
$item->expects($this->once())->method('getSubscriberFullName')->willReturn('full_name');
193+
$item->expects($this->once())
194+
->method('getUnsubscriptionLink')
195+
->willReturn('http://example.com/newsletter/subscriber/unsubscribe/');
191196
$this->transportBuilderMock->expects($this->once())->method('setTemplateOptions')->willReturnSelf();
192197
$this->transportBuilderMock->expects($this->once())->method('setTemplateVars')->willReturnSelf();
193198
$this->transportBuilderMock->expects($this->once())->method('setFrom')->willReturnSelf();

app/code/Magento/Newsletter/i18n/en_US.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Paused,Paused
9191
"You selected an invalid queue.","You selected an invalid queue."
9292
"We cannot mark as received subscriber.","We cannot mark as received subscriber."
9393
"Duplicate template code","Duplicate template code"
94-
"Follow this link to unsubscribe <!-- This tag is for unsubscribe link --><a href=""{{var subscriber.getUnsubscriptionLink()}}"">{{var subscriber.getUnsubscriptionLink()}}</a>","Follow this link to unsubscribe <!-- This tag is for unsubscribe link --><a href=""{{var subscriber.getUnsubscriptionLink()}}"">{{var subscriber.getUnsubscriptionLink()}}</a>"
94+
"Follow this link to unsubscribe <!-- This tag is for unsubscribe link --><a href=""{{var subscriber_data.unsubscription_link}}"">{{var subscriber_data.unsubscription_link}}</a>","Follow this link to unsubscribe <!-- This tag is for unsubscribe link --><a href=""{{var subscriber_data.unsubscription_link}}"">{{var subscriber_data.unsubscription_link}}</a>"
9595
"No such entity with %fieldName = %fieldValue","No such entity with %fieldName = %fieldValue"
9696
"Choose Store View:","Choose Store View:"
9797
"Newsletter Message Preview","Newsletter Message Preview"

0 commit comments

Comments
 (0)