In some cases it is necessary to create a wholesale directory on a website, which can be accessed by wholesale customers only, while all other users should not be able to access the directory. You can achieve this by using the observer controller_action_predispatch.
Partner With Us
Let's discuss how to grow your business. Get a Free Quote.
Talk to Andrey
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
public function controllerActionPredispatch(Varien_Event_Observer $observer) { if (Mage::helper('privatesite')->isEnabled()) { $customer = Mage::getSingleton('customer/session'); if (!$customer->isLoggedIn()) { $controller = $observer->getEvent()->getControllerAction(); if ($this->_checkRoute($controller)) { $request = $controller->getRequest(); $request->initForward(); $request->setControllerName('account'); $request->setModuleName('customer'); $request->setActionName('login') ->setDispatched(FALSE); } } } } |
i.e. checking if the customer has logged in, and if not, he is redirected to the login page.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
/** * @param $controller Mage_Core_Controller_Varien_Action */ protected function _checkRoute($controller) { if (($controller->getFullActionName() == 'customer_account_login') || $controller->getFullActionName() == 'customer_account_loginPost' ) { return FALSE; } return TRUE; } |
In the method we ignore the paths which do not need this functionality.
Partner With Us
Looking for a partner to grow your business? We are the right company to bring your webstore to success.
Talk to Andrey