Change Email Template On Specific Order Status:Magento2 Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Send Copy of Order Confirmation email programmatically in magento 2Set custom price of product when adding to cart code not workingMagento 2: How to override newsletter Subscriber modelMagento 2 Sending emails triggered by observerMagento 2: Add a product to the cart programmaticallyMagento 2: After custom cookie is created all pages default to home pageI have created one field using product form field for my price i want save my field value at product creation time from backend magento2Magento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 Can't view module's front end page output?Error Database Magento 2.3 migration from localhost to server
Improvising over quartal voicings
How many time has Arya actually used Needle?
How is the policy gradient calculated in REINFORCE?
One-one communication
How do you cope with tons of web fonts when copying and pasting from web pages?
"Destructive power" carried by a B-52?
How do Java 8 default methods hеlp with lambdas?
How to infer difference of population proportion between two groups when proportion is small?
Twin's vs. Twins'
calculator's angle answer for trig ratios that can work in more than 1 quadrant on the unit circle
How do I find my Spellcasting Ability for my D&D character?
Found this skink in my tomato plant bucket. Is he trapped? Or could he leave if he wanted?
Keep at all times, the minus sign above aligned with minus sign below
Why complex landing gears are used instead of simple, reliable and light weight muscle wire or shape memory alloys?
How to achieve cat-like agility?
3D Masyu - A Die
How can I list files in reverse time order by a command and pass them as arguments to another command?
Getting representations of the Lie group out of representations of its Lie algebra
Where did Ptolemy compare the Earth to the distance of fixed stars?
Is there night in Alpha Complex?
How to name indistinguishable henchmen in a screenplay?
NIntegrate on a solution of a matrix ODE
Can gravitational waves pass through a black hole?
Can I cut the hair of a conjured korred with a blade made of precious material to harvest that material from the korred?
Change Email Template On Specific Order Status:Magento2
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?Send Copy of Order Confirmation email programmatically in magento 2Set custom price of product when adding to cart code not workingMagento 2: How to override newsletter Subscriber modelMagento 2 Sending emails triggered by observerMagento 2: Add a product to the cart programmaticallyMagento 2: After custom cookie is created all pages default to home pageI have created one field using product form field for my price i want save my field value at product creation time from backend magento2Magento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 Can't view module's front end page output?Error Database Magento 2.3 migration from localhost to server
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am trying to use different e-mail template for one of my custom order status when the status is changed from the admin.
I have used the event sales_order_save_after
<observer name="sales_order_save_after" instance="HawkOrderFlowObserverSalesOrderSalesOrderAfterSave"/>
And created an observer like follows:
<?php
namespace HawkOrderFlowObserverSalesOrder;
use MagentoFrameworkEventObserver as EventObserver;
use MagentoFrameworkEventObserverInterface;
class SalesOrderAfterSave implements ObserverInterface
/**
* @var MagentoFrameworkAppRequestHttp
*/
protected $_request;
/**
* @var MagentoFrameworkMailTemplateTransportBuilder
*/
protected $_transportBuilder;
/**
* @var MagentoStoreModelStoreManagerInterface
*/
protected $_storeManager;
/**
* For logger, var/log
*/
protected $_logger;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkAppRequestHttp $request,
MagentoFrameworkMailTemplateTransportBuilder $transportBuilder,
MagentoStoreModelStoreManagerInterface $storeManager,
PsrLogLoggerInterface $logger
)
$this->_request = $request;
$this->_transportBuilder = $transportBuilder;
$this->_storeManager = $storeManager;
$this->_logger = $logger;
public function execute(MagentoFrameworkEventObserver $observer)
$order = $observer->getEvent()->getOrder();
$lastOrderId = $order->getId();
$orderStatus = $order->getStatus();
try
if($orderStatus == "viewed_by_admin")
$store = $this->_storeManager->getStore()->getId();
$template = $this->_transportBuilder->setTemplateIdentifier('13') //Where 13 is the Email Template ID created in the admin pannel under the Stores -> Email Templates
->setTemplateOptions(['area' => 'frontend', 'store' => $store]);
return $template;
catch (Exception $e)
$this->_logger->critical($e->getMessage());
return;
Still not using my defined email template rather then still using the default email template from admin configuration, Is there anything I am missing here please guide about it.
Any help will be appreciated.
magento2 php sales-order email-templates order-email
add a comment |
I am trying to use different e-mail template for one of my custom order status when the status is changed from the admin.
I have used the event sales_order_save_after
<observer name="sales_order_save_after" instance="HawkOrderFlowObserverSalesOrderSalesOrderAfterSave"/>
And created an observer like follows:
<?php
namespace HawkOrderFlowObserverSalesOrder;
use MagentoFrameworkEventObserver as EventObserver;
use MagentoFrameworkEventObserverInterface;
class SalesOrderAfterSave implements ObserverInterface
/**
* @var MagentoFrameworkAppRequestHttp
*/
protected $_request;
/**
* @var MagentoFrameworkMailTemplateTransportBuilder
*/
protected $_transportBuilder;
/**
* @var MagentoStoreModelStoreManagerInterface
*/
protected $_storeManager;
/**
* For logger, var/log
*/
protected $_logger;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkAppRequestHttp $request,
MagentoFrameworkMailTemplateTransportBuilder $transportBuilder,
MagentoStoreModelStoreManagerInterface $storeManager,
PsrLogLoggerInterface $logger
)
$this->_request = $request;
$this->_transportBuilder = $transportBuilder;
$this->_storeManager = $storeManager;
$this->_logger = $logger;
public function execute(MagentoFrameworkEventObserver $observer)
$order = $observer->getEvent()->getOrder();
$lastOrderId = $order->getId();
$orderStatus = $order->getStatus();
try
if($orderStatus == "viewed_by_admin")
$store = $this->_storeManager->getStore()->getId();
$template = $this->_transportBuilder->setTemplateIdentifier('13') //Where 13 is the Email Template ID created in the admin pannel under the Stores -> Email Templates
->setTemplateOptions(['area' => 'frontend', 'store' => $store]);
return $template;
catch (Exception $e)
$this->_logger->critical($e->getMessage());
return;
Still not using my defined email template rather then still using the default email template from admin configuration, Is there anything I am missing here please guide about it.
Any help will be appreciated.
magento2 php sales-order email-templates order-email
add a comment |
I am trying to use different e-mail template for one of my custom order status when the status is changed from the admin.
I have used the event sales_order_save_after
<observer name="sales_order_save_after" instance="HawkOrderFlowObserverSalesOrderSalesOrderAfterSave"/>
And created an observer like follows:
<?php
namespace HawkOrderFlowObserverSalesOrder;
use MagentoFrameworkEventObserver as EventObserver;
use MagentoFrameworkEventObserverInterface;
class SalesOrderAfterSave implements ObserverInterface
/**
* @var MagentoFrameworkAppRequestHttp
*/
protected $_request;
/**
* @var MagentoFrameworkMailTemplateTransportBuilder
*/
protected $_transportBuilder;
/**
* @var MagentoStoreModelStoreManagerInterface
*/
protected $_storeManager;
/**
* For logger, var/log
*/
protected $_logger;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkAppRequestHttp $request,
MagentoFrameworkMailTemplateTransportBuilder $transportBuilder,
MagentoStoreModelStoreManagerInterface $storeManager,
PsrLogLoggerInterface $logger
)
$this->_request = $request;
$this->_transportBuilder = $transportBuilder;
$this->_storeManager = $storeManager;
$this->_logger = $logger;
public function execute(MagentoFrameworkEventObserver $observer)
$order = $observer->getEvent()->getOrder();
$lastOrderId = $order->getId();
$orderStatus = $order->getStatus();
try
if($orderStatus == "viewed_by_admin")
$store = $this->_storeManager->getStore()->getId();
$template = $this->_transportBuilder->setTemplateIdentifier('13') //Where 13 is the Email Template ID created in the admin pannel under the Stores -> Email Templates
->setTemplateOptions(['area' => 'frontend', 'store' => $store]);
return $template;
catch (Exception $e)
$this->_logger->critical($e->getMessage());
return;
Still not using my defined email template rather then still using the default email template from admin configuration, Is there anything I am missing here please guide about it.
Any help will be appreciated.
magento2 php sales-order email-templates order-email
I am trying to use different e-mail template for one of my custom order status when the status is changed from the admin.
I have used the event sales_order_save_after
<observer name="sales_order_save_after" instance="HawkOrderFlowObserverSalesOrderSalesOrderAfterSave"/>
And created an observer like follows:
<?php
namespace HawkOrderFlowObserverSalesOrder;
use MagentoFrameworkEventObserver as EventObserver;
use MagentoFrameworkEventObserverInterface;
class SalesOrderAfterSave implements ObserverInterface
/**
* @var MagentoFrameworkAppRequestHttp
*/
protected $_request;
/**
* @var MagentoFrameworkMailTemplateTransportBuilder
*/
protected $_transportBuilder;
/**
* @var MagentoStoreModelStoreManagerInterface
*/
protected $_storeManager;
/**
* For logger, var/log
*/
protected $_logger;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkAppRequestHttp $request,
MagentoFrameworkMailTemplateTransportBuilder $transportBuilder,
MagentoStoreModelStoreManagerInterface $storeManager,
PsrLogLoggerInterface $logger
)
$this->_request = $request;
$this->_transportBuilder = $transportBuilder;
$this->_storeManager = $storeManager;
$this->_logger = $logger;
public function execute(MagentoFrameworkEventObserver $observer)
$order = $observer->getEvent()->getOrder();
$lastOrderId = $order->getId();
$orderStatus = $order->getStatus();
try
if($orderStatus == "viewed_by_admin")
$store = $this->_storeManager->getStore()->getId();
$template = $this->_transportBuilder->setTemplateIdentifier('13') //Where 13 is the Email Template ID created in the admin pannel under the Stores -> Email Templates
->setTemplateOptions(['area' => 'frontend', 'store' => $store]);
return $template;
catch (Exception $e)
$this->_logger->critical($e->getMessage());
return;
Still not using my defined email template rather then still using the default email template from admin configuration, Is there anything I am missing here please guide about it.
Any help will be appreciated.
magento2 php sales-order email-templates order-email
magento2 php sales-order email-templates order-email
edited 2 days ago
Zoo
asked 2 days ago
ZooZoo
136
136
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
It is good and you followed good approach as per M2 standards. It needs some improvement to make it compatible and error-free in a maximum of cases
Exception Handling.
$order = $observer->getEvent()->getOrder(); if( !empty($order) ) // do code here
Naming convention. Do use camel-case for variables.
$order_status
should be$orderStatus
.- It is observer so you won't be able to track if that happened or not so do wrap it in try-catch and log accordingly ( do add a check if logs are enabled or not ).
Thanks for the improvements you have mentioned, i have posted the least code here, Sure i will take and i am taking care of these standards, Can you please check the updated question now and try to answer that, will be appreciated.
– Zoo
2 days ago
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%2f270773%2fchange-email-template-on-specific-order-statusmagento2%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
It is good and you followed good approach as per M2 standards. It needs some improvement to make it compatible and error-free in a maximum of cases
Exception Handling.
$order = $observer->getEvent()->getOrder(); if( !empty($order) ) // do code here
Naming convention. Do use camel-case for variables.
$order_status
should be$orderStatus
.- It is observer so you won't be able to track if that happened or not so do wrap it in try-catch and log accordingly ( do add a check if logs are enabled or not ).
Thanks for the improvements you have mentioned, i have posted the least code here, Sure i will take and i am taking care of these standards, Can you please check the updated question now and try to answer that, will be appreciated.
– Zoo
2 days ago
add a comment |
It is good and you followed good approach as per M2 standards. It needs some improvement to make it compatible and error-free in a maximum of cases
Exception Handling.
$order = $observer->getEvent()->getOrder(); if( !empty($order) ) // do code here
Naming convention. Do use camel-case for variables.
$order_status
should be$orderStatus
.- It is observer so you won't be able to track if that happened or not so do wrap it in try-catch and log accordingly ( do add a check if logs are enabled or not ).
Thanks for the improvements you have mentioned, i have posted the least code here, Sure i will take and i am taking care of these standards, Can you please check the updated question now and try to answer that, will be appreciated.
– Zoo
2 days ago
add a comment |
It is good and you followed good approach as per M2 standards. It needs some improvement to make it compatible and error-free in a maximum of cases
Exception Handling.
$order = $observer->getEvent()->getOrder(); if( !empty($order) ) // do code here
Naming convention. Do use camel-case for variables.
$order_status
should be$orderStatus
.- It is observer so you won't be able to track if that happened or not so do wrap it in try-catch and log accordingly ( do add a check if logs are enabled or not ).
It is good and you followed good approach as per M2 standards. It needs some improvement to make it compatible and error-free in a maximum of cases
Exception Handling.
$order = $observer->getEvent()->getOrder(); if( !empty($order) ) // do code here
Naming convention. Do use camel-case for variables.
$order_status
should be$orderStatus
.- It is observer so you won't be able to track if that happened or not so do wrap it in try-catch and log accordingly ( do add a check if logs are enabled or not ).
edited 2 days ago
Raj Mohan R
673110
673110
answered 2 days ago
Shahzaib Hayat KhanShahzaib Hayat Khan
29615
29615
Thanks for the improvements you have mentioned, i have posted the least code here, Sure i will take and i am taking care of these standards, Can you please check the updated question now and try to answer that, will be appreciated.
– Zoo
2 days ago
add a comment |
Thanks for the improvements you have mentioned, i have posted the least code here, Sure i will take and i am taking care of these standards, Can you please check the updated question now and try to answer that, will be appreciated.
– Zoo
2 days ago
Thanks for the improvements you have mentioned, i have posted the least code here, Sure i will take and i am taking care of these standards, Can you please check the updated question now and try to answer that, will be appreciated.
– Zoo
2 days ago
Thanks for the improvements you have mentioned, i have posted the least code here, Sure i will take and i am taking care of these standards, Can you please check the updated question now and try to answer that, will be appreciated.
– Zoo
2 days ago
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%2f270773%2fchange-email-template-on-specific-order-statusmagento2%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