如何让magento网站仅供注册用户使用?

时间:2012-02-18 10:31:31

标签: magento

我想让我的网站仅对注册用户保密。如果有人试图访问我的主页。登录屏幕应该是第一位的。人们应该注册或登录进入我的网站。

怎么做?来自magento专家的任何建议?

1 个答案:

答案 0 :(得分:6)

如果你进行编程,那么简单的逻辑就是检查用户是否登录,否则使用event:controller_action_predispatch将它们重定向到登录页面。
1 GT;在config.xml中添加以下xml代码:

...
<frontend>
    <events>
        <controller_action_predispatch>
            <observers>
                <yourmodule_controller_action_predispatch>
                    <class>yourmodule/observer</class>
                    <method>checkForLogin</method>
                </yourmodule_controller_action_predispatch>
            </observers>
        </controller_action_predispatch>
    </events>
</frontend>
...

2 - ;在Module的Model /目录中创建一个Observer.php 以下是您需要在Observer类中使用的基本代码:

<?php
class YourCompany_Yourmodule_Model_Observer extends Varien_Object{

    public function checkForLogin(Varien_Event_Observer $observer){
        if(!Mage::getSingleton('customer/session')->isLoggedIn() && $observer->getControllerAction()->getFullActionName() != 'customer_account_login') {
            Mage::app()->getResponse()->setRedirect(Mage::getUrl('customer/account/login'))->sendResponse();
            exit;
        }
    }
}

如果您对更强大的解决方案感兴趣,并且有更多功能可供您的B2B商店使用,那么这里有一个很棒的Magento扩展名为“Store Restriction Pro”: http://www.magepsycho.com/store-restriction-pro.html

祝你好运


更新(13-11-27),JSOV

为了允许忘记密码,登录访问和默认功能,您可以添加要提供权限的默认页面数组,然后验证并重定向。 例如:

...
$allow = array('customer_account_login','customer_account_forgotpassword','customer_account_resetpassword','customer_account_loginpost','customer_account_forgotpasswordpost','customer_account_resetpasswordpost');
if(!Mage::getSingleton('customer/session')->isLoggedIn() && !in_array(strtolower($observer->getControllerAction()->getFullActionName()),$allow) ) {
...
相关问题