Magento2

If you want to redirect your customer in checkout page after customer registration success. Then you need to follow below steps to complete this process.
1). Create di.xml file at app/code/Magento/Tutorials/etc/ folder

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Checkout\Model\Session">
        <plugin name="redirect_to_checkout" type="Magento\Tutorials\Plugin\CheckoutRedirect" />
    </type>
</config>

2). Create CheckoutRedirect file at app/code/Magento/Tutorials/Plugin/ folder

<?php 
namespace Magento\Tutorials\Plugin;
 
class CheckoutRedirect
{
    protected $storeManager;
    protected $CustomerSession;
 
   public function __construct(
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        \Magento\Customer\Model\Session $CustomerSession
    )
    {
        $this->storeManager = $storeManager;
        $this->CustomerSession = $CustomerSession;
    }
    public function afterLoadCustomerQuote(\Magento\Checkout\Model\Session $subject,$result){
        $quote = $subject->getQuote();
        if(count($quote->getAllItems())>0){
            $this->CustomerSession->setBeforeAuthUrl($this->storeManager->getStore()->getUrl('checkout'));
        }
    }
}
?>

Run php bin/magento setup:di:compile when you add any dependency injection.Because without php bin/magento setup:di:compile it throws error in code.

Hope this will helps you!

Leave a Reply

Your email address will not be published. Required fields are marked *