0

I want to show different home page for logged in user, Which event/plugin I can use for this ?

Whenever logged in customer clicks on homepage he should be redirected to different url

Logged-in user : example.com/survey

Guest user : example.com

Please Note:

We have integrated wp-cloud for cms pages, we are not using magento cms page.

closed as off-topic by Amit Bera Aug 7 at 12:14

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about third-party modules are generally off-topic because the scope of functionality and code are not available. For more information, see this meta post/answer." – Amit Bera
If this question can be reworded to fit the rules in the help center, please edit the question.

1

You need to create even observer as below

<?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_observer" instance="<Your_packagename>\<Your_modulename>\Observer\LandignPage" />
    </event>
</config>

Now create an observer file as below

<?php

namespace YourPackage\YourModle\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Controller\ResultFactory;

class LandingPage implements ObserverInterface
{
    /**
     * @var \Magento\Framework\App\Config\ScopeConfigInterface
     */
    protected $scopeConfig;

    /**
     *@var\Magento\Framework\App\ResponseFactory
     */
    protected $responseFactory;
    /**
     * @var \Magento\Catalog\Helper\Category
     */
    protected $categoryHelper;

    /**
     * @var \Magento\Catalog\Model\CategoryRepository
     */
    protected $categoryRepository;

    /**
     * @var \Magento\Catalog\Model\CategoryRepository
     */

    protected $_storeManager;


    protected $pageHelper;

     protected $logger;

    public function __construct(      
        \Magento\Framework\App\ResponseFactory $responseFactory,      
        \Magento\Catalog\Model\CategoryRepository $categoryRepository,
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        \Magento\Cms\Helper\Page $pageHelper
    )
    {       
        $this->responseFactory = $responseFactory;

        $this->categoryRepository = $categoryRepository;
        $this->_storeManager = $storeManager;

        $this->pageHelper = $pageHelper;

    }

    public function execute(\Magento\Framework\Event\Observer $observer)
    {       
        $landingurl =  $this->getLandingPagedetails();
        if ($landingurl) {
                $resultRedirect = $this->responseFactory->create();
                $resultRedirect->setRedirect($landingurl)->sendResponse('200');
                exit();
        }
    }

    public function getLandingPagedetails()
    {
        $pageId = <cms_page_id>; 
           return $cmsPageUrl = $this->pageHelper->getPageUrl($pageId);
        return $cmsPageUrl->getUrl();
    }
}

This is what after login it will redirect to selected landing page. You can use observer code on any controller or model.

  • We have integrated wp-cloud for cms pages, we are not using magento cms – Daniel_12 Aug 7 at 11:59

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