Error attach pdf to invoce e-mail
I tried to send an invoice email from frontend with pdf attached, by extending InvoiceSender like this:
namespace NamespageModuleModelPluginOrder;
use MagentoSalesModelOrderInvoice;
use MagentoFrameworkDataObject;
use MagentoSalesModelOrder;
class InvoiceSender extends MagentoSalesModelOrderEmailSenderInvoiceSender
{
public function send(Invoice $invoice, $forceSyncMode = false)
{
$invoice->setSendEmail(true);
if (!$this->globalConfig->getValue('sales_email/general/async_sending') || $forceSyncMode) {
$order = $invoice->getOrder();
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
//start attact pdf invoce
$pdf = $objectManager->create('MagentoSalesModelOrderPdfInvoice')->getPdf([$invoice]);
$date = $objectManager->create('MagentoFrameworkStdlibDateTimeDateTime')->date('Y-m-d_H-i-s');
$pdf->render();
$message = $objectManager->get('MagentoFrameworkMailMessage');
$message->createAttachment(
$pdf->render(),
Zend_Mime::TYPE_OCTETSTREAM,
Zend_Mime::DISPOSITION_ATTACHMENT,
Zend_Mime::ENCODING_BASE64,
'invoice-'.$invoice->getId().'.pdf'
);
//end attach pdf invoce
$transport = [
'order' => $order,
'invoice' => $invoice,
'comment' => $invoice->getCustomerNoteNotify() ? $invoice->getCustomerNote() : '',
'billing' => $order->getBillingAddress(),
'payment_html' => $this->getPaymentHtml($order),
'store' => $order->getStore(),
'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
'formattedBillingAddress' => $this->getFormattedBillingAddress($order)
];
$transportObject = new DataObject($transport);
/**
* Event argument `transport` is @deprecated. Use `transportObject` instead.
*/
$this->eventManager->dispatch(
'email_invoice_set_template_vars_before',
['sender' => $this, 'transport' => $transportObject->getData(), 'transportObject' => $transportObject]
);
$this->templateContainer->setTemplateVars($transportObject->getData());
if ($this->checkAndSend($order)) {
$invoice->setEmailSent(true);
$this->invoiceResource->saveAttribute($invoice, ['send_email', 'email_sent']);
return true;
}
return true;
} else {
$invoice->setEmailSent(null);
$this->invoiceResource->saveAttribute($invoice, 'email_sent');
}
$this->invoiceResource->saveAttribute($invoice, 'send_email');
return false;
}
protected function checkAndSend(Order $order)
{
$this->identityContainer->setStore($order->getStore());
$this->prepareTemplate($order);
/** @var SenderBuilder $sender */
$sender = $this->getSender();
try {
$sender->send();
$sender->sendCopyTo();
} catch (Exception $e) {
$this->logger->error($e->getMessage());
}
return true;
}
}
the problem seems occure when getPdf(...)
function being called, and shows an error like this:
1 exception(s): Exception #0
(MagentoFrameworkExceptionValidatorException): Invalid template
file: 'Magento_OfflinePayments::info/pdf/checkmo.phtml' in module:
'Magento_OfflinePayments' block's name: 'infocheckmo_0'
Exception #0 (MagentoFrameworkExceptionValidatorException): Invalid
template file: 'Magento_OfflinePayments::info/pdf/checkmo.phtml' in
module: 'Magento_OfflinePayments' block's name: 'infocheckmo_0'
magento2 invoice pdf attachment
add a comment |
I tried to send an invoice email from frontend with pdf attached, by extending InvoiceSender like this:
namespace NamespageModuleModelPluginOrder;
use MagentoSalesModelOrderInvoice;
use MagentoFrameworkDataObject;
use MagentoSalesModelOrder;
class InvoiceSender extends MagentoSalesModelOrderEmailSenderInvoiceSender
{
public function send(Invoice $invoice, $forceSyncMode = false)
{
$invoice->setSendEmail(true);
if (!$this->globalConfig->getValue('sales_email/general/async_sending') || $forceSyncMode) {
$order = $invoice->getOrder();
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
//start attact pdf invoce
$pdf = $objectManager->create('MagentoSalesModelOrderPdfInvoice')->getPdf([$invoice]);
$date = $objectManager->create('MagentoFrameworkStdlibDateTimeDateTime')->date('Y-m-d_H-i-s');
$pdf->render();
$message = $objectManager->get('MagentoFrameworkMailMessage');
$message->createAttachment(
$pdf->render(),
Zend_Mime::TYPE_OCTETSTREAM,
Zend_Mime::DISPOSITION_ATTACHMENT,
Zend_Mime::ENCODING_BASE64,
'invoice-'.$invoice->getId().'.pdf'
);
//end attach pdf invoce
$transport = [
'order' => $order,
'invoice' => $invoice,
'comment' => $invoice->getCustomerNoteNotify() ? $invoice->getCustomerNote() : '',
'billing' => $order->getBillingAddress(),
'payment_html' => $this->getPaymentHtml($order),
'store' => $order->getStore(),
'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
'formattedBillingAddress' => $this->getFormattedBillingAddress($order)
];
$transportObject = new DataObject($transport);
/**
* Event argument `transport` is @deprecated. Use `transportObject` instead.
*/
$this->eventManager->dispatch(
'email_invoice_set_template_vars_before',
['sender' => $this, 'transport' => $transportObject->getData(), 'transportObject' => $transportObject]
);
$this->templateContainer->setTemplateVars($transportObject->getData());
if ($this->checkAndSend($order)) {
$invoice->setEmailSent(true);
$this->invoiceResource->saveAttribute($invoice, ['send_email', 'email_sent']);
return true;
}
return true;
} else {
$invoice->setEmailSent(null);
$this->invoiceResource->saveAttribute($invoice, 'email_sent');
}
$this->invoiceResource->saveAttribute($invoice, 'send_email');
return false;
}
protected function checkAndSend(Order $order)
{
$this->identityContainer->setStore($order->getStore());
$this->prepareTemplate($order);
/** @var SenderBuilder $sender */
$sender = $this->getSender();
try {
$sender->send();
$sender->sendCopyTo();
} catch (Exception $e) {
$this->logger->error($e->getMessage());
}
return true;
}
}
the problem seems occure when getPdf(...)
function being called, and shows an error like this:
1 exception(s): Exception #0
(MagentoFrameworkExceptionValidatorException): Invalid template
file: 'Magento_OfflinePayments::info/pdf/checkmo.phtml' in module:
'Magento_OfflinePayments' block's name: 'infocheckmo_0'
Exception #0 (MagentoFrameworkExceptionValidatorException): Invalid
template file: 'Magento_OfflinePayments::info/pdf/checkmo.phtml' in
module: 'Magento_OfflinePayments' block's name: 'infocheckmo_0'
magento2 invoice pdf attachment
add a comment |
I tried to send an invoice email from frontend with pdf attached, by extending InvoiceSender like this:
namespace NamespageModuleModelPluginOrder;
use MagentoSalesModelOrderInvoice;
use MagentoFrameworkDataObject;
use MagentoSalesModelOrder;
class InvoiceSender extends MagentoSalesModelOrderEmailSenderInvoiceSender
{
public function send(Invoice $invoice, $forceSyncMode = false)
{
$invoice->setSendEmail(true);
if (!$this->globalConfig->getValue('sales_email/general/async_sending') || $forceSyncMode) {
$order = $invoice->getOrder();
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
//start attact pdf invoce
$pdf = $objectManager->create('MagentoSalesModelOrderPdfInvoice')->getPdf([$invoice]);
$date = $objectManager->create('MagentoFrameworkStdlibDateTimeDateTime')->date('Y-m-d_H-i-s');
$pdf->render();
$message = $objectManager->get('MagentoFrameworkMailMessage');
$message->createAttachment(
$pdf->render(),
Zend_Mime::TYPE_OCTETSTREAM,
Zend_Mime::DISPOSITION_ATTACHMENT,
Zend_Mime::ENCODING_BASE64,
'invoice-'.$invoice->getId().'.pdf'
);
//end attach pdf invoce
$transport = [
'order' => $order,
'invoice' => $invoice,
'comment' => $invoice->getCustomerNoteNotify() ? $invoice->getCustomerNote() : '',
'billing' => $order->getBillingAddress(),
'payment_html' => $this->getPaymentHtml($order),
'store' => $order->getStore(),
'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
'formattedBillingAddress' => $this->getFormattedBillingAddress($order)
];
$transportObject = new DataObject($transport);
/**
* Event argument `transport` is @deprecated. Use `transportObject` instead.
*/
$this->eventManager->dispatch(
'email_invoice_set_template_vars_before',
['sender' => $this, 'transport' => $transportObject->getData(), 'transportObject' => $transportObject]
);
$this->templateContainer->setTemplateVars($transportObject->getData());
if ($this->checkAndSend($order)) {
$invoice->setEmailSent(true);
$this->invoiceResource->saveAttribute($invoice, ['send_email', 'email_sent']);
return true;
}
return true;
} else {
$invoice->setEmailSent(null);
$this->invoiceResource->saveAttribute($invoice, 'email_sent');
}
$this->invoiceResource->saveAttribute($invoice, 'send_email');
return false;
}
protected function checkAndSend(Order $order)
{
$this->identityContainer->setStore($order->getStore());
$this->prepareTemplate($order);
/** @var SenderBuilder $sender */
$sender = $this->getSender();
try {
$sender->send();
$sender->sendCopyTo();
} catch (Exception $e) {
$this->logger->error($e->getMessage());
}
return true;
}
}
the problem seems occure when getPdf(...)
function being called, and shows an error like this:
1 exception(s): Exception #0
(MagentoFrameworkExceptionValidatorException): Invalid template
file: 'Magento_OfflinePayments::info/pdf/checkmo.phtml' in module:
'Magento_OfflinePayments' block's name: 'infocheckmo_0'
Exception #0 (MagentoFrameworkExceptionValidatorException): Invalid
template file: 'Magento_OfflinePayments::info/pdf/checkmo.phtml' in
module: 'Magento_OfflinePayments' block's name: 'infocheckmo_0'
magento2 invoice pdf attachment
I tried to send an invoice email from frontend with pdf attached, by extending InvoiceSender like this:
namespace NamespageModuleModelPluginOrder;
use MagentoSalesModelOrderInvoice;
use MagentoFrameworkDataObject;
use MagentoSalesModelOrder;
class InvoiceSender extends MagentoSalesModelOrderEmailSenderInvoiceSender
{
public function send(Invoice $invoice, $forceSyncMode = false)
{
$invoice->setSendEmail(true);
if (!$this->globalConfig->getValue('sales_email/general/async_sending') || $forceSyncMode) {
$order = $invoice->getOrder();
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
//start attact pdf invoce
$pdf = $objectManager->create('MagentoSalesModelOrderPdfInvoice')->getPdf([$invoice]);
$date = $objectManager->create('MagentoFrameworkStdlibDateTimeDateTime')->date('Y-m-d_H-i-s');
$pdf->render();
$message = $objectManager->get('MagentoFrameworkMailMessage');
$message->createAttachment(
$pdf->render(),
Zend_Mime::TYPE_OCTETSTREAM,
Zend_Mime::DISPOSITION_ATTACHMENT,
Zend_Mime::ENCODING_BASE64,
'invoice-'.$invoice->getId().'.pdf'
);
//end attach pdf invoce
$transport = [
'order' => $order,
'invoice' => $invoice,
'comment' => $invoice->getCustomerNoteNotify() ? $invoice->getCustomerNote() : '',
'billing' => $order->getBillingAddress(),
'payment_html' => $this->getPaymentHtml($order),
'store' => $order->getStore(),
'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
'formattedBillingAddress' => $this->getFormattedBillingAddress($order)
];
$transportObject = new DataObject($transport);
/**
* Event argument `transport` is @deprecated. Use `transportObject` instead.
*/
$this->eventManager->dispatch(
'email_invoice_set_template_vars_before',
['sender' => $this, 'transport' => $transportObject->getData(), 'transportObject' => $transportObject]
);
$this->templateContainer->setTemplateVars($transportObject->getData());
if ($this->checkAndSend($order)) {
$invoice->setEmailSent(true);
$this->invoiceResource->saveAttribute($invoice, ['send_email', 'email_sent']);
return true;
}
return true;
} else {
$invoice->setEmailSent(null);
$this->invoiceResource->saveAttribute($invoice, 'email_sent');
}
$this->invoiceResource->saveAttribute($invoice, 'send_email');
return false;
}
protected function checkAndSend(Order $order)
{
$this->identityContainer->setStore($order->getStore());
$this->prepareTemplate($order);
/** @var SenderBuilder $sender */
$sender = $this->getSender();
try {
$sender->send();
$sender->sendCopyTo();
} catch (Exception $e) {
$this->logger->error($e->getMessage());
}
return true;
}
}
the problem seems occure when getPdf(...)
function being called, and shows an error like this:
1 exception(s): Exception #0
(MagentoFrameworkExceptionValidatorException): Invalid template
file: 'Magento_OfflinePayments::info/pdf/checkmo.phtml' in module:
'Magento_OfflinePayments' block's name: 'infocheckmo_0'
Exception #0 (MagentoFrameworkExceptionValidatorException): Invalid
template file: 'Magento_OfflinePayments::info/pdf/checkmo.phtml' in
module: 'Magento_OfflinePayments' block's name: 'infocheckmo_0'
magento2 invoice pdf attachment
magento2 invoice pdf attachment
edited Aug 29 '18 at 9:46
mileven
asked Aug 29 '18 at 9:31
milevenmileven
1697
1697
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Magento_OfflinePayments::info/pdf/checkmo.phtml file cannot be found.
This is due to a Core bug in 2.1, 2.2, maybe 2.3. Create a plugin to fix it :
In appcodeNamespaceModuleetcdi.xml
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoOfflinePaymentsBlockInfoCheckmo">
<plugin sortOrder="1" name="namespaceModuleCheckmo" type="NamespaceModulePluginBlockInfoCheckmoPlugin"/>
</type>
</config>
In appcodeNamespaceModulePluginBlockInfoCheckmoPlugin.php
<?php
namespace NamespaceModulePluginBlockInfo;
/**
* Class CheckmoPlugin
* @package NamespaceModulePluginBlockInfo
*/
class CheckmoPlugin
{
/**
* @param MagentoOfflinePaymentsBlockInfoCheckmo $subject
* @param callable $proceed
*/
public function aroundToPdf(MagentoOfflinePaymentsBlockInfoCheckmo $subject, callable $proceed)
{
return __('Check / Money order');
}
}
Finally, in command line :
php bin/magento setup:di:compile
php bin/magento setup:upgrade
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f240043%2ferror-attach-pdf-to-invoce-e-mail%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Magento_OfflinePayments::info/pdf/checkmo.phtml file cannot be found.
This is due to a Core bug in 2.1, 2.2, maybe 2.3. Create a plugin to fix it :
In appcodeNamespaceModuleetcdi.xml
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoOfflinePaymentsBlockInfoCheckmo">
<plugin sortOrder="1" name="namespaceModuleCheckmo" type="NamespaceModulePluginBlockInfoCheckmoPlugin"/>
</type>
</config>
In appcodeNamespaceModulePluginBlockInfoCheckmoPlugin.php
<?php
namespace NamespaceModulePluginBlockInfo;
/**
* Class CheckmoPlugin
* @package NamespaceModulePluginBlockInfo
*/
class CheckmoPlugin
{
/**
* @param MagentoOfflinePaymentsBlockInfoCheckmo $subject
* @param callable $proceed
*/
public function aroundToPdf(MagentoOfflinePaymentsBlockInfoCheckmo $subject, callable $proceed)
{
return __('Check / Money order');
}
}
Finally, in command line :
php bin/magento setup:di:compile
php bin/magento setup:upgrade
add a comment |
Magento_OfflinePayments::info/pdf/checkmo.phtml file cannot be found.
This is due to a Core bug in 2.1, 2.2, maybe 2.3. Create a plugin to fix it :
In appcodeNamespaceModuleetcdi.xml
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoOfflinePaymentsBlockInfoCheckmo">
<plugin sortOrder="1" name="namespaceModuleCheckmo" type="NamespaceModulePluginBlockInfoCheckmoPlugin"/>
</type>
</config>
In appcodeNamespaceModulePluginBlockInfoCheckmoPlugin.php
<?php
namespace NamespaceModulePluginBlockInfo;
/**
* Class CheckmoPlugin
* @package NamespaceModulePluginBlockInfo
*/
class CheckmoPlugin
{
/**
* @param MagentoOfflinePaymentsBlockInfoCheckmo $subject
* @param callable $proceed
*/
public function aroundToPdf(MagentoOfflinePaymentsBlockInfoCheckmo $subject, callable $proceed)
{
return __('Check / Money order');
}
}
Finally, in command line :
php bin/magento setup:di:compile
php bin/magento setup:upgrade
add a comment |
Magento_OfflinePayments::info/pdf/checkmo.phtml file cannot be found.
This is due to a Core bug in 2.1, 2.2, maybe 2.3. Create a plugin to fix it :
In appcodeNamespaceModuleetcdi.xml
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoOfflinePaymentsBlockInfoCheckmo">
<plugin sortOrder="1" name="namespaceModuleCheckmo" type="NamespaceModulePluginBlockInfoCheckmoPlugin"/>
</type>
</config>
In appcodeNamespaceModulePluginBlockInfoCheckmoPlugin.php
<?php
namespace NamespaceModulePluginBlockInfo;
/**
* Class CheckmoPlugin
* @package NamespaceModulePluginBlockInfo
*/
class CheckmoPlugin
{
/**
* @param MagentoOfflinePaymentsBlockInfoCheckmo $subject
* @param callable $proceed
*/
public function aroundToPdf(MagentoOfflinePaymentsBlockInfoCheckmo $subject, callable $proceed)
{
return __('Check / Money order');
}
}
Finally, in command line :
php bin/magento setup:di:compile
php bin/magento setup:upgrade
Magento_OfflinePayments::info/pdf/checkmo.phtml file cannot be found.
This is due to a Core bug in 2.1, 2.2, maybe 2.3. Create a plugin to fix it :
In appcodeNamespaceModuleetcdi.xml
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoOfflinePaymentsBlockInfoCheckmo">
<plugin sortOrder="1" name="namespaceModuleCheckmo" type="NamespaceModulePluginBlockInfoCheckmoPlugin"/>
</type>
</config>
In appcodeNamespaceModulePluginBlockInfoCheckmoPlugin.php
<?php
namespace NamespaceModulePluginBlockInfo;
/**
* Class CheckmoPlugin
* @package NamespaceModulePluginBlockInfo
*/
class CheckmoPlugin
{
/**
* @param MagentoOfflinePaymentsBlockInfoCheckmo $subject
* @param callable $proceed
*/
public function aroundToPdf(MagentoOfflinePaymentsBlockInfoCheckmo $subject, callable $proceed)
{
return __('Check / Money order');
}
}
Finally, in command line :
php bin/magento setup:di:compile
php bin/magento setup:upgrade
edited yesterday
answered yesterday
Antoine MartinAntoine Martin
663
663
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f240043%2ferror-attach-pdf-to-invoce-e-mail%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown