Close

September 6, 2013

Magento Category – Only Logged In Users

Recently one of our Magento Enterprise clients, wanted to build a category page such that only logged in users would have access to the page. Turns out this is fairly easy to do with a mix of Javascript and customer design pages.

Note, this requires modifying design layouts and creating template files, so this is not something you can implement in the Magento Admin interface alone.

First, setup your new category in Magento Admin. Go into the Custom Design and add a custom layout Update.

<reference name="content">
<block type="core/template" name="stech_loggedint" as="mecustomeronlypage"  template="catalog/navigation/logged_in_only.phtml" >
</block>
</reference>

Next create a CMS page that non-logged in users will be directed to. We called ours “Members Only” and just had simple instructions directing users to login.

Next you’ll need to create that layout file. For our purposes, we are just going to use Javascript to redirect the user if they are not logged in.

 
<?php if(!Mage::getSingleton('customer/session')->isLoggedIn()): ?>
 
<script>
// redirect to google after 5 seconds
window.setTimeout(function() {
    window.location.href = '/members-only';
}, 1000);
</script>
<?php 
exit;
endif; ?>

All the layout file does is check if the user is logged in or not in Magento. If they are not logged in, call a javascript function to redirect them to our members only page. Then it will “exit” the command of the page, so the rest of the products are not displayed. This WILL cause anything below this layout to render (ie: footer etc), but for our purposes that was not a problem.

As with anything, if you need a professional Magento integration expert to help you implement the above solution, please do not hesitate to contact us.

Leave a Reply

Your email address will not be published. Required fields are marked *