Redirect to login page if not login magento
You can create a module for that.
First you need to declare an observer on the controller_action_predispatch
event: app/code/local/Vendor/Module/etc/config.xml
<config>
<modules>
<Vendor_Module>
<version>0.0.1</version>
</Vendor_Module>
</modules>
<global>
<models>
<module>Vendor_Module_Model</module>
</models>
</global>
<frontend>
<events>
<controller_action_predispatch>
<observers>
<vendor_module_controller_action_predispatch>
<type>singleton</type>
<class>module/observer</class>
<method>preDispatch</method>
</vendor_module_controller_action_predispatch>
</observers>
</controller_action_predispatch>
</events>
</frontend>
</config>
Then in app/code/local/Vendor/Module/Model/Observer.php
please note that you need to replace STORE_ID
with the id of the store you want to implement that feature :
<?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);
}
}
}
}
And app/etc/modules/Vendor_Module.xml
<?xml version="1.0"?>
<config>
<modules>
<Vendor_Module>
<active>true</active>
<codePool>local</codePool>
<depends>
<Magento_Customer/>
</depends>
</Vendor_Module>
</modules>
</config>
You can create an observer for the event controller_action_predispatch
.
The observer method can look like this:
public function redirectNotLogged(Varien_Event_Observer $observer)
{
$storeId = Mage::app()->getStore()->getId();
$restrictedStoreId = your restricted store id here. It can even come from a config setting.
if ($storeId == $restrictedStoreId) {
$action = strtolower(Mage::app()->getRequest()->getActionName());
$controller = strtolower(Mage::app()->getRequest()->getControllerName());
$openActions = array(
'create',
'createpost',
'login',
'loginpost',
'logoutsuccess',
'forgotpassword',
'forgotpasswordpost',
'resetpassword',
'resetpasswordpost',
'confirm',
'confirmation'
);
if ($controller == 'account' && in_array($action, $openActions)) {
return $this; //if in allowed actions do nothing.
}
if(! Mage::helper('customer')->isLoggedIn()){
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('customer/account/login'));
}
}
}