Skip to content

Commit d7c4eb2

Browse files
author
Oleksii Korshenko
committed
MAGETWO-69668: [#7291] Change the default contact form email template to HTML #9786
- fixed issue with current store id
1 parent 2bc0c82 commit d7c4eb2

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

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

Lines changed: 15 additions & 2 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
/**
@@ -59,7 +72,7 @@ public function send($replyTo, array $variables)
5972
->setTemplateOptions(
6073
[
6174
'area' => 'frontend',
62-
'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
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

0 commit comments

Comments
 (0)