diff --git a/app/code/Magento/Contact/Model/Mail.php b/app/code/Magento/Contact/Model/Mail.php index 9a1f1ff8a2063..d63efbbca573b 100644 --- a/app/code/Magento/Contact/Model/Mail.php +++ b/app/code/Magento/Contact/Model/Mail.php @@ -6,7 +6,9 @@ namespace Magento\Contact\Model; use Magento\Framework\Mail\Template\TransportBuilder; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Translate\Inline\StateInterface; +use Magento\Store\Model\StoreManagerInterface; class Mail implements MailInterface { @@ -26,18 +28,29 @@ class Mail implements MailInterface private $inlineTranslation; /** + * @var StoreManagerInterface + */ + private $storeManager; + + /** + * Initialize dependencies. + * * @param ConfigInterface $contactsConfig * @param TransportBuilder $transportBuilder * @param StateInterface $inlineTranslation + * @param StoreManagerInterface|null $storeManager */ public function __construct( ConfigInterface $contactsConfig, TransportBuilder $transportBuilder, - StateInterface $inlineTranslation + StateInterface $inlineTranslation, + StoreManagerInterface $storeManager = null ) { $this->contactsConfig = $contactsConfig; $this->transportBuilder = $transportBuilder; $this->inlineTranslation = $inlineTranslation; + $this->storeManager = $storeManager ?: + ObjectManager::getInstance()->get(StoreManagerInterface::class); } /** @@ -58,8 +71,8 @@ public function send($replyTo, array $variables) ->setTemplateIdentifier($this->contactsConfig->emailTemplate()) ->setTemplateOptions( [ - 'area' => 'adminhtml', - 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID, + 'area' => 'frontend', + 'store' => $this->storeManager->getStore()->getId() ] ) ->setTemplateVars($variables) diff --git a/app/code/Magento/Contact/Test/Unit/Model/MailTest.php b/app/code/Magento/Contact/Test/Unit/Model/MailTest.php index e1e8fec435125..f432a4fc5ccee 100644 --- a/app/code/Magento/Contact/Test/Unit/Model/MailTest.php +++ b/app/code/Magento/Contact/Test/Unit/Model/MailTest.php @@ -8,6 +8,8 @@ use Magento\Contact\Model\ConfigInterface; use Magento\Contact\Model\Mail; +use Magento\Store\Model\StoreManagerInterface; +use Magento\Store\Api\Data\StoreInterface; class MailTest extends \PHPUnit_Framework_TestCase { @@ -32,6 +34,11 @@ class MailTest extends \PHPUnit_Framework_TestCase */ private $inlineTranslationMock; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $storeManagerMock; + /** * @var Mail */ @@ -50,10 +57,13 @@ protected function setUp() )->disableOriginalConstructor( )->getMock(); + $this->storeManagerMock = $this->getMock(StoreManagerInterface::class); + $this->mail = new Mail( $this->configMock, $this->transportBuilderMock, - $this->inlineTranslationMock + $this->inlineTranslationMock, + $this->storeManagerMock ); } @@ -64,6 +74,11 @@ public function testSendMail() $transport = $this->getMock(\Magento\Framework\Mail\TransportInterface::class, [], [], '', false); + $store = $this->getMock(StoreInterface::class); + $store->expects($this->once())->method('getId')->willReturn(555); + + $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($store); + $this->transportBuilderMock->expects($this->once()) ->method('setTemplateIdentifier') ->will($this->returnSelf()); @@ -71,8 +86,8 @@ public function testSendMail() $this->transportBuilderMock->expects($this->once()) ->method('setTemplateOptions') ->with([ - 'area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, - 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID, + 'area' => 'frontend', + 'store' => 555, ]) ->will($this->returnSelf()); diff --git a/app/code/Magento/Contact/etc/email_templates.xml b/app/code/Magento/Contact/etc/email_templates.xml index 8ae3b643f43c8..8f3f5ee442f7d 100644 --- a/app/code/Magento/Contact/etc/email_templates.xml +++ b/app/code/Magento/Contact/etc/email_templates.xml @@ -6,5 +6,5 @@ */ --> -