I want to restrict the visitors for a single store in multistore website. If they are not logged in, redirect them to login page. They can also create account and login after they visit the website. If anyone have idea please let me know.


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


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 :


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"?>
  • 1
    Thanks It works but according to my question we have to modify the observer function like Maurius Posted – Jack Jun 16 '16 at 13:16

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(
        if ($controller == 'account' && in_array($action, $openActions)) {
            return $this; //if in allowed actions do nothing.
        if(! Mage::helper('customer')->isLoggedIn()){
  • Your observer function working thanks for help – Jack Jun 16 '16 at 13:16

Magento 2

namespace BA\GiftCertificate\Controller\CustAccount;
use Magento\Customer\Model\Session;
use Magento\Framework\Controller\Result\RedirectFactory;
use Magento\Framework\View\Result\PageFactory;

class Index implements \Magento\Framework\App\ActionInterface
     * @var \Magento\Framework\View\Result\PageFactory
    protected $resultPageFactory;
     * @var \Magento\Framework\Controller\Result\RedirectFactory
    protected $resultRedirect;
     * @var \Magento\Customer\Model\Session
    protected $customerSession;

     * @param \Magento\Framework\Controller\Result\RedirectFactory $resultRedirect
     * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
     * @param \Magento\Customer\Model\Session $customerSession
    public function __construct(
        RedirectFactory $resultRedirect,
        PageFactory $resultPageFactory,
        Session $customerSession
    ) {
        $this->resultRedirect = $resultRedirect;
        $this->resultPageFactory = $resultPageFactory;
        $this->customerSession = $customerSession;
     * Default customer account page
     * @return void
    public function execute()
        if (!$this->customerSession->isLoggedIn()) {
            /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
            $resultRedirect = $this->resultRedirect->create();
            return $resultRedirect;
        } else {
            return $this->resultPageFactory->create();
  • Question relates to M1. – sv3n Dec 31 '20 at 1:26

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.