Skip to content

Commit 4cce3c3

Browse files
AC-2391: Remove legacy variable resolver from email template processor
1 parent 0a05f9b commit 4cce3c3

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
use Magento\Store\Model\Store;
9+
10+
class StoreAddress
11+
{
12+
/**
13+
* Make formatted store address accessible for templates
14+
*
15+
* @param Store $subject
16+
* @param string $key
17+
* @param string|int $index
18+
* @return null
19+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
20+
*/
21+
public function beforeGetData(Store $subject, $key = '', $index = null)
22+
{
23+
if ($key === 'formatted_address') {
24+
$subject->setData('formatted_address', $subject->getFormattedAddress());
25+
}
26+
27+
return null;
28+
}
29+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,7 @@
9393
</argument>
9494
</arguments>
9595
</type>
96+
<type name="Magento\Store\Model\Store">
97+
<plugin name="EmailTemplateStoreAddress" type="Magento\Email\Model\Plugin\StoreAddress"/>
98+
</type>
9699
</config>

dev/tests/integration/testsuite/Magento/Email/Model/TemplateTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,4 +870,31 @@ public function testSetOptions()
870870
$this->model->setOptions($options);
871871
$this->assertEquals($options, $this->model->getDesignConfig()->getData());
872872
}
873+
874+
/**
875+
* @magentoConfigFixture default_store general/store_information/name Test Store
876+
* @magentoConfigFixture default_store general/store_information/street_line1 Street 1
877+
* @magentoConfigFixture default_store general/store_information/street_line2 Street 2
878+
* @magentoConfigFixture default_store general/store_information/city Austin
879+
* @magentoConfigFixture default_store general/store_information/zip 78758
880+
* @magentoConfigFixture default_store general/store_information/country_id US
881+
* @magentoConfigFixture default_store general/store_information/region_id 57
882+
*/
883+
public function testStoreFormattedAddress()
884+
{
885+
$this->mockModel();
886+
$this->model->setTemplateType(TemplateTypesInterface::TYPE_HTML);
887+
888+
/* See app/design/frontend/Magento/luma/Magento_Email/email/footer.html */
889+
$template = '{{var store.formatted_address|raw}}';
890+
$this->model->setTemplateText($template);
891+
892+
$result = $this->model->getProcessedTemplate();
893+
$this->assertStringContainsString('Test Store', $result);
894+
$this->assertStringContainsString('Street 1', $result);
895+
$this->assertStringContainsString('Street 2', $result);
896+
$this->assertStringContainsString('Austin', $result);
897+
$this->assertStringContainsString('Texas', $result);
898+
$this->assertStringContainsString('United States', $result);
899+
}
873900
}

dev/tests/integration/testsuite/Magento/Framework/Filter/DirectiveProcessor/SimpleDirectiveTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ public function testDefaultFiltersAreUsed()
7474
public function testParametersAreParsed()
7575
{
7676
$filter = $this->objectManager->create(Template::class);
77-
$filter->setStrictMode(false);
7877

7978
$processor = $this->createWithProcessorsAndFilters(
8079
['mydir' => $this->objectManager->create(MyDirProcessor::class)],

0 commit comments

Comments
 (0)