2016-10-03 209 views
2
<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登录工作在登录页面正常,但当我尝试在结帐相同的登录它给我像使用Facebook登录登录无法在结帐登录页面上工作,但在登录页面上工作

Uncaught ReferenceError: fblogin is not defined

错误可能是什么问题,并没有关于如何解决它有什么建议?

+0

检查包含函数fblogin()的脚本是否正确加载。 –

回答

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> 

现在它的工作正常。