1

i want to show product detail page to logged in user only how can i do this ?? user will be redirected to login page if he is not logged.

I guess if any way so that i can do it via created a custome .phml file and called it to header of product info (custom deign of category section )

3

You can create an observer for the event controller_action_predispatch_catalog_product_view that looks like this:

For this you need an extension.
Let's call it Easylife_Restriction.
Is should contain the following files:

app/etc/modules/Easylife_Restriction.xml - the declaration file

<?xml version="1.0"?>
<config>
    <modules>
        <Easylife_Restriction>
            <codePool>local</codePool>
            <active>true</active>
            <depends>
                <Mage_Catalog />
            </depends>
        </Easylife_Restriction>
    </modules>
</config>

app/code/local/Easylife/Restriction/etc/config.xml - the configuration file

<?xml version="1.0"?>
<config>
    <modules>
        <Easylife_Restriction>
            <version>1.0.0</version>
        </Easylife_Restriction>
    </modules>
    <global>
        <models>
             <easylife_restriction>
                 <class>Easylife_Restriction_Model</class>
             </easylife_restriction>
        </models>
    </global>
    <frontend>
        <events>
             <controller_action_predispatch_catalog_product_view>
                 <observers>
                      <easylife_restriction>
                           <class>easylife_restriction/observer</class>
                           <method>redirectToLogin</method>
                      </easylife_restriction>
                 </observers>
             </controller_action_predispatch_catalog_product_view>
        </events>
    </frontend>
</config>

app/code/local/Easylife/Restriction/Model/Observer.php - the actual observer

class Easylife_Restriction_Model_Observer {
    public function redirectToLogin(Varien_Event_Observer $observer)
    {
        if(!Mage::helper('customer')->isLoggedIn()){
            Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('customer/account/login'));
        }
    }
}

Clear the cache when you are done.
Read here more about how event-observers work in Magento.

  • where can i put that file and call it – mcoder Oct 3 '14 at 11:51
  • @saurav. See my update answer. I just created an extension for you – Marius Oct 3 '14 at 12:00
  • Good works @Marius..upvote from me:) – Amit Bera Oct 3 '14 at 12:08

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.