2

In my custom controller I am checking if customer is logged in or not.If not redirects to customer login page .

public function customaddAction()
{


    if(!Mage::helper('customer')->isLoggedIn())
    {
        Mage::getSingleton('customer/session')->setBeforeAuthUrl(Mage::helper('core/url')->getCurrentUrl());
        Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('customer/account'));
        $this->_redirect('customer/account/login');

    }
    if(Mage::helper('customer')->isLoggedIn())
    {           
     $sampleid=$this->getRequest()->getParam('sampleid');

      $collection=Mage::getSingleton('mymodule/mymodule')->customisesaved($sampleid);
    if($collection)
    {
    $this->_redirect('mymodule/mymodule/customshow');
    }
    else{
             $this->_redirectReferer();
        }
    }
}

This is my custom controller from where I am checking if customer is logged in or not. But if the customer is new when he registers using ajax registration it redirect to MyAccount page but I want to continue my controller action. Suggest me some solution.

2 Answers 2

0

Please Look at below configuration That will help you to solve your problem

enter image description here

3
  • thanks for your answer i had made this changes but still it does not execute my controller action when user is creating new account
    – coder
    Commented Aug 23, 2016 at 6:43
  • try to enable Enable Guest Checkout And test its working or not Commented Aug 23, 2016 at 6:50
  • I want to execute my controller for register customer only
    – coder
    Commented Aug 23, 2016 at 7:07
0

If you want to check that the customer is new or not than you need to create custom customer attribute named "is_new". Use this extension: https://www.magentocommerce.com/magento-connect/manage-customer-attributes-1.html

Create observer for customer_save_after and customer_register_success.

<global>
    <events>
        <customer_save_after>
            <observers>
                <namespace_module>
                    <type>singleton</type>
                    <class>namespace_module/observer</class>
                    <method>doSomething</method>
                </namespace_module>
            </observers>
        </customer_save_after>
        <customer_register_success>
            <observers>
                <namespace_module>
                    <type>singleton</type>
                    <class>namespace_module/observer</class>
                    <method>doSomething</method>
                </namespace_module>
            </observers>
        </customer_register_success>
    </events>
</global>

Create Oberver.php

class [Namespace]_[Module]_Model_Observer
{
    protected $canDoSomething = false;

    public function doSomething($observer)
    {
        if (!$this->canDoSomething) {

            //here your code
            //set is_new = 1 here

            //now set flag to true to prevent executing your code twice 
            $this->canDoSomething = true;
        }
    }
}

Overrides the _loginPostRedirect method of default AccountController to redirect on custom URL.

require_once 'Mage/Customer/controllers/AccountController.php';
class MagentoPycho_Customer_AccountController extends Mage_Customer_AccountController
{

   /**
     * Overriding defaults redirect URL 
     * Define target URL and redirect customer after logging in
     */
    protected function _loginPostRedirect()
    {    
        $session    = $this->_getSession();        
        // $is_new = get customer data and check for is_new attribute value.

        if($is_new == 1){
            // redirect to your custom module
            // set is_new attribute value to 0.
        }else{
            if (!$session->getBeforeAuthUrl() || $session->getBeforeAuthUrl() == Mage::getBaseUrl() ) {

                // Set default URL to redirect customer to
                $session->setBeforeAuthUrl(Mage::helper('customer')->getAccountUrl());

                // Redirect customer to the last page visited after logging in
                if ($session->isLoggedIn())
                {
                    if (!Mage::getStoreConfigFlag('customer/startup/redirect_dashboard')) {
                        if ($referer = $this->getRequest()->getParam(Mage_Customer_Helper_Data::REFERER_QUERY_PARAM_NAME)) {
                            $referer = Mage::helper('core')->urlDecode($referer);
                            if ($this->_isUrlInternal($referer)) {
                                $session->setBeforeAuthUrl($referer);
                            }
                        }
                    }
                } else {
                    $session->setBeforeAuthUrl(Mage::helper('customer')->getLoginUrl());
                }
            }
        }

        $this->_redirectUrl($session->getBeforeAuthUrl(true));        
    }
}

Now this code will check if the customer is new than it will redirect to your module else default behaviour

8
  • you can also use observer to achieve this. Ref. blog.belvg.com/… Commented Aug 22, 2016 at 6:22
  • thanks for your answer but I don't want to always redirect to my custom controller ** only when my custom controller action is called the new registered customer should continue my controller action.**
    – coder
    Commented Aug 23, 2016 at 4:35
  • you can add that logical part in if condition if(1 == $custom_login_redirect_flag){ Commented Aug 23, 2016 at 5:49
  • check created_at date to find new registered customer. Commented Aug 23, 2016 at 5:54
  • please check my updated question. with my custom controller action.
    – coder
    Commented Aug 23, 2016 at 6:33

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.