使用facebook按钮登录不在结帐登录页面上工作,但在登录页面上工作

时间:2016-10-03 06:56:25

标签: magento-1.9

<a href="javascript:void(0)" onclick="return fblogin();" class="wksocialsignup fb_button_ps"><img src="<?php echo $this->helper('socialsignup/active')->getLoginImg()?>" alt="<?php echo $this->__('Facebook')?>" title="<?php echo $this->__('Connect with Facebook')?>"/></a>

我在登录和结帐页面使用相同的代码。 Facebook登录在登录页面工作正常,但当我在结帐登录时尝试相同时,它给我一个错误,如

  

未捕获的ReferenceError:未定义fblogin

可能是什么问题,是否有任何关于如何修复它的建议?

1 个答案:

答案 0 :(得分:2)

我得到了一个答案,我忘了加载下面的脚本来在结帐页面上调用fblogin()。

<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/
window.fbAsyncInit = function() {
    FB.init({appId: '<?php echo $this->getAppId()?>',             
        status     : true, 
            cookie     : true,
            xfbml      : true,
            oauth      : true});

    FB.getLoginStatus(function(response) {
       if (response.status == 'connected') {
        <?php if (Mage::getSingleton('customer/session')->isLoggedIn() && $uid = $this->checkFbUser()):?>
          greet('<?php echo $uid?>');
        <?php endif?>
       }
    });
};
(function(d){
           var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
           js = d.createElement('script'); js.id = id; js.async = true;
           js.src = "//connect.facebook.net/<?php echo Mage::app()->getLocale()->getLocaleCode()?>/all.js";
           d.getElementsByTagName('head')[0].appendChild(js);
         }(document));

function login(){
       document.location.href="<?php echo $this->getUrl('socialsignup/facebook/login')?>?referer=<?php echo Mage::helper('core')->urlEncode($this->helper('core/url')->getCurrentUrl())?>";
    }
    function logout(){
       document.location.href="<?php echo $this->getUrl('socialsignup/facebook/logout')?>";
    }
    function greet(id){
       FB.api('/me', function(response) {
        var src = 'https://graph.facebook.com/'+id+'/picture';
        $$('.welcome-msg')[0].insert('<img height="20" src="'+src+'"/>');
       });
    }

    function fblogin(){
        FB.login(function(response) {

           if (response.status == 'connected') {
                login();
            } else {
                // user is not logged in
                window.location.reload();
            }
        }, {scope:'email,publish_actions'});
        return false;
    }
/*]]>*/
</script>

现在工作正常。

相关问题