Skip to content
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
2 changes: 2 additions & 0 deletions app/code/Magento/Checkout/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ public function sendPaymentFailedEmail($checkout, $message, $checkoutType = 'one
'items' => nl2br($items),
'total' => $total,
]
)->setScopeId(
$checkout->getStoreId()
)->setFrom(
$this->scopeConfig->getValue(
'checkout/payment_failed/identity',
Expand Down
10 changes: 10 additions & 0 deletions app/code/Magento/Checkout/Test/Unit/Helper/DataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ public function testSendPaymentFailedEmail()
$this->returnSelf()
);

$this->_transportBuilder->expects(
$this->once()
)->method(
'setScopeId'
)->with(
8
)->will(
$this->returnSelf()
);

$this->_transportBuilder->expects(
$this->once()
)->method(
Expand Down
5 changes: 3 additions & 2 deletions app/code/Magento/Customer/Model/AccountManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -717,12 +717,12 @@ public function createAccountWithPasswordHash(CustomerInterface $customer, $hash
}
try {
foreach ($customerAddresses as $address) {
if ($address->getId()) {
if ($address->getId()) {
$newAddress = clone $address;
$newAddress->setId(null);
$newAddress->setCustomerId($customer->getId());
$this->addressRepository->save($newAddress);
} else {
} else {
$address->setCustomerId($customer->getId());
$this->addressRepository->save($address);
}
Expand Down Expand Up @@ -1093,6 +1093,7 @@ protected function sendEmailTemplate(
$transport = $this->transportBuilder->setTemplateIdentifier($templateId)
->setTemplateOptions(['area' => Area::AREA_FRONTEND, 'store' => $storeId])
->setTemplateVars($templateParams)
->setScopeId($storeId)
->setFrom($this->scopeConfig->getValue($sender, ScopeInterface::SCOPE_STORE, $storeId))
->addTo($email, $this->customerViewHelper->getCustomerName($customer))
->getTransport();
Expand Down
2 changes: 2 additions & 0 deletions app/code/Magento/Customer/Model/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,8 @@ protected function _sendEmailTemplate($template, $sender, $templateParams = [],
['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeId]
)->setTemplateVars(
$templateParams
)->setScopeId(
$storeId
)->setFrom(
$this->_scopeConfig->getValue($sender, ScopeInterface::SCOPE_STORE, $storeId)
)->addTo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,10 @@ public function testSendPasswordReminderEmail()
->method('setTemplateVars')
->with(['customer' => $this->customerSecure, 'store' => $this->store])
->willReturnSelf();
$this->transportBuilder->expects($this->any())
->method('setScopeId')
->with($customerStoreId)
->willReturnSelf();
$this->transportBuilder->expects($this->once())
->method('setFrom')
->with($sender)
Expand Down Expand Up @@ -1622,8 +1626,8 @@ public function testCreateAccountWithPasswordHashWithCustomerAddresses()
->expects($this->atLeastOnce())
->method("save")
->withConsecutive(
array($this->logicalNot($this->identicalTo($existingAddress))),
array($this->identicalTo($nonExistingAddress))
[$this->logicalNot($this->identicalTo($existingAddress))],
[$this->identicalTo($nonExistingAddress)]
);

$existingAddress
Expand Down
6 changes: 6 additions & 0 deletions app/code/Magento/Customer/Test/Unit/Model/CustomerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ public function testSendNewAccountEmailWithoutStoreId()
->method($method)
->will($this->returnSelf());
}

$this->_transportBuilderMock->expects($this->any())
->method('setScopeId')
->with(1)
->willReturnSelf();

$transportMock = $this->getMock('Magento\Framework\Mail\TransportInterface', [], [], '', false);
$transportMock->expects($this->once())
->method('sendMessage')
Expand Down
15 changes: 12 additions & 3 deletions app/code/Magento/Newsletter/Model/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ public function sendConfirmationRequestEmail()

$this->inlineTranslation->suspend();

$storeId = $this->_storeManager->getStore()->getId();
$this->_transportBuilder->setTemplateIdentifier(
$this->_scopeConfig->getValue(
self::XML_PATH_CONFIRM_EMAIL_TEMPLATE,
Expand All @@ -655,10 +656,12 @@ public function sendConfirmationRequestEmail()
)->setTemplateOptions(
[
'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
'store' => $this->_storeManager->getStore()->getId(),
'store' => $storeId,
]
)->setTemplateVars(
['subscriber' => $this, 'store' => $this->_storeManager->getStore()]
)->setScopeId(
$storeId
)->setFrom(
$this->_scopeConfig->getValue(
self::XML_PATH_CONFIRM_EMAIL_IDENTITY,
Expand Down Expand Up @@ -700,6 +703,7 @@ public function sendConfirmationSuccessEmail()

$this->inlineTranslation->suspend();

$storeId = $this->_storeManager->getStore()->getId();
$this->_transportBuilder->setTemplateIdentifier(
$this->_scopeConfig->getValue(
self::XML_PATH_SUCCESS_EMAIL_TEMPLATE,
Expand All @@ -708,10 +712,12 @@ public function sendConfirmationSuccessEmail()
)->setTemplateOptions(
[
'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
'store' => $this->_storeManager->getStore()->getId(),
'store' => $storeId,
]
)->setTemplateVars(
['subscriber' => $this]
)->setScopeId(
$storeId
)->setFrom(
$this->_scopeConfig->getValue(
self::XML_PATH_SUCCESS_EMAIL_IDENTITY,
Expand Down Expand Up @@ -752,6 +758,7 @@ public function sendUnsubscriptionEmail()

$this->inlineTranslation->suspend();

$storeId = $this->_storeManager->getStore()->getId();
$this->_transportBuilder->setTemplateIdentifier(
$this->_scopeConfig->getValue(
self::XML_PATH_UNSUBSCRIBE_EMAIL_TEMPLATE,
Expand All @@ -760,10 +767,12 @@ public function sendUnsubscriptionEmail()
)->setTemplateOptions(
[
'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
'store' => $this->_storeManager->getStore()->getId(),
'store' => $storeId,
]
)->setTemplateVars(
['subscriber' => $this]
)->setScopeId(
$storeId
)->setFrom(
$this->_scopeConfig->getValue(
self::XML_PATH_UNSUBSCRIBE_EMAIL_IDENTITY,
Expand Down
2 changes: 2 additions & 0 deletions app/code/Magento/ProductAlert/Model/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ public function send()
'customerName' => $this->_customerHelper->getCustomerName($this->_customer),
'alertGrid' => $alertGrid,
]
)->setScopeId(
$storeId
)->setFrom(
$this->_scopeConfig->getValue(
self::XML_PATH_EMAIL_IDENTITY,
Expand Down
2 changes: 2 additions & 0 deletions app/code/Magento/Sales/Model/Order/Email/SenderBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public function __construct(
*/
public function send()
{
$this->transportBuilder->setScopeId($this->identityContainer->getStore()->getId());

$this->configureEmailTemplate();

$this->transportBuilder->addTo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,23 @@ protected function setUp()
[
'getEmailIdentity', 'getCustomerEmail',
'getCustomerName', 'getTemplateOptions', 'getEmailCopyTo',
'getCopyMethod'
'getCopyMethod', 'getStore'
],
[],
'',
false
);

$this->identityContainerMock->expects($this->any())
->method('getStore')
->willReturn($this->storeMock);

$this->transportBuilder = $this->getMock(
'\Magento\Framework\Mail\Template\TransportBuilder',
[
'addTo', 'addBcc', 'getTransport',
'setTemplateIdentifier', 'setTemplateOptions', 'setTemplateVars',
'setFrom',
'setFrom'
],
[],
'',
Expand Down
5 changes: 4 additions & 1 deletion app/code/Magento/Wishlist/Controller/Index/Send.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ public function execute()

try {
foreach ($emails as $email) {
$storeId = $this->storeManager->getStore()->getStoreId();
$transport = $this->_transportBuilder->setTemplateIdentifier(
$this->scopeConfig->getValue(
'wishlist/email/email_template',
Expand All @@ -194,7 +195,7 @@ public function execute()
)->setTemplateOptions(
[
'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
'store' => $this->storeManager->getStore()->getStoreId(),
'store' => $storeId,
]
)->setTemplateVars(
[
Expand All @@ -206,6 +207,8 @@ public function execute()
'message' => $message,
'store' => $this->storeManager->getStore(),
]
)->setScopeId(
$storeId
)->setFrom(
$this->scopeConfig->getValue(
'wishlist/email/email_identity',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,10 @@ public function testExecute()
'store' => $this->store,
])
->willReturnSelf();
$this->transportBuilder->expects($this->any())
->method('setScopeId')
->with($storeId)
->willReturnSelf();
$this->transportBuilder->expects($this->once())
->method('setFrom')
->with($from)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ class TransportBuilder
*/
protected $mailTransportFactory;

/** @var int|null */
private $scopeId;

/**
* @param FactoryInterface $templateFactory
* @param MessageInterface $message
Expand Down Expand Up @@ -156,6 +159,18 @@ public function setReplyTo($email, $name = null)
return $this;
}

/**
* Set scope
*
* @param int $scopeId
* @return $this
*/
public function setScopeId($scopeId)
{
$this->scopeId = $scopeId;
return $this;
}

/**
* Set mail from address
*
Expand All @@ -164,7 +179,7 @@ public function setReplyTo($email, $name = null)
*/
public function setFrom($from)
{
$result = $this->_senderResolver->resolve($from);
$result = $this->_senderResolver->resolve($from, $this->scopeId);
$this->message->setFrom($result['email'], $result['name']);
return $this;
}
Expand Down Expand Up @@ -242,6 +257,7 @@ protected function reset()
$this->templateIdentifier = null;
$this->templateVars = null;
$this->templateOptions = null;
$this->scopeId = null;
return $this;
}

Expand Down