Skip to content

Commit 19a2bd7

Browse files
author
Oleksii Korshenko
authored
MAGETWO-69668: [#7291] Change the default contact form email template to HTML #9786
2 parents 19acfd3 + 59e0b98 commit 19a2bd7

File tree

6 files changed

+85
-26
lines changed

6 files changed

+85
-26
lines changed

app/code/Magento/Contact/Model/Mail.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
namespace Magento\Contact\Model;
77

88
use Magento\Framework\Mail\Template\TransportBuilder;
9+
use Magento\Framework\App\ObjectManager;
910
use Magento\Framework\Translate\Inline\StateInterface;
11+
use Magento\Store\Model\StoreManagerInterface;
1012

1113
class Mail implements MailInterface
1214
{
@@ -26,18 +28,29 @@ class Mail implements MailInterface
2628
private $inlineTranslation;
2729

2830
/**
31+
* @var StoreManagerInterface
32+
*/
33+
private $storeManager;
34+
35+
/**
36+
* Initialize dependencies.
37+
*
2938
* @param ConfigInterface $contactsConfig
3039
* @param TransportBuilder $transportBuilder
3140
* @param StateInterface $inlineTranslation
41+
* @param StoreManagerInterface|null $storeManager
3242
*/
3343
public function __construct(
3444
ConfigInterface $contactsConfig,
3545
TransportBuilder $transportBuilder,
36-
StateInterface $inlineTranslation
46+
StateInterface $inlineTranslation,
47+
StoreManagerInterface $storeManager = null
3748
) {
3849
$this->contactsConfig = $contactsConfig;
3950
$this->transportBuilder = $transportBuilder;
4051
$this->inlineTranslation = $inlineTranslation;
52+
$this->storeManager = $storeManager ?:
53+
ObjectManager::getInstance()->get(StoreManagerInterface::class);
4154
}
4255

4356
/**
@@ -58,8 +71,8 @@ public function send($replyTo, array $variables)
5871
->setTemplateIdentifier($this->contactsConfig->emailTemplate())
5972
->setTemplateOptions(
6073
[
61-
'area' => 'adminhtml',
62-
'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
74+
'area' => 'frontend',
75+
'store' => $this->storeManager->getStore()->getId()
6376
]
6477
)
6578
->setTemplateVars($variables)

app/code/Magento/Contact/Test/Unit/Model/MailTest.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
use Magento\Contact\Model\ConfigInterface;
1010
use Magento\Contact\Model\Mail;
11+
use Magento\Store\Model\StoreManagerInterface;
12+
use Magento\Store\Api\Data\StoreInterface;
1113

1214
class MailTest extends \PHPUnit_Framework_TestCase
1315
{
@@ -32,6 +34,11 @@ class MailTest extends \PHPUnit_Framework_TestCase
3234
*/
3335
private $inlineTranslationMock;
3436

37+
/**
38+
* @var \PHPUnit_Framework_MockObject_MockObject
39+
*/
40+
private $storeManagerMock;
41+
3542
/**
3643
* @var Mail
3744
*/
@@ -50,10 +57,13 @@ protected function setUp()
5057
)->disableOriginalConstructor(
5158
)->getMock();
5259

60+
$this->storeManagerMock = $this->getMock(StoreManagerInterface::class);
61+
5362
$this->mail = new Mail(
5463
$this->configMock,
5564
$this->transportBuilderMock,
56-
$this->inlineTranslationMock
65+
$this->inlineTranslationMock,
66+
$this->storeManagerMock
5767
);
5868
}
5969

@@ -64,15 +74,20 @@ public function testSendMail()
6474

6575
$transport = $this->getMock(\Magento\Framework\Mail\TransportInterface::class, [], [], '', false);
6676

77+
$store = $this->getMock(StoreInterface::class);
78+
$store->expects($this->once())->method('getId')->willReturn(555);
79+
80+
$this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($store);
81+
6782
$this->transportBuilderMock->expects($this->once())
6883
->method('setTemplateIdentifier')
6984
->will($this->returnSelf());
7085

7186
$this->transportBuilderMock->expects($this->once())
7287
->method('setTemplateOptions')
7388
->with([
74-
'area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE,
75-
'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
89+
'area' => 'frontend',
90+
'store' => 555,
7691
])
7792
->will($this->returnSelf());
7893

app/code/Magento/Contact/etc/email_templates.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Email:etc/email_templates.xsd">
9-
<template id="contact_email_email_template" label="Contact Form" file="submitted_form.html" type="text" module="Magento_Contact" area="adminhtml"/>
9+
<template id="contact_email_email_template" label="Contact Form" file="submitted_form.html" type="html" module="Magento_Contact" area="frontend"/>
1010
</config>

app/code/Magento/Contact/view/adminhtml/email/submitted_form.html

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!--
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<!--@subject {{trans "Contact Form"}} @-->
8+
<!--@vars {
9+
"var data.comment":"Comment",
10+
"var data.email":"Sender Email",
11+
"var data.name":"Sender Name",
12+
"var data.telephone":"Sender Telephone"
13+
} @-->
14+
15+
{{template config_path="design/email/header_template"}}
16+
17+
<table class="message-details">
18+
<tr>
19+
<td><b>{{trans "Name"}}</b></td>
20+
<td>{{var data.name}}</td>
21+
</tr>
22+
<tr>
23+
<td><b>{{trans "Email"}}</b></td>
24+
<td>{{var data.email}}</td>
25+
</tr>
26+
<tr>
27+
<td><b>{{trans "Phone"}}</b></td>
28+
<td>{{var data.telephone}}</td>
29+
</tr>
30+
</table>
31+
<p><b>{{trans "Message"}}</b></p>
32+
<p>{{var data.comment}}</p>
33+
34+
{{template config_path="design/email/footer_template"}}

app/design/frontend/Magento/blank/web/css/source/_email-base.less

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,19 @@ body {
287287
}
288288
}
289289
}
290+
291+
.message-details {
292+
margin-bottom: @indent__s;
293+
294+
b {
295+
font-weight: bold;
296+
}
297+
298+
td {
299+
padding-bottom: @indent__xs;
300+
301+
b {
302+
margin-right: @indent__s;
303+
}
304+
}
305+
}

0 commit comments

Comments
 (0)