Skip to content

Commit 8b1152a

Browse files
committed
Merge remote-tracking branch 'magento-l3/ACP2E-127' into L3_PR_21-09-30
2 parents 000bec2 + c25feef commit 8b1152a

File tree

4 files changed

+106
-22
lines changed

4 files changed

+106
-22
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
* Generate unique Urls/links separated by store in \Magento\Email\Model\AbstractTemplate `getUrl` function.
12+
*
13+
* @param \Magento\Email\Model\AbstractTemplate $subject
14+
* @param \Magento\Store\Model\Store $store
15+
* @param string $route
16+
* @param array $params
17+
* @return array
18+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
19+
*/
20+
public function beforeGetUrl(
21+
\Magento\Email\Model\AbstractTemplate $subject,
22+
\Magento\Store\Model\Store $store,
23+
$route = '',
24+
$params = []
25+
) {
26+
/**
27+
* Pass extra parameter to distinguish stores urls for property \Magento\Email\Model\AbstractTemplate `getUrl`
28+
* in multi-store environment
29+
*/
30+
$params['_escape_params'] = $store->getCode();
31+
32+
return [$store, $route, $params];
33+
}
34+
}

app/code/Magento/Email/Model/Template/Filter.php

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Cms\Block\Block;
1212
use Magento\Framework\App\Area;
1313
use Magento\Framework\App\Config\ScopeConfigInterface;
14+
use Magento\Framework\App\ObjectManager;
1415
use Magento\Framework\App\State;
1516
use Magento\Framework\Css\PreProcessor\Adapter\CssInliner;
1617
use Magento\Framework\Escaper;
@@ -30,14 +31,13 @@
3031
use Magento\Framework\View\Element\AbstractBlock;
3132
use Magento\Framework\View\LayoutFactory;
3233
use Magento\Framework\View\LayoutInterface;
34+
use Magento\Store\Model\Information as StoreInformation;
3335
use Magento\Store\Model\ScopeInterface;
3436
use Magento\Store\Model\StoreManagerInterface;
3537
use Magento\Variable\Model\Source\Variables;
3638
use Magento\Variable\Model\Variable;
3739
use Magento\Variable\Model\VariableFactory;
3840
use Psr\Log\LoggerInterface;
39-
use Magento\Store\Model\Information as StoreInformation;
40-
use Magento\Framework\App\ObjectManager;
4141

4242
/**
4343
* Core Email Template Filter Model
@@ -61,45 +61,33 @@ class Filter extends Template
6161
const TRANS_DIRECTIVE_REGEX = '/^\s*([\'"])([^\1]*?)(?<!\\\)\1(\s.*)?$/si';
6262

6363
/**
64-
* Use absolute links flag
65-
*
6664
* @var bool
6765
*/
6866
protected $_useAbsoluteLinks = false;
6967

7068
/**
71-
* Whether to allow SID in store directive: NO
72-
*
7369
* @var bool
7470
* @deprecated SID is not being used as query parameter anymore.
7571
*/
7672
protected $_useSessionInUrl = false;
7773

7874
/**
79-
* Modifier Callbacks
80-
*
8175
* @var array
8276
* @deprecated 101.0.4 Use the new Directive Processor interfaces
8377
*/
8478
protected $_modifiers = ['nl2br' => ''];
8579

8680
/**
87-
* Whether template being filtered is child of another template
88-
*
8981
* @var bool
9082
*/
9183
private $isChildTemplate = false;
9284

9385
/**
94-
* List of CSS files to inline
95-
*
9686
* @var []
9787
*/
9888
private $inlineCssFiles = [];
9989

10090
/**
101-
* Store id
102-
*
10391
* @var int
10492
*/
10593
protected $_storeId;
@@ -153,22 +141,16 @@ class Filter extends Template
153141
protected $_layoutFactory;
154142

155143
/**
156-
* Setup callbacks for filters
157-
*
158144
* @var ScopeConfigInterface
159145
*/
160146
protected $_scopeConfig;
161147

162148
/**
163-
* Layout directive params
164-
*
165149
* @var array
166150
*/
167151
protected $_directiveParams;
168152

169153
/**
170-
* App state
171-
*
172154
* @var State
173155
*/
174156
protected $_appState;
@@ -591,6 +573,13 @@ public function storeDirective($construction)
591573
unset($params['url']);
592574
}
593575

576+
/**
577+
* Pass extra parameter to distinguish stores urls for property Magento\Framework\Url $cacheUrl
578+
* in multi-store environment
579+
*/
580+
$this->urlModel->setScope($this->_storeManager->getStore());
581+
$params['_escape_params'] = $this->_storeManager->getStore()->getCode();
582+
594583
return $this->urlModel->getUrl($path, $params);
595584
}
596585

@@ -854,8 +843,8 @@ public function configDirective($construction)
854843
if ($params['path'] == $this->storeInformation::XML_PATH_STORE_INFO_COUNTRY_CODE) {
855844
$configValue = $storeInformationObj->getData('country');
856845
} elseif ($params['path'] == $this->storeInformation::XML_PATH_STORE_INFO_REGION_CODE) {
857-
$configValue = $storeInformationObj->getData('region')?
858-
$storeInformationObj->getData('region'):
846+
$configValue = $storeInformationObj->getData('region') ?
847+
$storeInformationObj->getData('region') :
859848
$configValue;
860849
}
861850
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 Magento\Email\Model\AbstractTemplate;
13+
use PHPUnit\Framework\MockObject\MockObject;
14+
use PHPUnit\Framework\TestCase;
15+
16+
class GetUrlTest extends TestCase
17+
{
18+
/** @var Store|MockObject */
19+
private $storeMock;
20+
21+
/** @var GetUrl */
22+
private $plugin;
23+
24+
/**
25+
* @inheritdoc
26+
*/
27+
protected function setUp(): void
28+
{
29+
$this->storeMock = $this->createMock(Store::class);
30+
31+
$this->plugin = new GetUrl();
32+
}
33+
34+
/**
35+
* Test if unique store parameter passed in third argument (`$params`) of `beforeGetUrl` function.
36+
*
37+
* @return void
38+
*/
39+
public function testBeforeGetUrl(): void
40+
{
41+
$storeCode = 'second_store_view';
42+
$params['_escape_params'] = $storeCode;
43+
$route = '';
44+
45+
$abstractTemplateMock = $this->getMockBuilder(AbstractTemplate::class)
46+
->disableOriginalConstructor()
47+
->getMock();
48+
49+
$this->storeMock->expects($this->once())
50+
->method('getCode')
51+
->willReturn($storeCode);
52+
53+
$this->assertEquals(
54+
[$this->storeMock, $route, $params],
55+
$this->plugin->beforeGetUrl($abstractTemplateMock, $this->storeMock, $route, [])
56+
);
57+
}
58+
}

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)