Here is a nice simple way to make your store only viewable by registered users. And if someone is not registered and tried to view any page they will be taken to the registration form. This can be changes so a guest is shown any page you want. this magento modification goes well with my previous post of restricting user registration to only certain email domains. So check that our after this.
Here I’ll show you how you can create object-specific layout handle functionality for your custom modules.
1. Create Observer
In order to add handle to Magento’s layout update object before it’s too late, we have to observe controller_action_layout_load_before event.<controller_action_layout_load_before>
<observers>
<quotes>
<class>Easylife_Quotes_Model_Observer</class>
<method>changeHomepageContent</method>
</quotes>
</observers>
</controller_action_layout_load_before>
2. Add Handle
Now we have to calculate layout update handle and add it to the layout update object.<?php
class Easylife_Quotes_Model_Observer
{
public function changeHomepageContent(Varien_Event_Observer $observer)
{
$fullActionName = $observer->getEvent()->getAction()->getFullActionName();
if($fullActionName == 'cms_index_index') { // check if current action is CMS Homepage
if (!Mage::getSingleton('customer/session')->isLoggedIn()) { // Check if customer is not logged in
$layout = $observer->getEvent()->getLayout();
$layout->getUpdate()->removeHandle('cms_page');// remove CMS page content
$layout->getUpdate()->addHandle('customer_account_login'); // add login form
}
}
}
}
If you have any queries feel free to leave a comment.......
That’s it!
Hope this helps you!
No comments:
Post a Comment