0

I'm trying to rediect the user to login page after the store is opened the url for the store is

e.g mysiteabc.com/store1

I want the user redirect to login page if he/she visits the store 1 I am trying this code as Reference but it doesnot work for me . Tell me What i'm doing wrong here

config.xml

 <frontend>
     <events>
         <controller_action_predispatch>
             <observers>
                 <client_controller_action_predispatch>
                     <type>singleton</type>
                     <class>Vendor_Module_Model_Observer</class>
                     <method>preDispatch</method>
                 </client_controller_action_predispatch>
             </observers>
         </controller_action_predispatch>
     </events>
</frontend> 

Observer.php

class Vendor_Module_Model_Observer {
    public function preDispatch(Varien_Event_Observer $observer)
    {
        $controller = $observer->getControllerAction();
        if (Mage::app()->getStore()->getId() == STORE_ID) {

            if ('customer' === $controller->getRouteName()) {
                return $this;
            }

            if (!Mage::getSingleton('customer/session')->authenticate($controller)) {
                $controller->setFlag('', 'no-dispatch', true);
            }
        }
    }
}
4
  • Are you sure that mysiteabc.com/store1 works ?
    – PЯINCƎ
    Commented Nov 12, 2019 at 9:42
  • Yes it is loading the store
    – wofang
    Commented Nov 12, 2019 at 10:02
  • In your reference comments says that it worked but with Marius code below not the accepted answer, so try the redirect method it should work.
    – pontikos
    Commented Nov 12, 2019 at 18:50
  • Did you replace STORE_ID with the actual store ID?
    – BlueC
    Commented Nov 15, 2019 at 9:35

0

Your Answer

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

Browse other questions tagged or ask your own question.