How to create member only module in Magento?
June 13, 2011 14:26
Sometimes you may have to implement the module that is for member only, how to do it in Magento?
In your controller which extends Mage_Core_Controller_Front_Action, add the following function:
public function preDispatch() { parent::preDispatch(); $action = $this->getRequest()->getActionName(); $loginUrl = Mage::helper('customer')->getLoginUrl(); if (!Mage::getSingleton('customer/session')->authenticate($this, $loginUrl)) { $this->setFlag('', self::FLAG_NO_DISPATCH, true); } }
If the customer didn’t login, the controller will redirect the page to login page.
Got it?
Happy Magento’ing ~
Allows you to restrict locations of your website from customers who are not finalized in. This element comes with a few different configurable options. You are able to restrict the product selection, the cms websites, or restrict everything.