7

I am trying to set the order history page as the default page when the customer is logged in.

When the customer login is successful, it redirects to customer/account/

Instead of this can we direct to sales/order/history/

So when the customer login happens, he can see order history page instead of the dashboard page.

Is something like that can be achieved? Can anyone help me on this issue, please?

Thanks

7

override account controller as like below.

Vendor\Module\etc\di.xml

 <?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">       
   <preference for="Magento\Customer\Controller\Account\Index" type="Vendor\Module\Controller\Account\ExtendIndex" /> 
</config>

Then, Vendor\Module\Controller\Account\ExtendIndex.php

<?php
 namespace Vendor\Module\Controller\Account;
 class ExtendIndex extends \Magento\Customer\Controller\Account\Index
 {
   public function execute()
  {
    $resultRedirect = $this->resultRedirectFactory->create();
    $resultRedirect->setPath('sales/order/history');
    return $resultRedirect;
  }
}

I hope this will help you!!

  • 1
    Thank you it worked !! @jafar – Manjunath Sep 5 '19 at 6:45
  • 1
    I have one question how user access to dashboard? – Addify Sep 5 '19 at 7:04
  • @Addify,its not required in my requirement! – Manjunath Sep 5 '19 at 7:05
4

Override the LoginPost controller and set the redirect to history controller in the plugin

Filepath: Vendor/Module/etc/frontend/di.xml:

<?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\Customer\Controller\Account\LoginPost">
    <plugin name="vendor_module_loginpostplugin" type="\Vendor\Module\Plugin\LoginPostPlugin" sortOrder="1" />
  </type>
</config>

Filepath: Vendor/Module/Plugin/LoginPostPlugin.php:

<?php

namespace Vendor\Module\Plugin;

class LoginPostPlugin
{

    public function afterExecute(
        \Magento\Customer\Controller\Account\LoginPost $subject,
        $result)
    {
        $result->setPath('sales/order/history'); 
        return $result;
    }

}

Note:Code tested

3

You can change My Account link by plugin

Add below code to app/code/Vendor/Module/etc/di.xml

<type name="Magento\Customer\Model\Url">
    <plugin name="custom_links" type="Vendor\Module\Model\Url" sortOrder="1" />
</type>

app/code/Vendor/Module/Model/Url.php

<?php

namespace Vendor\Module\Model;

use Magento\Framework\UrlInterface;

class Url
{
    /**
     * @var UrlInterface
     */
    protected $urlBuilder;


    /**
     * @param UrlInterface $urlBuilder
     */
    public function __construct(
        UrlInterface $urlBuilder
    ) {
        $this->urlBuilder = $urlBuilder;
    }

    public function afterGetAccountUrl(\Magento\Customer\Model\Url $subject, $result)
    {
        return $this->urlBuilder->getUrl('sales/order/history');
    }
}
2
  1. events.xml file in app\code\Vendore\Module\etc\frontend folder
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="customer_login">
        <observer name="customer_login_success_after_order" instance="Vendore\Module\Observer\CustomerLogin" />
    </event>
</config>
  1. Create CustomerLogin.php file in app\code\Vendore\Module\Observer folder
<?php

namespace Builderschoice\CustomModule\Observer;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Builderschoice\Company\Model\CompanyFactory;


class CustomerLogin implements ObserverInterface
{
/**
 * @var \Magento\Framework\App\ResponseFactory
 */
protected $responseFactory;

protected $webkulData;

protected $_companyBlock;

protected $_companyFactory;

protected $_storeManagerInterface;

/**
 * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
 * @param \Zend\Validator\Uri $uri
 * @param \Magento\Framework\App\ResponseFactory $responseFactory
 */
public function __construct(
    \Magento\Framework\App\ResponseFactory $responseFactory,
    \Webkul\Marketplace\Helper\Data $webkulData,
    \Builderschoice\Company\Block\Index\Index $companyBlock,
    \Magento\Store\Model\StoreManagerInterface $storeManagerInterface,
    CompanyFactory $companyFactory
) {
    $this->responseFactory = $responseFactory;
    $this->webkulData = $webkulData;
    $this->_companyBlock = $companyBlock;
    $this->_storeManagerInterface = $storeManagerInterface;
    $this->_companyFactory = $companyFactory;
}
/**
 * Handler for 'customer_login' event.
 *
 * @param Observer $observer
 * @return void
 */
public function execute(Observer $observer)
{
    $event = $observer->getEvent();
    $customer = $event->getCustomer();

    $storeManager = $this->_storeManagerInterface->create();
    $baseurl=$storeManager->getStore()->getBaseUrl();
    $url = $baseurl.'sales/order/history';

    $resultRedirect = $this->responseFactory->create();

    $resultRedirect->setRedirect($url)->sendResponse('200');

    exit();
}
}

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.