Skip to content

Commit de871b6

Browse files
pradeep.rauthanpradeep.rauthan
authored andcommitted
ACP2E-127:Asynchronous order emails from non-default websites has default website logo URL - New Plugin introduce
1 parent 9a4cb39 commit de871b6

File tree

4 files changed

+95
-7
lines changed

4 files changed

+95
-7
lines changed

app/code/Magento/Email/Model/AbstractTemplate.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -771,13 +771,6 @@ public function getUrl(Store $store, $route = '', $params = [])
771771
if ($this->storeManager->getStore()->getId() != $store->getId()) {
772772
$params['_scope_to_url'] = true;
773773
}
774-
775-
/**
776-
* Pass extra parameter to distinguish stores urls for property Magento\Framework\Url $cacheUrl
777-
* in multi-store environment
778-
*/
779-
$params['_escape_params'] = $store->getCode();
780-
781774
return $url->getUrl($route, $params);
782775
}
783776
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Email\Model\Plugin;
7+
8+
class GetUrl
9+
{
10+
/**
11+
* A unique store parameter need to pass in \Magento\Email\Model\AbstractTemplate `getUrl` function
12+
* for separating links in email content for sales order email confirmation.
13+
*
14+
* @param \Magento\Email\Model\AbstractTemplate $subject
15+
* @param \Magento\Store\Model\Store $store
16+
* @param string $scope
17+
* @return array
18+
*/
19+
public function beforeGetUrl(
20+
\Magento\Email\Model\AbstractTemplate $subject,
21+
\Magento\Store\Model\Store $store,
22+
$route = '',
23+
$params = []
24+
) {
25+
/**
26+
* Pass extra parameter to distinguish stores urls for property \Magento\Email\Model\AbstractTemplate `getUrl`
27+
* in multi-store environment
28+
*/
29+
$params['_escape_params'] = $store->getCode();
30+
31+
return [$store, $route, $params];
32+
}
33+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Email\Test\Unit\Model\Plugin;
9+
10+
use Magento\Email\Model\Plugin\GetUrl;
11+
use Magento\Store\Model\Store;
12+
use PHPUnit\Framework\MockObject\MockObject;
13+
use PHPUnit\Framework\TestCase;
14+
15+
class GetUrlTest extends TestCase
16+
{
17+
/** @var Store|MockObject */
18+
private $storeMock;
19+
20+
/** @var GetUrl|Object */
21+
private $plugin;
22+
23+
/**
24+
* setUp
25+
*
26+
* @return void
27+
*/
28+
protected function setUp(): void
29+
{
30+
$this->storeMock = $this->createMock(Store::class);
31+
32+
$this->plugin = new GetUrl();
33+
}
34+
35+
/**
36+
* Test if unique store parameter passed in third argument `$params` of `beforeGetUrl` function.
37+
*
38+
* @return void
39+
*/
40+
public function testBeforeGetUrl(): void
41+
{
42+
$storeCode = 'second_store_view';
43+
$params['_escape_params'] = $storeCode;
44+
$route = '';
45+
46+
$abstractTemplateMock = $this->getMockBuilder(\Magento\Email\Model\AbstractTemplate::class)
47+
->disableOriginalConstructor()
48+
->getMock();
49+
50+
$this->storeMock->expects($this->once())
51+
->method('getCode')
52+
->willReturn($storeCode);
53+
54+
$this->assertEquals(
55+
[$this->storeMock, $route, $params],
56+
$this->plugin->beforeGetUrl($abstractTemplateMock, $this->storeMock, $route, [])
57+
);
58+
}
59+
}

app/code/Magento/Email/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@
6161
<plugin name="WindowsSmtpConfig" type="Magento\Email\Model\Plugin\WindowsSmtpConfig" />
6262
<plugin name="EmailDisable" type="Magento\Email\Model\Mail\TransportInterfacePlugin" />
6363
</type>
64+
<type name="Magento\Email\Model\AbstractTemplate">
65+
<plugin name="EmailTemplateLinkUrl" type="Magento\Email\Model\Plugin\GetUrl"/>
66+
</type>
6467
<type name="Magento\Config\Model\Config\TypePool">
6568
<arguments>
6669
<argument name="sensitive" xsi:type="array">

0 commit comments

Comments
 (0)