Search code examples
magento-1.9

Login with facebook button not working on checkout login page but working on login page


<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>

i am using same code in both login and checkout page. Facebook login working fine in login page but when i try same in checkout login it giving me an error like

Uncaught ReferenceError: fblogin is not defined

What could be the problem and are there any suggestions on how to fix it?


Solution

  • I got an answer i forgot to load the below script to call fblogin() on checkout page.

    <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>
    

    Now its working fine.