<?php
namespace Softadroit\Prescription\Controller\Index;
use Magento\Framework\Controller\ResultFactory;
class Save extends \Magento\Framework\App\Action\Action
{
protected $_pageFactory;
protected $resultRedirect;
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory\Magento\Framework\Controller\Result\RedirectFactory $pageFactory$resultRedirectFactory,
\Magento\Checkout\Model\CartFactory\Magento\Framework\View\Result\PageFactory $cartFactory$pageFactory,
\Magento\Framework\Controller\ResultFactory\Magento\Checkout\Model\CartFactory $resultPageFactory$cartFactory
) {
$this->_pageFactory = $pageFactory;
$this->cartFactory = $cartFactory;
$this->resultRedirect>resultRedirectFactory = $context->getResultFactory();$resultRedirectFactory;
return parent::__construct($context);
}
public function execute()
{
$post = $this->getRequest()->getPost();
/* echo "<pre>";
print_r($post);
die(); */
if (!empty($post)) {
foreach ($post['name'] as $key => $name) {
$age = $post['age'][$key];
$weight = $post['weight'][$key];
$height = $post['height'][$key];
$gender = $post['subject_gender'][$key];
$product_id = $post['product_id'][$key];
$customer_id = $post['customer_id'][$key];
$model = $this->_objectManager->create('Softadroit\Prescription\Model\Prescription');
$model->setData([
"name" => $name,
"age" => $age,
"weight" => $weight,
"height" => $height,
"gender" => $gender,
"product_id" => $product_id,
"customer_id" => $customer_id,
]);
$msg = "";
$data = $model->save();
if ($data != '') {
//$model->save();
$this->messageManager->addSuccessMessage('Thanks your form is submitted successfully!');
} else {
$this->messageManager->addSuccessMessage('Error in submitting data. Please contact on this email!');
}
}
echo $msg;
$cartObject = $this->cartFactory->create()->truncate();
$cartObject->saveQuote();
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */}
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath('checkout'prescription/onepageindex/success');
return $resultRedirect;
}
}
}
<?php
namespace Softadroit\Prescription\Controller\Index;
use Magento\Framework\Controller\ResultFactory;
class Save extends \Magento\Framework\App\Action\Action
{
protected $_pageFactory;
protected $resultRedirect;
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $pageFactory,
\Magento\Checkout\Model\CartFactory $cartFactory,
\Magento\Framework\Controller\ResultFactory $resultPageFactory
) {
$this->_pageFactory = $pageFactory;
$this->cartFactory = $cartFactory;
$this->resultRedirect = $context->getResultFactory();
return parent::__construct($context);
}
public function execute()
{
$post = $this->getRequest()->getPost();
/* echo "<pre>";
print_r($post);
die(); */
if (!empty($post)) {
foreach ($post['name'] as $key => $name) {
$age = $post['age'][$key];
$weight = $post['weight'][$key];
$height = $post['height'][$key];
$gender = $post['subject_gender'][$key];
$product_id = $post['product_id'][$key];
$customer_id = $post['customer_id'][$key];
$model = $this->_objectManager->create('Softadroit\Prescription\Model\Prescription');
$model->setData([
"name" => $name,
"age" => $age,
"weight" => $weight,
"height" => $height,
"gender" => $gender,
"product_id" => $product_id,
"customer_id" => $customer_id,
]);
$msg = "";
$data = $model->save();
if ($data != '') {
//$model->save();
$this->messageManager->addSuccessMessage('Thanks your form is submitted successfully!');
} else {
$this->messageManager->addSuccessMessage('Error in submitting data. Please contact on this email!');
}
}
echo $msg;
$cartObject = $this->cartFactory->create()->truncate();
$cartObject->saveQuote();
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath('checkout/onepage/success');
return $resultRedirect;
}
}
}
<?php
namespace Softadroit\Prescription\Controller\Index;
class Save extends \Magento\Framework\App\Action\Action
{
protected $_pageFactory;
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory,
\Magento\Framework\View\Result\PageFactory $pageFactory,
\Magento\Checkout\Model\CartFactory $cartFactory
) {
$this->_pageFactory = $pageFactory;
$this->cartFactory = $cartFactory;
$this->resultRedirectFactory = $resultRedirectFactory;
return parent::__construct($context);
}
public function execute()
{
$post = $this->getRequest()->getPost();
/* echo "<pre>";
print_r($post);
die(); */
if (!empty($post)) {
foreach ($post['name'] as $key => $name) {
$age = $post['age'][$key];
$weight = $post['weight'][$key];
$height = $post['height'][$key];
$gender = $post['subject_gender'][$key];
$product_id = $post['product_id'][$key];
$customer_id = $post['customer_id'][$key];
$model = $this->_objectManager->create('Softadroit\Prescription\Model\Prescription');
$model->setData([
"name" => $name,
"age" => $age,
"weight" => $weight,
"height" => $height,
"gender" => $gender,
"product_id" => $product_id,
"customer_id" => $customer_id,
]);
$msg = "";
$data = $model->save();
if ($data != '') {
//$model->save();
$this->messageManager->addSuccessMessage('Thanks your form is submitted successfully!');
} else {
$this->messageManager->addSuccessMessage('Error in submitting data. Please contact on this email!');
}
}
echo $msg;
$cartObject = $this->cartFactory->create()->truncate();
$cartObject->saveQuote();
}
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath('prescription/index/success');
return $resultRedirect;
}
}
use Magento\Framework\App\Action\Action;<?php
use Magento\Framework\Controller\Result\JsonFactory;
usenamespace Magento\Framework\View\Result\PageFactory;Softadroit\Prescription\Controller\Index;
use Magento\Framework\App\Action\Context;Magento\Framework\Controller\ResultFactory;
class Save extends Action\Magento\Framework\App\Action\Action
{
/**
protected $_pageFactory;
* @varprotected Magento\Framework\View\Result\PageFactory$resultRedirect;
public */function __construct(
protected $_resultPageFactory;
\Magento\Framework\App\Action\Context /**$context,
* @param Context \Magento\Framework\View\Result\PageFactory $pageFactory,
$context
*\Magento\Checkout\Model\CartFactory @param$cartFactory,
PageFactory $resultPageFactory
*/
\Magento\Framework\Controller\ResultFactory $resultPageFactory
public function) __construct({
Context$this->_pageFactory $context,
= $pageFactory;
PageFactory $resultPageFactory
$this->cartFactory ) {= $cartFactory;
$this->_resultPageFactory>resultRedirect = $resultPageFactory;$context->getResultFactory();
return parent::__construct($context);
}
public function execute()
{
$resultPage$post = $this->_resultPageFactory>getRequest()->create>getPost();
$resultPage->getConfig/* echo "<pre>";
print_r($post)->getTitle;
die()->prepend; */
if (__!empty('$post)) Success{
' foreach ($post['name'] as $key => $name) {
$age = $post['age'][$key];
$weight = $post['weight'][$key];
$height = $post['height'][$key];
$gender = $post['subject_gender'][$key];
$product_id = $post['product_id'][$key];
$customer_id = $post['customer_id'][$key];
$model = $this->_objectManager->create('Softadroit\Prescription\Model\Prescription');
$block = $resultPage $model->getLayout>setData([
"name" => $name,
"age" => $age,
"weight" => $weight,
"height" => $height,
"gender" => $gender,
"product_id" => $product_id,
"customer_id" => $customer_id,
]);
$msg = "";
$data = $model->createBlock>save('Softadroit\Prescription\Block\blockname');
if ($data != '') {
//or$model->save();
use default block class of magento $this->messageManager->addSuccessMessage('Thanks your form is submitted successfully!');
} else {
$this->setTemplate>messageManager->addSuccessMessage('Softadroit_Prescription::Success'Error in submitting data.phtml' Please contact on this email!');
}
}
echo $msg;
$cartObject = $this->toHtml>cartFactory->create()->truncate();
$cartObject->saveQuote();
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->getResponse>resultRedirectFactory->create();
$resultRedirect->setBody>setPath($block'checkout/onepage/success');
return $resultRedirect;
}
}
}
use Magento\Framework\App\Action\Action;
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Framework\View\Result\PageFactory;
use Magento\Framework\App\Action\Context;
class Save extends Action
{
/**
* @var Magento\Framework\View\Result\PageFactory
*/
protected $_resultPageFactory;
/**
* @param Context $context
* @param PageFactory $resultPageFactory
*/
public function __construct(
Context $context,
PageFactory $resultPageFactory
) {
$this->_resultPageFactory = $resultPageFactory;
parent::__construct($context);
}
public function execute()
{
$resultPage = $this->_resultPageFactory->create();
$resultPage->getConfig()->getTitle()->prepend(__(' Success '));
$block = $resultPage->getLayout()
->createBlock('Softadroit\Prescription\Block\blockname') //or use default block class of magento
->setTemplate('Softadroit_Prescription::Success.phtml')
->toHtml();
$this->getResponse()->setBody($block);
}
}
<?php
namespace Softadroit\Prescription\Controller\Index;
use Magento\Framework\Controller\ResultFactory;
class Save extends \Magento\Framework\App\Action\Action
{
protected $_pageFactory;
protected $resultRedirect;
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $pageFactory,
\Magento\Checkout\Model\CartFactory $cartFactory,
\Magento\Framework\Controller\ResultFactory $resultPageFactory
) {
$this->_pageFactory = $pageFactory;
$this->cartFactory = $cartFactory;
$this->resultRedirect = $context->getResultFactory();
return parent::__construct($context);
}
public function execute()
{
$post = $this->getRequest()->getPost();
/* echo "<pre>";
print_r($post);
die(); */
if (!empty($post)) {
foreach ($post['name'] as $key => $name) {
$age = $post['age'][$key];
$weight = $post['weight'][$key];
$height = $post['height'][$key];
$gender = $post['subject_gender'][$key];
$product_id = $post['product_id'][$key];
$customer_id = $post['customer_id'][$key];
$model = $this->_objectManager->create('Softadroit\Prescription\Model\Prescription');
$model->setData([
"name" => $name,
"age" => $age,
"weight" => $weight,
"height" => $height,
"gender" => $gender,
"product_id" => $product_id,
"customer_id" => $customer_id,
]);
$msg = "";
$data = $model->save();
if ($data != '') {
//$model->save();
$this->messageManager->addSuccessMessage('Thanks your form is submitted successfully!');
} else {
$this->messageManager->addSuccessMessage('Error in submitting data. Please contact on this email!');
}
}
echo $msg;
$cartObject = $this->cartFactory->create()->truncate();
$cartObject->saveQuote();
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath('checkout/onepage/success');
return $resultRedirect;
}
}
}
check the below code
In controller:
use Magento\Framework\App\Action\Action;
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Framework\View\Result\PageFactory;
use Magento\Framework\App\Action\Context;
class Save extends Action
{
/**
* @var Magento\Framework\View\Result\PageFactory
*/
protected $_resultPageFactory;
/**
* @param Context $context
* @param PageFactory $resultPageFactory
*/
public function __construct(
Context $context,
PageFactory $resultPageFactory
) {
$this->_resultPageFactory = $resultPageFactory;
parent::__construct($context);
}
public function execute()
{
$resultPage = $this->_resultPageFactory->create();
$resultPage->getConfig()->getTitle()->prepend(__(' Success '));
$block = $resultPage->getLayout()
->createBlock('Softadroit\Prescription\Block\blockname') //or use default block class of magento
->setTemplate('Softadroit_Prescription::Success.phtml')
->toHtml();
$this->getResponse()->setBody($block);
}
}
default