4

I created a custom module in magento, and I need to make it work only for customers who are logged in. How should I make customer login required for a magento module?

8

You need to add this inside your frontend controller(s) of your module

public function preDispatch()
{
    parent::preDispatch();
    if (!Mage::getSingleton('customer/session')->isLoggedIn()) {
        $this->_redirect(Mage::getUrl('customer/account/login'));
        return;
    }
}
3

Thanks to Marius, the following worked for me (with the URL variant):

    public function preDispatch()
{
    parent::preDispatch();
    if (!Mage::getSingleton('customer/session')->isLoggedIn()) {
        $this->_redirect('customer/account/login');
        return;
    }
}

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.