Skip to content

Commit

Permalink
ENGCOM-9381: 33310 fix unsubscribe url in newsletter email template #…
Browse files Browse the repository at this point in the history
…33753

 - Merge Pull Request #33753 from SilinMykola/magento2:33310_unsubscribe_url_in_email
 - Merged commits:
   1. dfe2a28
   2. 31c5137
   3. 49d2e51
   4. b7139ed
   5. 4b42e83
   6. 990641b
   7. 17ab362
   8. 61e21b2
  • Loading branch information
magento-engcom-team committed Jan 14, 2022
2 parents f40c40b + 61e21b2 commit 9ceb1f0
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ protected function _toHtml()
if ($this->getRequest()->getParam('subscriber')) {
$vars['subscriber']->load($this->getRequest()->getParam('subscriber'));
}
$vars['subscriber_data']['unsubscription_link'] = $vars['subscriber'] ?
$vars['subscriber']->getUnsubscriptionLink() :
null;

$template->emulateDesign($this->getStoreId());
$templateProcessed = $this->_appState->emulateAreaCode(
Expand Down
27 changes: 16 additions & 11 deletions app/code/Magento/Newsletter/Model/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ class Queue extends \Magento\Framework\Model\AbstractModel implements TemplateTy
protected $_template;

/**
* Subscribers collection
* Subscriber collection
*
* @var \Magento\Newsletter\Model\ResourceModel\Subscriber\Collection
*/
protected $_subscribersCollection;

/**
* Save stores flag.
* Flag for Save Stores.
*
* @var boolean
*/
Expand All @@ -68,15 +68,15 @@ class Queue extends \Magento\Framework\Model\AbstractModel implements TemplateTy
*/
protected $_stores = [];

const STATUS_NEVER = 0;
public const STATUS_NEVER = 0;

const STATUS_SENDING = 1;
public const STATUS_SENDING = 1;

const STATUS_CANCEL = 2;
public const STATUS_CANCEL = 2;

const STATUS_SENT = 3;
public const STATUS_SENT = 3;

const STATUS_PAUSE = 4;
public const STATUS_PAUSE = 4;

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

/**
* Date
* Datetime
*
* @var \Magento\Framework\Stdlib\DateTime\DateTime
*/
protected $_date;

/**
* Problem factory
* Factory of Problem
*
* @var \Magento\Newsletter\Model\ProblemFactory
*/
protected $_problemFactory;

/**
* Template factory
* Factory of Template
*
* @var \Magento\Newsletter\Model\TemplateFactory
*/
Expand Down Expand Up @@ -259,7 +259,12 @@ public function sendPerSubscriber($count = 20)
$transport = $this->_transportBuilder->setTemplateOptions(
['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $item->getStoreId()]
)->setTemplateVars(
['subscriber' => $item]
[
'subscriber' => $item,
'subscriber_data' => [
'unsubscription_link' => $item->getUnsubscriptionLink()
]
]
)->setFrom(
['name' => $this->getNewsletterSenderName(), 'email' => $this->getNewsletterSenderEmail()]
)->addTo(
Expand Down
7 changes: 4 additions & 3 deletions app/code/Magento/Newsletter/Model/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Template extends \Magento\Email\Model\AbstractTemplate
* Mail object
*
* @deprecated 100.3.0 Unused property
*
* @var string
*/
protected $_mail;

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

/**
* Filter factory
* Factory of Filter class
*
* @var \Magento\Newsletter\Model\Template\FilterFactory
*/
Expand Down Expand Up @@ -224,7 +224,8 @@ public function getTemplateText()
'template_text',
__(
'Follow this link to unsubscribe <!-- This tag is for unsubscribe link -->' .
'<a href="{{var subscriber.getUnsubscriptionLink()}}">{{var subscriber.getUnsubscriptionLink()}}' .
'<a href="{{var subscriber_data.unsubscription_link}}">
{{var subscriber_data.unsubscription_link}}' .
'</a>'
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,14 @@ public function testToHtml()
->with(
Template::DEFAULT_DESIGN_AREA,
[$this->templateMock, 'getProcessedTemplate'],
[['subscriber' => null]]
[
[
'subscriber' => null,
'subscriber_data' => [
'unsubscription_link' => null
]
]
]
)
->willReturn('Processed Template');

Expand Down Expand Up @@ -141,7 +148,10 @@ public function testToHtmlForNewTemplate()
],
[
[
'subscriber' => null
'subscriber' => null,
'subscriber_data' => [
'unsubscription_link' => null
]
]
]
)
Expand All @@ -162,7 +172,9 @@ public function testToHtmlWithSubscriber()
$subscriber = $this->createMock(Subscriber::class);
$subscriber->expects($this->atLeastOnce())->method('load')->with(3)->willReturnSelf();
$this->subscriberFactoryMock->expects($this->atLeastOnce())->method('create')->willReturn($subscriber);

$subscriber->expects($this->exactly(2))
->method('getUnsubscriptionLink')
->willReturn('http://example.com/newsletter/subscriber/unsubscribe/');
$this->templateMock->expects($this->atLeastOnce())->method('emulateDesign')->with(1);
$this->templateMock->expects($this->atLeastOnce())->method('revertDesign');

Expand All @@ -175,7 +187,10 @@ public function testToHtmlWithSubscriber()
],
[
[
'subscriber' => $subscriber
'subscriber' => $subscriber,
'subscriber_data' => [
'unsubscription_link' => $subscriber->getUnsubscriptionLink()
]
]
]
)
Expand Down
7 changes: 6 additions & 1 deletion app/code/Magento/Newsletter/Test/Unit/Model/QueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ public function testSendPerSubscriber2()
->getMock();
$item = $this->getMockBuilder(Subscriber::class)
->disableOriginalConstructor()
->setMethods(['getStoreId', 'getSubscriberEmail', 'getSubscriberFullName', 'received'])
->setMethods(
['getStoreId', 'getSubscriberEmail', 'getSubscriberFullName', 'received', 'getUnsubscriptionLink']
)
->getMock();
$transport = $this->getMockForAbstractClass(TransportInterface::class);
$this->subscribersCollectionMock->expects($this->once())->method('getQueueJoinedFlag')->willReturn(false);
Expand All @@ -188,6 +190,9 @@ public function testSendPerSubscriber2()
$item->expects($this->once())->method('getStoreId')->willReturn('store_id');
$item->expects($this->once())->method('getSubscriberEmail')->willReturn('email');
$item->expects($this->once())->method('getSubscriberFullName')->willReturn('full_name');
$item->expects($this->once())
->method('getUnsubscriptionLink')
->willReturn('http://example.com/newsletter/subscriber/unsubscribe/');
$this->transportBuilderMock->expects($this->once())->method('setTemplateOptions')->willReturnSelf();
$this->transportBuilderMock->expects($this->once())->method('setTemplateVars')->willReturnSelf();
$this->transportBuilderMock->expects($this->once())->method('setFrom')->willReturnSelf();
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Newsletter/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Paused,Paused
"You selected an invalid queue.","You selected an invalid queue."
"We cannot mark as received subscriber.","We cannot mark as received subscriber."
"Duplicate template code","Duplicate template code"
"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>"
"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>"
"No such entity with %fieldName = %fieldValue","No such entity with %fieldName = %fieldValue"
"Choose Store View:","Choose Store View:"
"Newsletter Message Preview","Newsletter Message Preview"
Expand Down

0 comments on commit 9ceb1f0

Please sign in to comment.