Skip to content

Commit b7139ed

Browse files
committed
ISSUE-33310 Fix the code to appear unsubscribe link in newsletter template
1 parent 49d2e51 commit b7139ed

File tree

5 files changed

+31
-10
lines changed

5 files changed

+31
-10
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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ 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}}">{{var subscriber_data.unsubscription_link}}' .
228228
'</a>'
229229
)
230230
);

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
)

lib/internal/Magento/Framework/Filter/VariableResolver/StrictResolver.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,8 @@ private function handleGetterMethod(int $i, Template $filter, array $templateVar
115115
...$stackArgs[$i]['args']
116116
);
117117
} else {
118-
$stackArgs[$i]['variable'] = call_user_func_array(
119-
[$stackArgs[$i - 1]['variable'], $stackArgs[$i]['name']],
120-
$stackArgs[$i]['args']
121-
);
118+
$dataKey = $this->extractDataKeyFromGetter($stackArgs[$i]['name']);
119+
$stackArgs[$i]['variable'] = $stackArgs[$i - 1]['variable']->getData($dataKey);
122120
}
123121
}
124122

0 commit comments

Comments
 (0)