0

I have set login page as home page using cms page but I want to display login page as home page before login but after login my category page should display as home page how to do this

3 Answers 3

2

I would hook into the event controller_action_predispatch_customer_customer_login, check wether the user is logged in, if it is the case, throw an exception of the form

$e = new Mage_Core_Controller_Varien_Exception();
$e->prepareForward('catalog','category','view', array('id' => $categoryId));
throw $e;

If the user is not logged in, the default behaviour is used, which is the login form.

How to do it?

Implement your own module

As @MagikTejas explains in another answer, you need to implement your own Module, by creating a YourCompany_YourModule.xml in app/etc/modules, but instead of implementing your own route, you implement an observer as described here: https://stackoverflow.com/a/11197771/1480397

Observer are implement inside of the config.xml in app/code/<local|community>/YourCompany/YourModule/etc/. The question wether you use community or local depends on whether you want to publish your module (aka use it in more than one installation)

Your config.xml should contain this part:

<frontend>
    <events>
        <controller_action_predispatch_customer_customer_login>
            <observers>
                <yourmodule_save_order_observer>
                    <class>YourCompany_YourModule_Model_Observer</class>
                    <method>controllerActionPredispatchCustomerCustomerLogin</method>
                </yourmodule_save_order_observer>
            </observers>
        </controller_action_predispatch_customer_customer_login>
    </events>
</frontend>

Now you implement your observer, the observer lives in app/code/<local|community>/YourCompany/YourModule/Model/Observer.php

The name of the observer is YourCompany_YourModule_Model_Observer and it contains the method controllerActionPredispatchCustomerCustomerLogin

public function controllerActionPredispatchCustomerCustomerLogin() {
    //check wether customer is logged in, if yes, redirect him
    if(Mage::getSingleton('customer/session')->isLoggedIn()) {
        // you need to get the $categoryId, but this is your part. You could hardcode it (which is a bad idea) or add a configuration setting (just google, how to do it) or something else, this is up to you.
        $e = new Mage_Core_Controller_Varien_Exception();
        $e->prepareForward('catalog','category','view', array('id' => $categoryId));
        throw $e;
    }
}
5
  • Please give the step to reproduce clearly
    – vidhya
    Commented Jan 18, 2014 at 3:16
  • Kindly explain me step by step clearly to proceed
    – vidhya
    Commented Jan 18, 2014 at 3:39
  • added more description. Commented Jan 18, 2014 at 9:22
  • I have tried above but there is no change my cms login page is default page before and after login ,is there any other step
    – vidhya
    Commented Jan 20, 2014 at 5:42
  • Hook with xdebug into the observer, check whether it is called, if not something with the configuration is wrong, if yes, something with the observer is wrong. Commented Jan 20, 2014 at 7:10
0

You can do this by creating a custom module as follows:

Create following directories for the module -

/app/code/local/Mycompany/Mymodule
/app/code/local/Mycompany/Mymodule/controllers
/app/code/local/Mycompany/Mymodule/etc

To set up a module that will let you redirect an incoming root website link to wherever you want, first set up a module xml file under /app/etc/modules/Mycompany_Mymodule.xml containing this

<?xml version="1.0"?>
<config>
    <modules>
        <Mycompany_Mymodule>
            <active>true</active>
            <codePool>local</codePool>
        </Mycompany_Mymodule>
    </modules>
</config> 

Create your config file in /app/code/local/Mycompany/Mymodule/etc/config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <Mycompany_Mymodule>
            <version>0.1.0</version>
        </Mycompany_Mymodule>
    </modules>
    <frontend>
        <routers>
            <mycompany>
                <use>standard</use>
                <args>
                    <module>Mycompany_Mymodule</module>
                    <frontName>mycompany</frontName>
                </args>
            </mycompany>
        </routers>
    </frontend>
</config> 

Now, create the controller file in /app/code/local/Mycompany/Mymodule/controllers/PageController.php

<?php
class Mycompany_Mymodule_PageController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {       
          if(Mage::getSingleton('customer/session')->isLoggedIn())
          {
         $this->getResponse()->setRedirect('catalog/category/view/id/10'); //10 is the category id which you want to display as home page
          }
          else
          {
          $this->_redirect('contacts'); //contacts - is the URL identifier of cms page add you login page identifier here.
          }
    }   
} 

Now the most important thing to make this work as expected go to "System > Configuration > Web > Default Pages" and enter the following for the "Default web url" option:

mycompany/page/

mycompany/page/ - this will call index action of our custom module. Hope this will help you.

5
  • I have tried all you said but my page results There has been an error processing your request Front controller reached 100 router match iterations Trace: #0 /opt/lampp/htdocs/vidhya/wigmore/app/code/core/Mage/Core/Controller/Varien/Front.php(183): Mage::throwException('Front controlle...') #1 /opt/lampp/htdocs/vidhya/wigmore/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch() #2 /opt/lampp/htdocs/vidhya/wigmore/app/Mage.php(683): Mage_Core_Model_App->run(Array) Error log record number: 180714953
    – vidhya
    Commented Jan 18, 2014 at 3:56
  • I change default web url from cms to mycompany/page/ is there any need to change cms option
    – vidhya
    Commented Jan 18, 2014 at 3:56
  • is there any solution to rectify the above error
    – vidhya
    Commented Jan 20, 2014 at 3:29
  • Have you tried clearing cache? What magento version you are using?
    – Tejas Shah
    Commented Jan 20, 2014 at 5:14
  • ya I clear cache Magento ver. 1.7.0.2
    – vidhya
    Commented Jan 20, 2014 at 5:25
0

To change homepage layout with login layout you can able to do using event controller_action_layout_load_before

You can follow below working code:

create one module, add below code in MyCompany/MyModulename/etc/config.xml

<events>
        <controller_action_layout_load_before> 
            <observers>
                <mymodulename>
                    <class>MyCompany_MyModulename_Model_Observer</class>
                    <method>changeHomepageContent</method>
                </mymodulename> 
            </observers>
        </controller_action_layout_load_before>
    </events>

Create observer file in MyCompany/MyModulename/Model/Observer.php

class MyCompany_MyModulename_Model_Observer 
{ 
    /**
     * change homepage content
     * @param Varien_Event_Observer $observer
     */
    public function changeHomepageContent(Varien_Event_Observer $observer) {
       $fullActionName = $observer->getEvent()->getAction()->getFullActionName();
       if($fullActionName == 'cms_index_index') {
             if (!Mage::getSingleton('customer/session')->isLoggedIn()) { // check if customer is not logged in                          
                   $layout = $observer->getEvent()->getLayout();
                   $layout->getUpdate()->removeHandle('cms_page');// this will remove existing cms page content.
                   $layout->getUpdate()->addHandle('customer_account_login'); //this code will add login page content to homepage.
            } 
        }


    }        
}

I hope above code will help you :)

13
  • BhavsarI have done above two code what is the next step to do
    – vidhya
    Commented Jan 20, 2014 at 3:56
  • because after doing this there is no change in my website
    – vidhya
    Commented Jan 20, 2014 at 4:59
  • I think you are doing something wrong, as above code is working fine with fresh Magento 1.7.0.2. Is there any other extension installed? Commented Jan 20, 2014 at 5:45
  • My question is there any need to change "System > Configuration > Web > Default Pages" and enter the following for the "Default web url" option: because in that I have give cms and load login page
    – vidhya
    Commented Jan 20, 2014 at 5:55
  • In "System > Configuration > Web > Default Pages" we can set only single page, which will be CMS page by default. I hope you have created module and added above code. Commented Jan 20, 2014 at 6:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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