0

i want when a logged customer visit a CMS page he should be redirect to account page and when customer is not login he can see page content.

2
  1. First you need to call a custom template from your cms/page.

{{block type="core/template" name="visitor_page" template="YourTemplateFolder/TemplateFileName.phtml"}}

  1. Then in your .phtml file you can do something like this:
$logged_in = Mage::getSingleton('customer/session' )->isLoggedIn();
if ($logged_in){
$url = Mage::getUrl('customer/account');
Mage::app()->getResponse()->setRedirect($url);
return;
}

?>

<div class="main-content"> <h1>MY CMS PAGE CONTENT</h1> <p>MAYBE YOU CAN CALL A CMS BLOCK TO MAKE CONTENT ADMINISTRABLE.</p> </div>
0

This is not an easy one to explain. To maintain control over all aspects you will probably need to extend the original Customer Account class and handle the redirects yourself. However you should try to see if some of the built in functionality works that Magento gives you out of the box. To set where customers go after they login, you can set this value in System->Configuration->Customers->Customer Configuration->Login Options This drop down will allow you to move customers to their dashboard after logging in. If this does not offer enough flexibility, do an extension of Mage_Customer is your next option. First step create the module declaration for example app/etc/modules/Gallup_Customer.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Russell_Customer>
            <active>true</active>
            <codePool>local</codePool>
        </Russell_Customer>
    </modules>
</config>

Next you need to create your local module, in this example we are using the Namespace Russell Create a folder in app/code/local/Russell Then create an etc folder here is the path app/code/local/Russell/Customer/etc/ Inside that create a file called config.xml here is the path app/code/local/Russell/Customer/etc/config.xml that xml file should have something similar to this:

<?xml version="1.0" encoding="UTF-8"?>
    <config>
        <modules>
            <Russell_Customer>
                <version>0.1.0</version>
            </Russell_Customer>
        </modules>
    <frontend>
        <routers>
            <customer>               
                <args>
                    <modules>
                        <Russell_Customer before="Mage_Customer">Russell_Customer</Russell_Customer>
                    </modules>                   
                </args>
            </customer>
        </routers>
    </frontend>
</config>

Next create a controllers folder in app/code/local/Russell/Customer/controllers and create a file called AccountController.php It may look similar to this. this version I am showing is very simple, I would assume you have some other logic you need to use but this should give you a head start.

<?php

require_once 'Mage/Customer/controllers/AccountController.php';

class Russell_Customer_AccountController extends Mage_Customer_AccountController
{
        protected function _loginPostRedirect()
    {
        $session = $this->_getSession();

        if (!$session->getBeforeAuthUrl() || $session->getBeforeAuthUrl() == Mage::getBaseUrl()) {
        // Set default URL to redirect customer to
        $session->setBeforeAuthUrl($this->_getHelper('customer')->getAccountUrl());
        // Redirect customer to the last page visited after logging in
        if ($session->isLoggedIn()) {
            if (!Mage::getStoreConfigFlag(
                Mage_Customer_Helper_Data::XML_PATH_CUSTOMER_STARTUP_REDIRECT_TO_DASHBOARD
            )) {
                    $referer = $this->getRequest()->getParam(Mage_Customer_Helper_Data::REFERER_QUERY_PARAM_NAME);
                    if ($referer) {
                    // Rebuild referer URL to handle the case when SID was changed
                        $referer = $this->_getModel('core/url')
                        ->getRebuiltUrl( $this->_getHelper('core')->urlDecodeAndEscape($referer));
                        if ($this->_isUrlInternal($referer)) {
                        $session->setBeforeAuthUrl($referer);
                        }
                    }
                } else if ($session->getAfterAuthUrl()) {
                    $session->setBeforeAuthUrl($session->getAfterAuthUrl(true));
                }
            } else {
            $session->setBeforeAuthUrl( $this->_getHelper('customer')->getLoginUrl());
            }
        } else if ($session->getBeforeAuthUrl() ==  $this->_getHelper('customer')->getLogoutUrl()) {
            $session->setBeforeAuthUrl( $this->_getHelper('customer')->getDashboardUrl());
        } else {
            if (!$session->getAfterAuthUrl()) {
                $session->setAfterAuthUrl($session->getBeforeAuthUrl());
            }
            if ($session->isLoggedIn()) {
                $session->setBeforeAuthUrl($session->getAfterAuthUrl(true));
            }
        }
        // set the redirect URL 
        $this->_redirectUrl($this->getUrl('module/controller/action');
    }

}

Now with this in place you can take the customers to any page you want after they log in.

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.