Magento 2 - Error when I try to override OrderSender classmain.CRITICAL: Plugin class doesn't existMagento 2: How to override newsletter Subscriber modelOverride model function Magento 2How to overwrite AhimsaSalesModelOrderEmailSenderOrderSender in M2?Magento 2.3 email attachment not working while sending custom email
Cooking Scrambled Eggs
Why error propagation in CBC mode encryption affect two blocks?
Why does Windows store Wi-Fi passwords in a reversible format?
What is the best way to solve this 6x6 sudoku?
Contours of a national emergency in the United States
Why is the winner of Pow different everytime?
Can you board the plane when your passport is valid less than 3 months?
Why does a sticker slowly peel off, but if it is pulled quickly it tears?
1mth baby boy keeps peeing through diapers, sometimes diper seems practically unused
Talk interpreter
How is linear momentum conserved in case of a freely falling body?
Disk usage of integer column vs boolean column in Postgres
Did Dr. Hannibal Lecter like Clarice or was he attracted to her?
Papers on arXiv solving the same problem at the same time
How much does Commander Data weigh?
Given current technology, could TV display screens double as video camera sensors?
50-move rule: only the last 50 or any consecutive 50?
What is this fighter jet at Weymouth NAS?
Set orthographic view using python?
Which old Technic set included large yellow motor?
Weird corners with cline
What does it take for witness testimony to be believed?
Did Israelites who stayed in Egypt become halachically Jewish?
What's special ammo in Destiny 2?
Magento 2 - Error when I try to override OrderSender class
main.CRITICAL: Plugin class doesn't existMagento 2: How to override newsletter Subscriber modelOverride model function Magento 2How to overwrite AhimsaSalesModelOrderEmailSenderOrderSender in M2?Magento 2.3 email attachment not working while sending custom email
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a problem when I want to override the class OrderSender of the transactional mail.
I want to know if the order was paid by a custom payment method 'quotation', so I modify the class, it works if I modify in the vendor, but now I want to override in my custom module but I have this error
"Type Error occurred when creating object: MagentoAuthorizenetModelDirectpostInterceptor"
Can you help me?
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace OpsKgOrderModelOrderEmailSender;
use MagentoPaymentHelperData as PaymentHelper;
use MagentoSalesModelOrder;
use MagentoSalesModelOrderEmailContainerOrderIdentity;
use MagentoSalesModelOrderEmailContainerTemplate;
use MagentoSalesModelOrderEmailSender;
use MagentoSalesModelResourceModelOrder as OrderResource;
use MagentoSalesModelOrderAddressRenderer;
use MagentoFrameworkEventManagerInterface;
use MagentoFrameworkDataObject;
use OpsKgOrderHelperOrder as OrderHelper;
/**
* Class OrderSender
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class OrderSender extends Sender
/**
* @var PaymentHelper
*/
protected $paymentHelper;
/**
* @var OrderResource
*/
protected $orderResource;
/**
* @var OrderHelper
*/
protected $orderHelper;
/**
* Global configuration storage.
*
* @var MagentoFrameworkAppConfigScopeConfigInterface
*/
protected $globalConfig;
/**
* @var Renderer
*/
protected $addressRenderer;
/**
* Application Event Dispatcher
*
* @var ManagerInterface
*/
protected $eventManager;
/**
* @param Template $templateContainer
* @param OrderIdentity $identityContainer
* @param OrderEmailSenderBuilderFactory $senderBuilderFactory
* @param PsrLogLoggerInterface $logger
* @param Renderer $addressRenderer
* @param PaymentHelper $paymentHelper
* @param OrderResource $orderResource
* @param MagentoFrameworkAppConfigScopeConfigInterface $globalConfig
* @param ManagerInterface $eventManager
*/
public function __construct(
Template $templateContainer,
OrderIdentity $identityContainer,
MagentoSalesModelOrderEmailSenderBuilderFactory $senderBuilderFactory,
PsrLogLoggerInterface $logger,
Renderer $addressRenderer,
PaymentHelper $paymentHelper,
OrderResource $orderResource,
MagentoFrameworkAppConfigScopeConfigInterface $globalConfig,
ManagerInterface $eventManager,
OrderHelper $orderHelper
)
parent::__construct($templateContainer, $identityContainer, $senderBuilderFactory, $logger, $addressRenderer);
$this->paymentHelper = $paymentHelper;
$this->orderResource = $orderResource;
$this->globalConfig = $globalConfig;
$this->addressRenderer = $addressRenderer;
$this->eventManager = $eventManager;
$this->orderHelper = $orderHelper;
/**
* Sends order email to the customer.
*
* Email will be sent immediately in two cases:
*
* - if asynchronous email sending is disabled in global settings
* - if $forceSyncMode parameter is set to TRUE
*
* Otherwise, email will be sent later during running of
* corresponding cron job.
*
* @param Order $order
* @param bool $forceSyncMode
* @return bool
*/
public function send(Order $order, $forceSyncMode = false)
$forceSyncMode)
if ($this->checkAndSend($order))
$order->setEmailSent(true);
$this->orderResource->saveAttribute($order, ['send_email', 'email_sent']);
return true;
else
$order->setEmailSent(null);
$this->orderResource->saveAttribute($order, 'email_sent');
$this->orderResource->saveAttribute($order, 'send_email');
return false;
/**
* Prepare email template with variables
*
* @param Order $order
* @return void
*/
protected function prepareTemplate(Order $order)
$transport = [
'order' => $order,
'isquotation' => ($this->orderHelper->isQuotation($order)) ? ($this->orderHelper->isQuotation($order)) : false,
'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_order_set_template_vars_before',
['sender' => $this, 'transport' => $transportObject, 'transportObject' => $transportObject]
);
$this->templateContainer->setTemplateVars($transportObject->getData());
parent::prepareTemplate($order);
/**
* Get payment info block as html
*
* @param Order $order
* @return string
*/
protected function getPaymentHtml(Order $order)
return $this->paymentHelper->getInfoBlockHtml(
$order->getPayment(),
$this->identityContainer->getStore()->getStoreId()
);
and in the di.xml
<preference for="MagentoSalesModelOrderEmailSenderOrderSender" type="OpsKgOrderModelOrderEmailSenderOrderSender"/>
magento2 email-templates order-email
add a comment |
I have a problem when I want to override the class OrderSender of the transactional mail.
I want to know if the order was paid by a custom payment method 'quotation', so I modify the class, it works if I modify in the vendor, but now I want to override in my custom module but I have this error
"Type Error occurred when creating object: MagentoAuthorizenetModelDirectpostInterceptor"
Can you help me?
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace OpsKgOrderModelOrderEmailSender;
use MagentoPaymentHelperData as PaymentHelper;
use MagentoSalesModelOrder;
use MagentoSalesModelOrderEmailContainerOrderIdentity;
use MagentoSalesModelOrderEmailContainerTemplate;
use MagentoSalesModelOrderEmailSender;
use MagentoSalesModelResourceModelOrder as OrderResource;
use MagentoSalesModelOrderAddressRenderer;
use MagentoFrameworkEventManagerInterface;
use MagentoFrameworkDataObject;
use OpsKgOrderHelperOrder as OrderHelper;
/**
* Class OrderSender
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class OrderSender extends Sender
/**
* @var PaymentHelper
*/
protected $paymentHelper;
/**
* @var OrderResource
*/
protected $orderResource;
/**
* @var OrderHelper
*/
protected $orderHelper;
/**
* Global configuration storage.
*
* @var MagentoFrameworkAppConfigScopeConfigInterface
*/
protected $globalConfig;
/**
* @var Renderer
*/
protected $addressRenderer;
/**
* Application Event Dispatcher
*
* @var ManagerInterface
*/
protected $eventManager;
/**
* @param Template $templateContainer
* @param OrderIdentity $identityContainer
* @param OrderEmailSenderBuilderFactory $senderBuilderFactory
* @param PsrLogLoggerInterface $logger
* @param Renderer $addressRenderer
* @param PaymentHelper $paymentHelper
* @param OrderResource $orderResource
* @param MagentoFrameworkAppConfigScopeConfigInterface $globalConfig
* @param ManagerInterface $eventManager
*/
public function __construct(
Template $templateContainer,
OrderIdentity $identityContainer,
MagentoSalesModelOrderEmailSenderBuilderFactory $senderBuilderFactory,
PsrLogLoggerInterface $logger,
Renderer $addressRenderer,
PaymentHelper $paymentHelper,
OrderResource $orderResource,
MagentoFrameworkAppConfigScopeConfigInterface $globalConfig,
ManagerInterface $eventManager,
OrderHelper $orderHelper
)
parent::__construct($templateContainer, $identityContainer, $senderBuilderFactory, $logger, $addressRenderer);
$this->paymentHelper = $paymentHelper;
$this->orderResource = $orderResource;
$this->globalConfig = $globalConfig;
$this->addressRenderer = $addressRenderer;
$this->eventManager = $eventManager;
$this->orderHelper = $orderHelper;
/**
* Sends order email to the customer.
*
* Email will be sent immediately in two cases:
*
* - if asynchronous email sending is disabled in global settings
* - if $forceSyncMode parameter is set to TRUE
*
* Otherwise, email will be sent later during running of
* corresponding cron job.
*
* @param Order $order
* @param bool $forceSyncMode
* @return bool
*/
public function send(Order $order, $forceSyncMode = false)
$forceSyncMode)
if ($this->checkAndSend($order))
$order->setEmailSent(true);
$this->orderResource->saveAttribute($order, ['send_email', 'email_sent']);
return true;
else
$order->setEmailSent(null);
$this->orderResource->saveAttribute($order, 'email_sent');
$this->orderResource->saveAttribute($order, 'send_email');
return false;
/**
* Prepare email template with variables
*
* @param Order $order
* @return void
*/
protected function prepareTemplate(Order $order)
$transport = [
'order' => $order,
'isquotation' => ($this->orderHelper->isQuotation($order)) ? ($this->orderHelper->isQuotation($order)) : false,
'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_order_set_template_vars_before',
['sender' => $this, 'transport' => $transportObject, 'transportObject' => $transportObject]
);
$this->templateContainer->setTemplateVars($transportObject->getData());
parent::prepareTemplate($order);
/**
* Get payment info block as html
*
* @param Order $order
* @return string
*/
protected function getPaymentHtml(Order $order)
return $this->paymentHelper->getInfoBlockHtml(
$order->getPayment(),
$this->identityContainer->getStore()->getStoreId()
);
and in the di.xml
<preference for="MagentoSalesModelOrderEmailSenderOrderSender" type="OpsKgOrderModelOrderEmailSenderOrderSender"/>
magento2 email-templates order-email
Try a setup:upgrade to clean your generated files.
– Tsita
Aug 14 at 12:52
I try it but doesn't work...
– Robert S.
Aug 14 at 12:52
What about this line of code $this->addressRenderer = $addressRenderer; Do you need it? Because the same instance is happening in parent constructor.
– Tsita
Aug 14 at 12:55
I only need to rewrite the protected function prepareTemplate(Order $order)
– Robert S.
Aug 14 at 12:57
add a comment |
I have a problem when I want to override the class OrderSender of the transactional mail.
I want to know if the order was paid by a custom payment method 'quotation', so I modify the class, it works if I modify in the vendor, but now I want to override in my custom module but I have this error
"Type Error occurred when creating object: MagentoAuthorizenetModelDirectpostInterceptor"
Can you help me?
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace OpsKgOrderModelOrderEmailSender;
use MagentoPaymentHelperData as PaymentHelper;
use MagentoSalesModelOrder;
use MagentoSalesModelOrderEmailContainerOrderIdentity;
use MagentoSalesModelOrderEmailContainerTemplate;
use MagentoSalesModelOrderEmailSender;
use MagentoSalesModelResourceModelOrder as OrderResource;
use MagentoSalesModelOrderAddressRenderer;
use MagentoFrameworkEventManagerInterface;
use MagentoFrameworkDataObject;
use OpsKgOrderHelperOrder as OrderHelper;
/**
* Class OrderSender
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class OrderSender extends Sender
/**
* @var PaymentHelper
*/
protected $paymentHelper;
/**
* @var OrderResource
*/
protected $orderResource;
/**
* @var OrderHelper
*/
protected $orderHelper;
/**
* Global configuration storage.
*
* @var MagentoFrameworkAppConfigScopeConfigInterface
*/
protected $globalConfig;
/**
* @var Renderer
*/
protected $addressRenderer;
/**
* Application Event Dispatcher
*
* @var ManagerInterface
*/
protected $eventManager;
/**
* @param Template $templateContainer
* @param OrderIdentity $identityContainer
* @param OrderEmailSenderBuilderFactory $senderBuilderFactory
* @param PsrLogLoggerInterface $logger
* @param Renderer $addressRenderer
* @param PaymentHelper $paymentHelper
* @param OrderResource $orderResource
* @param MagentoFrameworkAppConfigScopeConfigInterface $globalConfig
* @param ManagerInterface $eventManager
*/
public function __construct(
Template $templateContainer,
OrderIdentity $identityContainer,
MagentoSalesModelOrderEmailSenderBuilderFactory $senderBuilderFactory,
PsrLogLoggerInterface $logger,
Renderer $addressRenderer,
PaymentHelper $paymentHelper,
OrderResource $orderResource,
MagentoFrameworkAppConfigScopeConfigInterface $globalConfig,
ManagerInterface $eventManager,
OrderHelper $orderHelper
)
parent::__construct($templateContainer, $identityContainer, $senderBuilderFactory, $logger, $addressRenderer);
$this->paymentHelper = $paymentHelper;
$this->orderResource = $orderResource;
$this->globalConfig = $globalConfig;
$this->addressRenderer = $addressRenderer;
$this->eventManager = $eventManager;
$this->orderHelper = $orderHelper;
/**
* Sends order email to the customer.
*
* Email will be sent immediately in two cases:
*
* - if asynchronous email sending is disabled in global settings
* - if $forceSyncMode parameter is set to TRUE
*
* Otherwise, email will be sent later during running of
* corresponding cron job.
*
* @param Order $order
* @param bool $forceSyncMode
* @return bool
*/
public function send(Order $order, $forceSyncMode = false)
$forceSyncMode)
if ($this->checkAndSend($order))
$order->setEmailSent(true);
$this->orderResource->saveAttribute($order, ['send_email', 'email_sent']);
return true;
else
$order->setEmailSent(null);
$this->orderResource->saveAttribute($order, 'email_sent');
$this->orderResource->saveAttribute($order, 'send_email');
return false;
/**
* Prepare email template with variables
*
* @param Order $order
* @return void
*/
protected function prepareTemplate(Order $order)
$transport = [
'order' => $order,
'isquotation' => ($this->orderHelper->isQuotation($order)) ? ($this->orderHelper->isQuotation($order)) : false,
'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_order_set_template_vars_before',
['sender' => $this, 'transport' => $transportObject, 'transportObject' => $transportObject]
);
$this->templateContainer->setTemplateVars($transportObject->getData());
parent::prepareTemplate($order);
/**
* Get payment info block as html
*
* @param Order $order
* @return string
*/
protected function getPaymentHtml(Order $order)
return $this->paymentHelper->getInfoBlockHtml(
$order->getPayment(),
$this->identityContainer->getStore()->getStoreId()
);
and in the di.xml
<preference for="MagentoSalesModelOrderEmailSenderOrderSender" type="OpsKgOrderModelOrderEmailSenderOrderSender"/>
magento2 email-templates order-email
I have a problem when I want to override the class OrderSender of the transactional mail.
I want to know if the order was paid by a custom payment method 'quotation', so I modify the class, it works if I modify in the vendor, but now I want to override in my custom module but I have this error
"Type Error occurred when creating object: MagentoAuthorizenetModelDirectpostInterceptor"
Can you help me?
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace OpsKgOrderModelOrderEmailSender;
use MagentoPaymentHelperData as PaymentHelper;
use MagentoSalesModelOrder;
use MagentoSalesModelOrderEmailContainerOrderIdentity;
use MagentoSalesModelOrderEmailContainerTemplate;
use MagentoSalesModelOrderEmailSender;
use MagentoSalesModelResourceModelOrder as OrderResource;
use MagentoSalesModelOrderAddressRenderer;
use MagentoFrameworkEventManagerInterface;
use MagentoFrameworkDataObject;
use OpsKgOrderHelperOrder as OrderHelper;
/**
* Class OrderSender
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class OrderSender extends Sender
/**
* @var PaymentHelper
*/
protected $paymentHelper;
/**
* @var OrderResource
*/
protected $orderResource;
/**
* @var OrderHelper
*/
protected $orderHelper;
/**
* Global configuration storage.
*
* @var MagentoFrameworkAppConfigScopeConfigInterface
*/
protected $globalConfig;
/**
* @var Renderer
*/
protected $addressRenderer;
/**
* Application Event Dispatcher
*
* @var ManagerInterface
*/
protected $eventManager;
/**
* @param Template $templateContainer
* @param OrderIdentity $identityContainer
* @param OrderEmailSenderBuilderFactory $senderBuilderFactory
* @param PsrLogLoggerInterface $logger
* @param Renderer $addressRenderer
* @param PaymentHelper $paymentHelper
* @param OrderResource $orderResource
* @param MagentoFrameworkAppConfigScopeConfigInterface $globalConfig
* @param ManagerInterface $eventManager
*/
public function __construct(
Template $templateContainer,
OrderIdentity $identityContainer,
MagentoSalesModelOrderEmailSenderBuilderFactory $senderBuilderFactory,
PsrLogLoggerInterface $logger,
Renderer $addressRenderer,
PaymentHelper $paymentHelper,
OrderResource $orderResource,
MagentoFrameworkAppConfigScopeConfigInterface $globalConfig,
ManagerInterface $eventManager,
OrderHelper $orderHelper
)
parent::__construct($templateContainer, $identityContainer, $senderBuilderFactory, $logger, $addressRenderer);
$this->paymentHelper = $paymentHelper;
$this->orderResource = $orderResource;
$this->globalConfig = $globalConfig;
$this->addressRenderer = $addressRenderer;
$this->eventManager = $eventManager;
$this->orderHelper = $orderHelper;
/**
* Sends order email to the customer.
*
* Email will be sent immediately in two cases:
*
* - if asynchronous email sending is disabled in global settings
* - if $forceSyncMode parameter is set to TRUE
*
* Otherwise, email will be sent later during running of
* corresponding cron job.
*
* @param Order $order
* @param bool $forceSyncMode
* @return bool
*/
public function send(Order $order, $forceSyncMode = false)
$forceSyncMode)
if ($this->checkAndSend($order))
$order->setEmailSent(true);
$this->orderResource->saveAttribute($order, ['send_email', 'email_sent']);
return true;
else
$order->setEmailSent(null);
$this->orderResource->saveAttribute($order, 'email_sent');
$this->orderResource->saveAttribute($order, 'send_email');
return false;
/**
* Prepare email template with variables
*
* @param Order $order
* @return void
*/
protected function prepareTemplate(Order $order)
$transport = [
'order' => $order,
'isquotation' => ($this->orderHelper->isQuotation($order)) ? ($this->orderHelper->isQuotation($order)) : false,
'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_order_set_template_vars_before',
['sender' => $this, 'transport' => $transportObject, 'transportObject' => $transportObject]
);
$this->templateContainer->setTemplateVars($transportObject->getData());
parent::prepareTemplate($order);
/**
* Get payment info block as html
*
* @param Order $order
* @return string
*/
protected function getPaymentHtml(Order $order)
return $this->paymentHelper->getInfoBlockHtml(
$order->getPayment(),
$this->identityContainer->getStore()->getStoreId()
);
and in the di.xml
<preference for="MagentoSalesModelOrderEmailSenderOrderSender" type="OpsKgOrderModelOrderEmailSenderOrderSender"/>
magento2 email-templates order-email
magento2 email-templates order-email
edited Aug 14 at 12:51
Sumit
5131 silver badge14 bronze badges
5131 silver badge14 bronze badges
asked Aug 14 at 12:49
Robert S.Robert S.
226 bronze badges
226 bronze badges
Try a setup:upgrade to clean your generated files.
– Tsita
Aug 14 at 12:52
I try it but doesn't work...
– Robert S.
Aug 14 at 12:52
What about this line of code $this->addressRenderer = $addressRenderer; Do you need it? Because the same instance is happening in parent constructor.
– Tsita
Aug 14 at 12:55
I only need to rewrite the protected function prepareTemplate(Order $order)
– Robert S.
Aug 14 at 12:57
add a comment |
Try a setup:upgrade to clean your generated files.
– Tsita
Aug 14 at 12:52
I try it but doesn't work...
– Robert S.
Aug 14 at 12:52
What about this line of code $this->addressRenderer = $addressRenderer; Do you need it? Because the same instance is happening in parent constructor.
– Tsita
Aug 14 at 12:55
I only need to rewrite the protected function prepareTemplate(Order $order)
– Robert S.
Aug 14 at 12:57
Try a setup:upgrade to clean your generated files.
– Tsita
Aug 14 at 12:52
Try a setup:upgrade to clean your generated files.
– Tsita
Aug 14 at 12:52
I try it but doesn't work...
– Robert S.
Aug 14 at 12:52
I try it but doesn't work...
– Robert S.
Aug 14 at 12:52
What about this line of code $this->addressRenderer = $addressRenderer; Do you need it? Because the same instance is happening in parent constructor.
– Tsita
Aug 14 at 12:55
What about this line of code $this->addressRenderer = $addressRenderer; Do you need it? Because the same instance is happening in parent constructor.
– Tsita
Aug 14 at 12:55
I only need to rewrite the protected function prepareTemplate(Order $order)
– Robert S.
Aug 14 at 12:57
I only need to rewrite the protected function prepareTemplate(Order $order)
– Robert S.
Aug 14 at 12:57
add a comment |
1 Answer
1
active
oldest
votes
The only new variable I see in your code is "isquotation". So I don't think it's neccesary to overwrite all other functions of the OrderSender class as well. I've recently had to check for a specific payment method as well and I only modified the prepareTemplate method.
If I combine this with your code this would be:
<?php
namespace OpsKgOrderModelOrderEmailSender;
use MagentoPaymentHelperData as PaymentHelper;
use MagentoSalesModelOrder;
use MagentoSalesModelOrderEmailContainerOrderIdentity;
use MagentoSalesModelOrderEmailContainerTemplate;
use MagentoSalesModelOrderEmailSender;
use MagentoSalesModelResourceModelOrder as OrderResource;
use MagentoSalesModelOrderAddressRenderer;
use MagentoFrameworkEventManagerInterface;
use OpsKgOrderHelperOrder as OrderHelper;
class OrderSender extends MagentoSalesModelOrderEmailSenderOrderSender
/**
* @var OrderHelper
*/
protected $orderHelper;
public function __construct(
Template $templateContainer,
OrderIdentity $identityContainer,
MagentoSalesModelOrderEmailSenderBuilderFactory $senderBuilderFactory,
PsrLogLoggerInterface $logger,
Renderer $addressRenderer,
PaymentHelper $paymentHelper,
OrderResource $orderResource,
MagentoFrameworkAppConfigScopeConfigInterface $globalConfig,
ManagerInterface $eventManager,
OrderHelper $orderHelper
)
parent::__construct($templateContainer, $identityContainer, $senderBuilderFactory, $logger, $addressRenderer, $paymentHelper, $orderResource, $globalConfig, $eventManager);
$this->orderHelper = $orderHelper;
protected function prepareTemplate(Order $order)
// Call parent
parent::prepareTemplate($order);
// Add isquotation variable
$templateVars = $this->templateContainer->getTemplateVars();
$templateVars['isquotation'] = ($this->orderHelper->isQuotation($order)) ? ($this->orderHelper->isQuotation($order)) : false;
$this->templateContainer->setTemplateVars($templateVars);
It's works ! Thank you, now I can use this condition in my mail template ;) I already change all but I can't add a condition to the subject of the mail, is it possible ?
– Robert S.
Aug 16 at 7:39
Glad it works! Sorry, can't really help you with the subject since I don't have any experience manipulating those outside of the general transactional e-mail management in the backend. But you could use a different template alltogether (with a different subject). ($this->templateContainer->setTemplateId(<your_id>);)
– sduif
Aug 16 at 11:46
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%2f285491%2fmagento-2-error-when-i-try-to-override-ordersender-class%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
The only new variable I see in your code is "isquotation". So I don't think it's neccesary to overwrite all other functions of the OrderSender class as well. I've recently had to check for a specific payment method as well and I only modified the prepareTemplate method.
If I combine this with your code this would be:
<?php
namespace OpsKgOrderModelOrderEmailSender;
use MagentoPaymentHelperData as PaymentHelper;
use MagentoSalesModelOrder;
use MagentoSalesModelOrderEmailContainerOrderIdentity;
use MagentoSalesModelOrderEmailContainerTemplate;
use MagentoSalesModelOrderEmailSender;
use MagentoSalesModelResourceModelOrder as OrderResource;
use MagentoSalesModelOrderAddressRenderer;
use MagentoFrameworkEventManagerInterface;
use OpsKgOrderHelperOrder as OrderHelper;
class OrderSender extends MagentoSalesModelOrderEmailSenderOrderSender
/**
* @var OrderHelper
*/
protected $orderHelper;
public function __construct(
Template $templateContainer,
OrderIdentity $identityContainer,
MagentoSalesModelOrderEmailSenderBuilderFactory $senderBuilderFactory,
PsrLogLoggerInterface $logger,
Renderer $addressRenderer,
PaymentHelper $paymentHelper,
OrderResource $orderResource,
MagentoFrameworkAppConfigScopeConfigInterface $globalConfig,
ManagerInterface $eventManager,
OrderHelper $orderHelper
)
parent::__construct($templateContainer, $identityContainer, $senderBuilderFactory, $logger, $addressRenderer, $paymentHelper, $orderResource, $globalConfig, $eventManager);
$this->orderHelper = $orderHelper;
protected function prepareTemplate(Order $order)
// Call parent
parent::prepareTemplate($order);
// Add isquotation variable
$templateVars = $this->templateContainer->getTemplateVars();
$templateVars['isquotation'] = ($this->orderHelper->isQuotation($order)) ? ($this->orderHelper->isQuotation($order)) : false;
$this->templateContainer->setTemplateVars($templateVars);
It's works ! Thank you, now I can use this condition in my mail template ;) I already change all but I can't add a condition to the subject of the mail, is it possible ?
– Robert S.
Aug 16 at 7:39
Glad it works! Sorry, can't really help you with the subject since I don't have any experience manipulating those outside of the general transactional e-mail management in the backend. But you could use a different template alltogether (with a different subject). ($this->templateContainer->setTemplateId(<your_id>);)
– sduif
Aug 16 at 11:46
add a comment |
The only new variable I see in your code is "isquotation". So I don't think it's neccesary to overwrite all other functions of the OrderSender class as well. I've recently had to check for a specific payment method as well and I only modified the prepareTemplate method.
If I combine this with your code this would be:
<?php
namespace OpsKgOrderModelOrderEmailSender;
use MagentoPaymentHelperData as PaymentHelper;
use MagentoSalesModelOrder;
use MagentoSalesModelOrderEmailContainerOrderIdentity;
use MagentoSalesModelOrderEmailContainerTemplate;
use MagentoSalesModelOrderEmailSender;
use MagentoSalesModelResourceModelOrder as OrderResource;
use MagentoSalesModelOrderAddressRenderer;
use MagentoFrameworkEventManagerInterface;
use OpsKgOrderHelperOrder as OrderHelper;
class OrderSender extends MagentoSalesModelOrderEmailSenderOrderSender
/**
* @var OrderHelper
*/
protected $orderHelper;
public function __construct(
Template $templateContainer,
OrderIdentity $identityContainer,
MagentoSalesModelOrderEmailSenderBuilderFactory $senderBuilderFactory,
PsrLogLoggerInterface $logger,
Renderer $addressRenderer,
PaymentHelper $paymentHelper,
OrderResource $orderResource,
MagentoFrameworkAppConfigScopeConfigInterface $globalConfig,
ManagerInterface $eventManager,
OrderHelper $orderHelper
)
parent::__construct($templateContainer, $identityContainer, $senderBuilderFactory, $logger, $addressRenderer, $paymentHelper, $orderResource, $globalConfig, $eventManager);
$this->orderHelper = $orderHelper;
protected function prepareTemplate(Order $order)
// Call parent
parent::prepareTemplate($order);
// Add isquotation variable
$templateVars = $this->templateContainer->getTemplateVars();
$templateVars['isquotation'] = ($this->orderHelper->isQuotation($order)) ? ($this->orderHelper->isQuotation($order)) : false;
$this->templateContainer->setTemplateVars($templateVars);
It's works ! Thank you, now I can use this condition in my mail template ;) I already change all but I can't add a condition to the subject of the mail, is it possible ?
– Robert S.
Aug 16 at 7:39
Glad it works! Sorry, can't really help you with the subject since I don't have any experience manipulating those outside of the general transactional e-mail management in the backend. But you could use a different template alltogether (with a different subject). ($this->templateContainer->setTemplateId(<your_id>);)
– sduif
Aug 16 at 11:46
add a comment |
The only new variable I see in your code is "isquotation". So I don't think it's neccesary to overwrite all other functions of the OrderSender class as well. I've recently had to check for a specific payment method as well and I only modified the prepareTemplate method.
If I combine this with your code this would be:
<?php
namespace OpsKgOrderModelOrderEmailSender;
use MagentoPaymentHelperData as PaymentHelper;
use MagentoSalesModelOrder;
use MagentoSalesModelOrderEmailContainerOrderIdentity;
use MagentoSalesModelOrderEmailContainerTemplate;
use MagentoSalesModelOrderEmailSender;
use MagentoSalesModelResourceModelOrder as OrderResource;
use MagentoSalesModelOrderAddressRenderer;
use MagentoFrameworkEventManagerInterface;
use OpsKgOrderHelperOrder as OrderHelper;
class OrderSender extends MagentoSalesModelOrderEmailSenderOrderSender
/**
* @var OrderHelper
*/
protected $orderHelper;
public function __construct(
Template $templateContainer,
OrderIdentity $identityContainer,
MagentoSalesModelOrderEmailSenderBuilderFactory $senderBuilderFactory,
PsrLogLoggerInterface $logger,
Renderer $addressRenderer,
PaymentHelper $paymentHelper,
OrderResource $orderResource,
MagentoFrameworkAppConfigScopeConfigInterface $globalConfig,
ManagerInterface $eventManager,
OrderHelper $orderHelper
)
parent::__construct($templateContainer, $identityContainer, $senderBuilderFactory, $logger, $addressRenderer, $paymentHelper, $orderResource, $globalConfig, $eventManager);
$this->orderHelper = $orderHelper;
protected function prepareTemplate(Order $order)
// Call parent
parent::prepareTemplate($order);
// Add isquotation variable
$templateVars = $this->templateContainer->getTemplateVars();
$templateVars['isquotation'] = ($this->orderHelper->isQuotation($order)) ? ($this->orderHelper->isQuotation($order)) : false;
$this->templateContainer->setTemplateVars($templateVars);
The only new variable I see in your code is "isquotation". So I don't think it's neccesary to overwrite all other functions of the OrderSender class as well. I've recently had to check for a specific payment method as well and I only modified the prepareTemplate method.
If I combine this with your code this would be:
<?php
namespace OpsKgOrderModelOrderEmailSender;
use MagentoPaymentHelperData as PaymentHelper;
use MagentoSalesModelOrder;
use MagentoSalesModelOrderEmailContainerOrderIdentity;
use MagentoSalesModelOrderEmailContainerTemplate;
use MagentoSalesModelOrderEmailSender;
use MagentoSalesModelResourceModelOrder as OrderResource;
use MagentoSalesModelOrderAddressRenderer;
use MagentoFrameworkEventManagerInterface;
use OpsKgOrderHelperOrder as OrderHelper;
class OrderSender extends MagentoSalesModelOrderEmailSenderOrderSender
/**
* @var OrderHelper
*/
protected $orderHelper;
public function __construct(
Template $templateContainer,
OrderIdentity $identityContainer,
MagentoSalesModelOrderEmailSenderBuilderFactory $senderBuilderFactory,
PsrLogLoggerInterface $logger,
Renderer $addressRenderer,
PaymentHelper $paymentHelper,
OrderResource $orderResource,
MagentoFrameworkAppConfigScopeConfigInterface $globalConfig,
ManagerInterface $eventManager,
OrderHelper $orderHelper
)
parent::__construct($templateContainer, $identityContainer, $senderBuilderFactory, $logger, $addressRenderer, $paymentHelper, $orderResource, $globalConfig, $eventManager);
$this->orderHelper = $orderHelper;
protected function prepareTemplate(Order $order)
// Call parent
parent::prepareTemplate($order);
// Add isquotation variable
$templateVars = $this->templateContainer->getTemplateVars();
$templateVars['isquotation'] = ($this->orderHelper->isQuotation($order)) ? ($this->orderHelper->isQuotation($order)) : false;
$this->templateContainer->setTemplateVars($templateVars);
answered Aug 15 at 8:16
sduifsduif
5952 silver badges9 bronze badges
5952 silver badges9 bronze badges
It's works ! Thank you, now I can use this condition in my mail template ;) I already change all but I can't add a condition to the subject of the mail, is it possible ?
– Robert S.
Aug 16 at 7:39
Glad it works! Sorry, can't really help you with the subject since I don't have any experience manipulating those outside of the general transactional e-mail management in the backend. But you could use a different template alltogether (with a different subject). ($this->templateContainer->setTemplateId(<your_id>);)
– sduif
Aug 16 at 11:46
add a comment |
It's works ! Thank you, now I can use this condition in my mail template ;) I already change all but I can't add a condition to the subject of the mail, is it possible ?
– Robert S.
Aug 16 at 7:39
Glad it works! Sorry, can't really help you with the subject since I don't have any experience manipulating those outside of the general transactional e-mail management in the backend. But you could use a different template alltogether (with a different subject). ($this->templateContainer->setTemplateId(<your_id>);)
– sduif
Aug 16 at 11:46
It's works ! Thank you, now I can use this condition in my mail template ;) I already change all but I can't add a condition to the subject of the mail, is it possible ?
– Robert S.
Aug 16 at 7:39
It's works ! Thank you, now I can use this condition in my mail template ;) I already change all but I can't add a condition to the subject of the mail, is it possible ?
– Robert S.
Aug 16 at 7:39
Glad it works! Sorry, can't really help you with the subject since I don't have any experience manipulating those outside of the general transactional e-mail management in the backend. But you could use a different template alltogether (with a different subject). ($this->templateContainer->setTemplateId(<your_id>);)
– sduif
Aug 16 at 11:46
Glad it works! Sorry, can't really help you with the subject since I don't have any experience manipulating those outside of the general transactional e-mail management in the backend. But you could use a different template alltogether (with a different subject). ($this->templateContainer->setTemplateId(<your_id>);)
– sduif
Aug 16 at 11:46
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.
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%2f285491%2fmagento-2-error-when-i-try-to-override-ordersender-class%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
Try a setup:upgrade to clean your generated files.
– Tsita
Aug 14 at 12:52
I try it but doesn't work...
– Robert S.
Aug 14 at 12:52
What about this line of code $this->addressRenderer = $addressRenderer; Do you need it? Because the same instance is happening in parent constructor.
– Tsita
Aug 14 at 12:55
I only need to rewrite the protected function prepareTemplate(Order $order)
– Robert S.
Aug 14 at 12:57