<?php
namespace MageVision\Blog27\Controller\Adminhtml\Ohgod;
use Magento\Sales\Model\Order;
class Index extends \Magento\Backend\App\Action
{
public function __construct(
\Magento\Framework\App\Action\Context $context
// \Magento\Framework\Message\ManagerInterface $messageManager
) {
$this->resultFactory = $context->getResultFactory();
//$this->messageManager = $messageManager;
return parent::__construct($context);
}
public function execute()
{
// $this->messageManager->addSuccess(__("Error Message"));
// return $this->_messageManager->addError(__("Error Message"));
// echo "hi";
$id = $this->getRequest()->getParam('order_id');
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('Magento\Sales\Api\Data\OrderInterface')->load($id);
$orderState = 'processing';
$order->setState($orderState)->setStatus('processing');
$order->save();
// Code to send email.
$templateId = 8;
/* Receiver Detail */
$store = $objectManager->create('Magento\Store\Model\ScopeInterface');
$semail = $store->getValue('trans_email/ident_sales/name', ScopeInterface:COPE_STORE);
$receiverInfo = [
'name' => $semail,
'email' => $semail
];
//$name = $customerSession->getCustomer()->getName();
/* Sender Detail */
$email = $order->getCustomerEmail();
$name = $order->getCustomerFirstname() . " " . $order->getCustomerMiddlename() . " " . $order->getCustomerLastname();
$senderInfo = [
'name' => $name,
'email' => $email
];
$variablevalue1 = 'Tippanna Pawar';
$variablevalue2 = "12345";
/* Assign values for your template variables */
$emailTempVariables = array();
$emailTempVariables['myvar1'] = $variablevalue1;
$emailTempVariables['myvar2'] = $variablevalue2;
/* We write send mail function in helper because if we want to
use same in other action then we can call it directly from helper */
/* call send mail method from helper or where you define it*/
$this->_objectManager->get('Tp\Emails\Helper\Email')->yourCustomMailSendMethod(
$emailTempVariables,
$senderInfo,
$receiverInfo,
$templateId
);
//End of email code
// $order->setStatus(\Magento\Sales\Model\Order:TATE_PENDING, true)->save();
$order->addStatusToHistory($order->getStatus(), 'Order processed successfully with reference again and again');
// $this->_getSession()->addSuccess($this->__('The order state has been changed.'));
$this->_redirect('sales/order/view', array('order_id' => $id));
}
/**
* Check Permission.
*
* @return bool
*/
protected function _isAllowed()
{
return $this->_authorization->isAllowed('MageVision_Blog27');
}
}