Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#14952 Confirmation emails have no FROM or FROM email address 2.2.4 #15119

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions app/code/Magento/Sales/Model/Order/Email/SenderBuilder.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
*/
namespace Magento\Sales\Model\Order\Email;

use Magento\Framework\App\ObjectManager;
use Magento\Framework\Mail\Template\TransportBuilder;
use Magento\Framework\Mail\Template\TransportBuilderByStore;
use Magento\Sales\Model\Order\Email\Container\IdentityInterface;
use Magento\Sales\Model\Order\Email\Container\Template;

Expand All @@ -28,29 +26,19 @@ class SenderBuilder
*/
protected $transportBuilder;

/**
* @var TransportBuilderByStore
*/
private $transportBuilderByStore;

/**
* @param Template $templateContainer
* @param IdentityInterface $identityContainer
* @param TransportBuilder $transportBuilder
* @param TransportBuilderByStore $transportBuilderByStore
*/
public function __construct(
Template $templateContainer,
IdentityInterface $identityContainer,
TransportBuilder $transportBuilder,
TransportBuilderByStore $transportBuilderByStore = null
TransportBuilder $transportBuilder
) {
$this->templateContainer = $templateContainer;
$this->identityContainer = $identityContainer;
$this->transportBuilder = $transportBuilder;
$this->transportBuilderByStore = $transportBuilderByStore ?: ObjectManager::getInstance()->get(
TransportBuilderByStore::class
);
}

/**
Expand Down Expand Up @@ -110,7 +98,7 @@ protected function configureEmailTemplate()
$this->transportBuilder->setTemplateIdentifier($this->templateContainer->getTemplateId());
$this->transportBuilder->setTemplateOptions($this->templateContainer->getTemplateOptions());
$this->transportBuilder->setTemplateVars($this->templateContainer->getTemplateVars());
$this->transportBuilderByStore->setFromByStore(
$this->transportBuilder->setFromByStore(
$this->identityContainer->getEmailIdentity(),
$this->identityContainer->getStore()->getId()
);
Expand Down
14 changes: 3 additions & 11 deletions app/code/Magento/Sales/Test/Unit/Model/Order/Email/SenderBuilderTest.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

namespace Magento\Sales\Test\Unit\Model\Order\Email;

use Magento\Framework\Mail\Template\TransportBuilderByStore;
use Magento\Sales\Model\Order\Email\SenderBuilder;

class SenderBuilderTest extends \PHPUnit\Framework\TestCase
Expand Down Expand Up @@ -36,11 +35,6 @@ class SenderBuilderTest extends \PHPUnit\Framework\TestCase
*/
private $storeMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $transportBuilderByStore;

protected function setUp()
{
$templateId = 'test_template_id';
Expand Down Expand Up @@ -82,11 +76,10 @@ protected function setUp()
'setTemplateIdentifier',
'setTemplateOptions',
'setTemplateVars',
'setFromByStore'
]
);

$this->transportBuilderByStore = $this->createMock(TransportBuilderByStore::class);

$this->templateContainerMock->expects($this->once())
->method('getTemplateId')
->will($this->returnValue($templateId));
Expand All @@ -109,7 +102,7 @@ protected function setUp()
$this->identityContainerMock->expects($this->once())
->method('getEmailIdentity')
->will($this->returnValue($emailIdentity));
$this->transportBuilderByStore->expects($this->once())
$this->transportBuilder->expects($this->once())
->method('setFromByStore')
->with($this->equalTo($emailIdentity));

Expand All @@ -120,8 +113,7 @@ protected function setUp()
$this->senderBuilder = new SenderBuilder(
$this->templateContainerMock,
$this->identityContainerMock,
$this->transportBuilder,
$this->transportBuilderByStore
$this->transportBuilder
);
}

Expand Down
16 changes: 16 additions & 0 deletions lib/internal/Magento/Framework/Mail/Template/TransportBuilder.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,20 @@ protected function prepareMessage()

return $this;
}

/**
* Set mail from address by store.
*
* @param string|array $from
* @param string|int $store
*
* @return $this
*/
public function setFromByStore($from, $store)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to avoid adding new public methods when not necessary. Every public method is a kind of contract for backward compatibility.

Changing setFrom and adding an optional parameter could be a better option.

See https://github.com/magento/magento2/pull/16356/files trying to fix the same issue.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am facing the same issue , when a customer placed an order then customer is getting the mail but not admin.. And the second thing is that it is the taking the different host as my id is socketswitches@socket-switches.com but system is sending from socketswitches@ssdvps-80478.vps.net  . ssdvps-80478.vps.net this is the server ..Any help!!!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had tried this code but isn't working.

Copy link

@gopal2k6 gopal2k6 Jun 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am also facing same issue.. can you help in this ? My issue in 2.3

{
$result = $this->_senderResolver->resolve($from, $store);
$this->message->setFrom($result['email'], $result['name']);

return $this;
}
}

This file was deleted.

This file was deleted.

19 changes: 19 additions & 0 deletions lib/internal/Magento/Framework/Mail/Test/Unit/Template/TransportBuilderTest.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,23 @@ public function testSetReplyTo()

$this->builder->setReplyTo('replyTo@example.com', 'replyName');
}

/**
* @return void
*/
public function testSetFromByStore()
{
$sender = ['email' => 'from@example.com', 'name' => 'name'];
$store = 1;
$this->senderResolverMock->expects($this->once())
->method('resolve')
->with($sender, $store)
->willReturn($sender);
$this->messageMock->expects($this->once())
->method('setFrom')
->with('from@example.com', 'name')
->willReturnSelf();

$this->builder->setFromByStore($sender, $store);
}
}