Skip to content

Commit

Permalink
ENGCOM-4512: #21786 Fixed asynchronous email sending for the sales en…
Browse files Browse the repository at this point in the history
…tities which were created with disabled email sending #21788
  • Loading branch information
sidolov authored Apr 15, 2019
2 parents ad95ff9 + 78e98e4 commit 84826f9
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,15 @@ public function __construct(
* @param bool $forceSyncMode
*
* @return bool
* @throws \Exception
*/
public function send(
\Magento\Sales\Api\Data\OrderInterface $order,
\Magento\Sales\Api\Data\CreditmemoInterface $creditmemo,
\Magento\Sales\Api\Data\CreditmemoCommentCreationInterface $comment = null,
$forceSyncMode = false
) {
$creditmemo->setSendEmail(true);
$creditmemo->setSendEmail($this->identityContainer->isEnabled());

if (!$this->globalConfig->getValue('sales_email/general/async_sending') || $forceSyncMode) {
$transport = [
Expand Down Expand Up @@ -145,6 +146,7 @@ public function send(
* @param \Magento\Sales\Api\Data\OrderInterface $order
*
* @return string
* @throws \Exception
*/
private function getPaymentHtml(\Magento\Sales\Api\Data\OrderInterface $order)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ class CreditmemoSender extends Sender
* @param CreditmemoIdentity $identityContainer
* @param Order\Email\SenderBuilderFactory $senderBuilderFactory
* @param \Psr\Log\LoggerInterface $logger
* @param Renderer $addressRenderer
* @param PaymentHelper $paymentHelper
* @param CreditmemoResource $creditmemoResource
* @param \Magento\Framework\App\Config\ScopeConfigInterface $globalConfig
* @param Renderer $addressRenderer
* @param ManagerInterface $eventManager
*/
public function __construct(
Expand Down Expand Up @@ -96,10 +96,11 @@ public function __construct(
* @param Creditmemo $creditmemo
* @param bool $forceSyncMode
* @return bool
* @throws \Exception
*/
public function send(Creditmemo $creditmemo, $forceSyncMode = false)
{
$creditmemo->setSendEmail(true);
$creditmemo->setSendEmail($this->identityContainer->isEnabled());

if (!$this->globalConfig->getValue('sales_email/general/async_sending') || $forceSyncMode) {
$order = $creditmemo->getOrder();
Expand Down Expand Up @@ -146,6 +147,7 @@ public function send(Creditmemo $creditmemo, $forceSyncMode = false)
*
* @param Order $order
* @return string
* @throws \Exception
*/
protected function getPaymentHtml(Order $order)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ class InvoiceSender extends Sender
* @param InvoiceIdentity $identityContainer
* @param Order\Email\SenderBuilderFactory $senderBuilderFactory
* @param \Psr\Log\LoggerInterface $logger
* @param Renderer $addressRenderer
* @param PaymentHelper $paymentHelper
* @param InvoiceResource $invoiceResource
* @param \Magento\Framework\App\Config\ScopeConfigInterface $globalConfig
* @param Renderer $addressRenderer
* @param ManagerInterface $eventManager
*/
public function __construct(
Expand Down Expand Up @@ -96,10 +96,11 @@ public function __construct(
* @param Invoice $invoice
* @param bool $forceSyncMode
* @return bool
* @throws \Exception
*/
public function send(Invoice $invoice, $forceSyncMode = false)
{
$invoice->setSendEmail(true);
$invoice->setSendEmail($this->identityContainer->isEnabled());

if (!$this->globalConfig->getValue('sales_email/general/async_sending') || $forceSyncMode) {
$order = $invoice->getOrder();
Expand Down Expand Up @@ -146,6 +147,7 @@ public function send(Invoice $invoice, $forceSyncMode = false)
*
* @param Order $order
* @return string
* @throws \Exception
*/
protected function getPaymentHtml(Order $order)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ class ShipmentSender extends Sender
* @param ShipmentIdentity $identityContainer
* @param Order\Email\SenderBuilderFactory $senderBuilderFactory
* @param \Psr\Log\LoggerInterface $logger
* @param Renderer $addressRenderer
* @param PaymentHelper $paymentHelper
* @param ShipmentResource $shipmentResource
* @param \Magento\Framework\App\Config\ScopeConfigInterface $globalConfig
* @param Renderer $addressRenderer
* @param ManagerInterface $eventManager
*/
public function __construct(
Expand Down Expand Up @@ -96,10 +96,11 @@ public function __construct(
* @param Shipment $shipment
* @param bool $forceSyncMode
* @return bool
* @throws \Exception
*/
public function send(Shipment $shipment, $forceSyncMode = false)
{
$shipment->setSendEmail(true);
$shipment->setSendEmail($this->identityContainer->isEnabled());

if (!$this->globalConfig->getValue('sales_email/general/async_sending') || $forceSyncMode) {
$order = $shipment->getOrder();
Expand Down Expand Up @@ -146,6 +147,7 @@ public function send(Shipment $shipment, $forceSyncMode = false)
*
* @param Order $order
* @return string
* @throws \Exception
*/
protected function getPaymentHtml(Order $order)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,15 @@ public function __construct(
* @param bool $forceSyncMode
*
* @return bool
* @throws \Exception
*/
public function send(
\Magento\Sales\Api\Data\OrderInterface $order,
\Magento\Sales\Api\Data\InvoiceInterface $invoice,
\Magento\Sales\Api\Data\InvoiceCommentCreationInterface $comment = null,
$forceSyncMode = false
) {
$invoice->setSendEmail(true);
$invoice->setSendEmail($this->identityContainer->isEnabled());

if (!$this->globalConfig->getValue('sales_email/general/async_sending') || $forceSyncMode) {
$transport = [
Expand Down Expand Up @@ -145,6 +146,7 @@ public function send(
* @param \Magento\Sales\Api\Data\OrderInterface $order
*
* @return string
* @throws \Exception
*/
private function getPaymentHtml(\Magento\Sales\Api\Data\OrderInterface $order)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,15 @@ public function __construct(
* @param bool $forceSyncMode
*
* @return bool
* @throws \Exception
*/
public function send(
\Magento\Sales\Api\Data\OrderInterface $order,
\Magento\Sales\Api\Data\ShipmentInterface $shipment,
\Magento\Sales\Api\Data\ShipmentCommentCreationInterface $comment = null,
$forceSyncMode = false
) {
$shipment->setSendEmail(true);
$shipment->setSendEmail($this->identityContainer->isEnabled());

if (!$this->globalConfig->getValue('sales_email/general/async_sending') || $forceSyncMode) {
$transport = [
Expand Down Expand Up @@ -145,6 +146,7 @@ public function send(
* @param \Magento\Sales\Api\Data\OrderInterface $order
*
* @return string
* @throws \Exception
*/
private function getPaymentHtml(\Magento\Sales\Api\Data\OrderInterface $order)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
Expand Down Expand Up @@ -249,7 +248,7 @@ public function testSend($configValue, $forceSyncMode, $isComment, $emailSending

$this->creditmemoMock->expects($this->once())
->method('setSendEmail')
->with(true);
->with($emailSendingResult);

if (!$configValue || $forceSyncMode) {
$transport = [
Expand Down Expand Up @@ -279,7 +278,7 @@ public function testSend($configValue, $forceSyncMode, $isComment, $emailSending
->method('setTemplateVars')
->with($transport->getData());

$this->identityContainerMock->expects($this->once())
$this->identityContainerMock->expects($this->exactly(2))
->method('isEnabled')
->willReturn($emailSendingResult);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

use Magento\Sales\Model\Order\Email\Sender\CreditmemoSender;

/**
* Test for Magento\Sales\Model\Order\Email\Sender\CreditmemoSender class.
*/
class CreditmemoSenderTest extends AbstractSenderTest
{
/**
Expand Down Expand Up @@ -90,7 +93,7 @@ public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $ema

$this->creditmemoMock->expects($this->once())
->method('setSendEmail')
->with(true);
->with($emailSendingResult);

$this->globalConfig->expects($this->once())
->method('getValue')
Expand Down Expand Up @@ -130,7 +133,7 @@ public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $ema
]
);

$this->identityContainerMock->expects($this->once())
$this->identityContainerMock->expects($this->exactly(2))
->method('isEnabled')
->willReturn($emailSendingResult);

Expand Down Expand Up @@ -197,6 +200,8 @@ public function sendDataProvider()
* @param bool $isVirtualOrder
* @param int $formatCallCount
* @param string|null $expectedShippingAddress
*
* @return void
* @dataProvider sendVirtualOrderDataProvider
*/
public function testSendVirtualOrder($isVirtualOrder, $formatCallCount, $expectedShippingAddress)
Expand All @@ -207,7 +212,7 @@ public function testSendVirtualOrder($isVirtualOrder, $formatCallCount, $expecte

$this->creditmemoMock->expects($this->once())
->method('setSendEmail')
->with(true);
->with(false);

$this->globalConfig->expects($this->once())
->method('getValue')
Expand Down Expand Up @@ -242,7 +247,7 @@ public function testSendVirtualOrder($isVirtualOrder, $formatCallCount, $expecte
]
);

$this->identityContainerMock->expects($this->once())
$this->identityContainerMock->expects($this->exactly(2))
->method('isEnabled')
->willReturn(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

use Magento\Sales\Model\Order\Email\Sender\InvoiceSender;

/**
* Test for Magento\Sales\Model\Order\Email\Sender\InvoiceSender class.
*/
class InvoiceSenderTest extends AbstractSenderTest
{
/**
Expand Down Expand Up @@ -90,7 +93,7 @@ public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $ema

$this->invoiceMock->expects($this->once())
->method('setSendEmail')
->with(true);
->with($emailSendingResult);

$this->globalConfig->expects($this->once())
->method('getValue')
Expand Down Expand Up @@ -136,7 +139,7 @@ public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $ema
]
);

$this->identityContainerMock->expects($this->once())
$this->identityContainerMock->expects($this->exactly(2))
->method('isEnabled')
->willReturn($emailSendingResult);

Expand Down Expand Up @@ -212,7 +215,7 @@ public function testSendVirtualOrder($isVirtualOrder, $formatCallCount, $expecte

$this->invoiceMock->expects($this->once())
->method('setSendEmail')
->with(true);
->with(false);

$this->globalConfig->expects($this->once())
->method('getValue')
Expand Down Expand Up @@ -247,7 +250,7 @@ public function testSendVirtualOrder($isVirtualOrder, $formatCallCount, $expecte
]
);

$this->identityContainerMock->expects($this->once())
$this->identityContainerMock->expects($this->exactly(2))
->method('isEnabled')
->willReturn(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

use Magento\Sales\Model\Order\Email\Sender\ShipmentSender;

/**
* Test for Magento\Sales\Model\Order\Email\Sender\ShipmentSender class.
*/
class ShipmentSenderTest extends AbstractSenderTest
{
/**
Expand Down Expand Up @@ -90,7 +93,7 @@ public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $ema

$this->shipmentMock->expects($this->once())
->method('setSendEmail')
->with(true);
->with($emailSendingResult);

$this->globalConfig->expects($this->once())
->method('getValue')
Expand Down Expand Up @@ -136,7 +139,7 @@ public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $ema
]
);

$this->identityContainerMock->expects($this->once())
$this->identityContainerMock->expects($this->exactly(2))
->method('isEnabled')
->willReturn($emailSendingResult);

Expand Down Expand Up @@ -212,7 +215,7 @@ public function testSendVirtualOrder($isVirtualOrder, $formatCallCount, $expecte

$this->shipmentMock->expects($this->once())
->method('setSendEmail')
->with(true);
->with(false);

$this->globalConfig->expects($this->once())
->method('getValue')
Expand Down Expand Up @@ -247,7 +250,7 @@ public function testSendVirtualOrder($isVirtualOrder, $formatCallCount, $expecte
]
);

$this->identityContainerMock->expects($this->once())
$this->identityContainerMock->expects($this->exactly(2))
->method('isEnabled')
->willReturn(false);
$this->shipmentResourceMock->expects($this->once())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public function testSend($configValue, $forceSyncMode, $isComment, $emailSending

$this->invoiceMock->expects($this->once())
->method('setSendEmail')
->with(true);
->with($emailSendingResult);

if (!$configValue || $forceSyncMode) {
$transport = [
Expand Down Expand Up @@ -277,7 +277,7 @@ public function testSend($configValue, $forceSyncMode, $isComment, $emailSending
->method('setTemplateVars')
->with($transport->getData());

$this->identityContainerMock->expects($this->once())
$this->identityContainerMock->expects($this->exactly(2))
->method('isEnabled')
->willReturn($emailSendingResult);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public function testSend($configValue, $forceSyncMode, $isComment, $emailSending

$this->shipmentMock->expects($this->once())
->method('setSendEmail')
->with(true);
->with($emailSendingResult);

if (!$configValue || $forceSyncMode) {
$transport = [
Expand Down Expand Up @@ -279,7 +279,7 @@ public function testSend($configValue, $forceSyncMode, $isComment, $emailSending
->method('setTemplateVars')
->with($transport->getData());

$this->identityContainerMock->expects($this->once())
$this->identityContainerMock->expects($this->exactly(2))
->method('isEnabled')
->willReturn($emailSendingResult);

Expand Down

0 comments on commit 84826f9

Please sign in to comment.