2

This is my controller page. I need to redirect to success page and place all orders in cart. This returns https 500 error.

<?php

namespace Cod\Otp\Controller\Index;

use Magento\Quote\Api\CartManagementInterface;
use Magento\Quote\Model\Quote;
use Magento\Checkout\Model\Type\Onepage;
use Magento\Framework\Controller\ResultFactory;

class sotp extends \Magento\Framework\App\Action\Action
{

    protected $cartManagement;
    protected $quote;
    protected $resultRedirect;
    protected $checkoutSession;

    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Quote\Api\CartManagementInterface $cartManagement,
        \Magento\Quote\Model\Quote $quote,
        \Magento\Checkout\Model\Session $checkoutSession,
        \Magento\Framework\Controller\ResultFactory $resultPageFactory

        ){
        parent::__construct($context);
        $this->cartManagement = $cartManagement;
        $this->quote = $quote;
        $this->resultRedirect = $context->getResultFactory();
            $this->_checkoutSession = $checkoutSession;
    }
    public function execute()
    {

        $this->_view->loadLayout();
        $this->_view->getLayout()->initMessages();
        $this->_view->renderLayout();
        $this->quote = $this->checkoutSession->getQuote();
        $this->quote->getPayment()->setMethod('payfull');
        $this->cartManagement->placeOrder($this->quote->getId());
        $resultRedirect = $this->resultRedirect->create(ResultFactory::TYPE_REDIRECT);
        $resultRedirect->setPath('checkout/onepage/success', ['_secure' => true]);
    }
}
1

try this

/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
           $resultRedirect = $this->resultRedirectFactory->create();
           return $resultRedirect->setPath('router_id/controller_name/action_name');
| improve this answer | |
0

First thing your class should start with Capital letter

By following code you can redirect to success page

$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath('checkout/onepage/successs');
return $resultRedirect;

Hope it helps.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.