Skip to content

Make Sales' emails $transport changeable from an observer #9755

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

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use Magento\Sales\Model\Order\Email\Sender;
use Magento\Sales\Model\Order\Creditmemo\SenderInterface;
use Magento\Framework\DataObject;

/**
* Email notification sender for Creditmemo.
Expand Down Expand Up @@ -106,13 +107,14 @@ public function send(
'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
'formattedBillingAddress' => $this->getFormattedBillingAddress($order),
];
$transport = new DataObject($transport);

$this->eventManager->dispatch(
'email_creditmemo_set_template_vars_before',
['sender' => $this, 'transport' => $transport]
);

$this->templateContainer->setTemplateVars($transport);
$this->templateContainer->setTemplateVars($transport->getData());

if ($this->checkAndSend($order)) {
$creditmemo->setEmailSent(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Magento\Sales\Model\Order\Email\NotifySender;
use Magento\Sales\Model\Order\Address\Renderer;
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\DataObject;

/**
* Class CreditmemoCommentSender
Expand Down Expand Up @@ -71,13 +72,14 @@ public function send(Creditmemo $creditmemo, $notify = true, $comment = '')
'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
'formattedBillingAddress' => $this->getFormattedBillingAddress($order),
];
$transport = new DataObject($transport);

$this->eventManager->dispatch(
'email_creditmemo_comment_set_template_vars_before',
['sender' => $this, 'transport' => $transport]
);

$this->templateContainer->setTemplateVars($transport);
$this->templateContainer->setTemplateVars($transport->getData());

return $this->checkAndSend($order, $notify);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Magento\Sales\Model\ResourceModel\Order\Creditmemo as CreditmemoResource;
use Magento\Sales\Model\Order\Address\Renderer;
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\DataObject;

/**
* Class CreditmemoSender
Expand Down Expand Up @@ -113,13 +114,14 @@ public function send(Creditmemo $creditmemo, $forceSyncMode = false)
'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
'formattedBillingAddress' => $this->getFormattedBillingAddress($order),
];
$transport = new DataObject($transport);

$this->eventManager->dispatch(
'email_creditmemo_set_template_vars_before',
['sender' => $this, 'transport' => $transport]
);

$this->templateContainer->setTemplateVars($transport);
$this->templateContainer->setTemplateVars($transport->getData());

if ($this->checkAndSend($order)) {
$creditmemo->setEmailSent(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Magento\Sales\Model\Order\Invoice;
use Magento\Sales\Model\Order\Address\Renderer;
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\DataObject;

/**
* Class InvoiceCommentSender
Expand Down Expand Up @@ -71,13 +72,14 @@ public function send(Invoice $invoice, $notify = true, $comment = '')
'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
'formattedBillingAddress' => $this->getFormattedBillingAddress($order),
];
$transport = new DataObject($transport);

$this->eventManager->dispatch(
'email_invoice_comment_set_template_vars_before',
['sender' => $this, 'transport' => $transport]
);

$this->templateContainer->setTemplateVars($transport);
$this->templateContainer->setTemplateVars($transport->getData());

return $this->checkAndSend($order, $notify);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Magento\Sales\Model\ResourceModel\Order\Invoice as InvoiceResource;
use Magento\Sales\Model\Order\Address\Renderer;
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\DataObject;

/**
* Class InvoiceSender
Expand Down Expand Up @@ -113,13 +114,14 @@ public function send(Invoice $invoice, $forceSyncMode = false)
'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
'formattedBillingAddress' => $this->getFormattedBillingAddress($order)
];
$transport = new DataObject($transport);

$this->eventManager->dispatch(
'email_invoice_set_template_vars_before',
['sender' => $this, 'transport' => $transport]
);

$this->templateContainer->setTemplateVars($transport);
$this->templateContainer->setTemplateVars($transport->getData());

if ($this->checkAndSend($order)) {
$invoice->setEmailSent(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Magento\Sales\Model\Order\Email\NotifySender;
use Magento\Sales\Model\Order\Address\Renderer;
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\DataObject;

/**
* Class OrderCommentSender
Expand Down Expand Up @@ -68,13 +69,14 @@ public function send(Order $order, $notify = true, $comment = '')
'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
'formattedBillingAddress' => $this->getFormattedBillingAddress($order),
];
$transport = new DataObject($transport);

$this->eventManager->dispatch(
'email_order_comment_set_template_vars_before',
['sender' => $this, 'transport' => $transport]
);

$this->templateContainer->setTemplateVars($transport);
$this->templateContainer->setTemplateVars($transport->getData());

return $this->checkAndSend($order, $notify);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Magento\Sales\Model\ResourceModel\Order as OrderResource;
use Magento\Sales\Model\Order\Address\Renderer;
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\DataObject;

/**
* Class OrderSender
Expand Down Expand Up @@ -130,7 +131,7 @@ protected function prepareTemplate(Order $order)
'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
'formattedBillingAddress' => $this->getFormattedBillingAddress($order),
];
$transport = new \Magento\Framework\DataObject($transport);
$transport = new DataObject($transport);

$this->eventManager->dispatch(
'email_order_set_template_vars_before',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Magento\Sales\Model\Order\Shipment;
use Magento\Sales\Model\Order\Address\Renderer;
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\DataObject;

/**
* Class ShipmentCommentSender
Expand Down Expand Up @@ -71,13 +72,14 @@ public function send(Shipment $shipment, $notify = true, $comment = '')
'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
'formattedBillingAddress' => $this->getFormattedBillingAddress($order),
];
$transport = new DataObject($transport);

$this->eventManager->dispatch(
'email_shipment_comment_set_template_vars_before',
['sender' => $this, 'transport' => $transport]
);

$this->templateContainer->setTemplateVars($transport);
$this->templateContainer->setTemplateVars($transport->getData());

return $this->checkAndSend($order, $notify);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Magento\Sales\Model\ResourceModel\Order\Shipment as ShipmentResource;
use Magento\Sales\Model\Order\Address\Renderer;
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\DataObject;

/**
* Class ShipmentSender
Expand Down Expand Up @@ -113,13 +114,14 @@ public function send(Shipment $shipment, $forceSyncMode = false)
'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
'formattedBillingAddress' => $this->getFormattedBillingAddress($order)
];
$transport = new DataObject($transport);

$this->eventManager->dispatch(
'email_shipment_set_template_vars_before',
['sender' => $this, 'transport' => $transport]
);

$this->templateContainer->setTemplateVars($transport);
$this->templateContainer->setTemplateVars($transport->getData());

if ($this->checkAndSend($order)) {
$shipment->setEmailSent(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use Magento\Sales\Model\Order\Email\Sender;
use Magento\Sales\Model\Order\Invoice\SenderInterface;
use Magento\Framework\DataObject;

/**
* Email notification sender for Invoice.
Expand Down Expand Up @@ -106,13 +107,14 @@ public function send(
'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
'formattedBillingAddress' => $this->getFormattedBillingAddress($order),
];
$transport = new DataObject($transport);

$this->eventManager->dispatch(
'email_invoice_set_template_vars_before',
['sender' => $this, 'transport' => $transport]
);

$this->templateContainer->setTemplateVars($transport);
$this->templateContainer->setTemplateVars($transport->getData());

if ($this->checkAndSend($order)) {
$invoice->setEmailSent(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use Magento\Sales\Model\Order\Email\Sender;
use Magento\Sales\Model\Order\Shipment\SenderInterface;
use Magento\Framework\DataObject;

/**
* Email notification sender for Shipment.
Expand Down Expand Up @@ -106,13 +107,14 @@ public function send(
'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
'formattedBillingAddress' => $this->getFormattedBillingAddress($order)
];
$transport = new DataObject($transport);

$this->eventManager->dispatch(
'email_shipment_set_template_vars_before',
['sender' => $this, 'transport' => $transport]
);

$this->templateContainer->setTemplateVars($transport);
$this->templateContainer->setTemplateVars($transport->getData());

if ($this->checkAndSend($order)) {
$shipment->setEmailSent(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ public function testSend($configValue, $forceSyncMode, $isComment, $emailSending
'formattedShippingAddress' => 'Formatted address',
'formattedBillingAddress' => 'Formatted address',
];
$transport = new \Magento\Framework\DataObject($transport);

$this->eventManagerMock->expects($this->once())
->method('dispatch')
Expand All @@ -275,7 +276,7 @@ public function testSend($configValue, $forceSyncMode, $isComment, $emailSending

$this->templateContainerMock->expects($this->once())
->method('setTemplateVars')
->with($transport);
->with($transport->getData());

$this->identityContainerMock->expects($this->once())
->method('isEnabled')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ public function testSend($configValue, $forceSyncMode, $isComment, $emailSending
'formattedShippingAddress' => 'Formatted address',
'formattedBillingAddress' => 'Formatted address',
];
$transport = new \Magento\Framework\DataObject($transport);

$this->eventManagerMock->expects($this->once())
->method('dispatch')
Expand All @@ -273,7 +274,7 @@ public function testSend($configValue, $forceSyncMode, $isComment, $emailSending

$this->templateContainerMock->expects($this->once())
->method('setTemplateVars')
->with($transport);
->with($transport->getData());

$this->identityContainerMock->expects($this->once())
->method('isEnabled')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ public function testSend($configValue, $forceSyncMode, $isComment, $emailSending
'formattedShippingAddress' => 'Formatted address',
'formattedBillingAddress' => 'Formatted address',
];
$transport = new \Magento\Framework\DataObject($transport);

$this->eventManagerMock->expects($this->once())
->method('dispatch')
Expand All @@ -275,7 +276,7 @@ public function testSend($configValue, $forceSyncMode, $isComment, $emailSending

$this->templateContainerMock->expects($this->once())
->method('setTemplateVars')
->with($transport);
->with($transport->getData());

$this->identityContainerMock->expects($this->once())
->method('isEnabled')
Expand Down