Jump to content


Corporate Sponsors


Latest News: (loading..)

* * * * * 1 votes

HOW TO: Facebook "Like" Button in OSCommerce


77 replies to this topic

#41 blr044

  • Community Member
  • 1,009 posts
  • Real Name:Bennett
  • Gender:Male
  • Location:USA

Posted 27 October 2010, 17:34

View Postburt, on 23 September 2010, 09:09, said:

The iframe version of the FB::like comes as standard in the soon-to-be-release 2.3 version of osCommerce.
I have this ver on hard drive to see what I can do with it. Below is image showing where the text at bottom of the box is being cut off. I've looked under modules and in the languages files in search of where this can be fixed, but keep coming to dead end. I have tried to increase the padding for the infoboxcontens, but to no prevail. Any clues?

Thank you.

#42 matrix2223

  • Community Member
  • 859 posts
  • Real Name:Eric
  • Gender:Male
  • Location:MD USA

Posted 28 October 2010, 05:01

If your adding the js to the left or right columns at the bottom or top you can just use the <script></script> so long as its not enclosed in php and it will work just fine I would think.

also the <script> tag is wrong it should be <script type="text/javascript" .....></script>
Eric

Keep up on osCommerce changes and updates at Github | Understand osCommerce a little further at OsCommerce Documentation | Copy and paste your error message in Google add "in osCommerce" at the end to get relevant answers to most issues.


#43 blr044

  • Community Member
  • 1,009 posts
  • Real Name:Bennett
  • Gender:Male
  • Location:USA

Posted 28 October 2010, 15:32

View Postblr044, on 27 October 2010, 17:34, said:

I have this ver on hard drive to see what I can do with it. Below is image showing where the text at bottom of the box is being cut off. I've looked under modules and in the languages files in search of where this can be fixed, but keep coming to dead end. I have tried to increase the padding for the infoboxcontens, but to no prevail. Any clues?

Thank you.


Soryy, I forgot to attach the image:

[img]http://www.greatdiscounts4u.com/images/scoialbm.jpg[/img]
I am wondering if this might be a image and maybe then, it has something to with size of the image. But do not see anywhere in the social FB like bookmark where it mentions this.

Thank you.

Edited by blr044, 28 October 2010, 15:36.


#44 Xtreme-Hobby

  • Community Member
  • 79 posts
  • Real Name:Jon
  • Location:Canada, Ontario

Posted 28 October 2010, 18:44

Im wanting to add this to my store also. Can this be added to numerous pages on the store for different products?

Not sure how to do this since the web developer that did my site is no longer around.
Please help.
Thanks

#45 spear

  • Community Member
  • 21 posts
  • Real Name:spear

Posted 01 November 2010, 14:19

All examples shown in all 3 pages doesn't worked for me after yeatserday. Before it worked with errors in IE, but seems facebook chaged something and this method not work anymore.
So I decided to try the newest iFrame solution by facebook.
It works in any browser but show correct URL only when it is:
http://mysite.com/catalog/product_info.php?products_id=1
If the address is
http://mysite.com/catalog/product_info.php?cPath=1_11_111&products_id=1
facebook show it in this way:
http://mysite.com/catalog/product_info.php?cPath=1_11_111
the product ID missing :'(

Seems this generating the URL <?php echo HTTP_SERVER . $_SERVER['REQUEST_URI']; ?> is not correct.
Do you guys know a correct command which will transform
product_info.php?cPath=1_11_111&products_id=1
to
product_info.php?products_id=1 to can facebook accept it properly?

Edited by spear, 01 November 2010, 14:23.


#46 spear

  • Community Member
  • 21 posts
  • Real Name:spear

Posted 01 November 2010, 16:15

Problem solved with correct URL, Big thanks to Sam's contribution "Sam's Remove & Prevent duplicate content with the canonical tag": http://addons.oscommerce.com/info/7163

So here are the steps to install the Like button iFrame version:
Add, at the very bottom, before the last ?> in catalog/includes/functions/html_output.php this code:

// remove duplicate content with canonical tag by Spooks 12/2009
function CanonicalLink( $xhtml = false , $ssl = 'SSL' ) {
global $request_type;
$rem_index = false; // Set to true to additionally remove index.php from the uri
$close_tag = ( false === $xhtml ? ' >' : ' />' ); $spage = '';
$domain = ( $request_type == 'SSL' && $ssl == 'SSL' ? HTTPS_SERVER : HTTP_SERVER ); // gets the base URI

// Find the file basename safely = PHP_SELF is unreliable - SCRIPT_NAME can show path to phpcgi
	if ( array_key_exists( 'SCRIPT_NAME', $_SERVER ) 
			&& ( substr( basename( $_SERVER['SCRIPT_NAME'] ), -4, 4 ) == '.php' ) ) {
			$basefile = basename( $_SERVER['SCRIPT_NAME'] );
	} elseif ( array_key_exists( 'PHP_SELF', $_SERVER )
			&& ( substr( basename( $_SERVER['PHP_SELF'] ), -4, 4 ) == '.php' ) ) {
			$basefile = basename( $_SERVER['PHP_SELF'] );
	} else {
	// No base file so we have to return nothing
	return false;
	}
// Don't produce canonicals for SSL pages that bots shouldn't see
$ignore_array = array( 'account', 'address', 'checkout', 'login', 'password', 'logoff' );
// partial match to ssl filenames
	foreach ( $ignore_array as $value ) {
		$spage .= '(' . $value . ')|';
	}
	$spage = rtrim($spage,'|');	
	if (preg_match("/$spage/", $basefile)) return false;
	
// REQUEST_URI usually doesn't exist on Windows servers ( sometimes ORIG_PATH_INFO doesn't either )
	if ( array_key_exists( 'REQUEST_URI', $_SERVER ) ) {
			$request_uri = $_SERVER['REQUEST_URI'];
	} elseif( array_key_exists( 'ORIG_PATH_INFO', $_SERVER ) ) {
			$request_uri = $_SERVER['ORIG_PATH_INFO'];
	} else {
// we need to fail here as we have no REQUEST_URI and return no canonical link html
	return false;
	}	
$remove_array = array( 'currency','language','main_page','page','sort','ref','affiliate_banner_id','max');	
// Add to this array any additional params you need to remove in the same format as the existing

	$page_remove_array = array(FILENAME_PRODUCT_INFO => array('manufacturers_id', 'cPath'),
			          FILENAME_DEFAULT	     => array() );
								
// remove page specific params, should be in same format as previous, given is manufacturers_id & cPath 
// have to be removed in product_info.php only

	if (is_array($page_remove_array[$basefile])) $remove_array = array_merge($remove_array, $page_remove_array[$basefile]);
	
	foreach ( $remove_array as $value ) {
			$search[] = '/&*' . $value . '[=\/]+[\w%..\+]*\/?/i';
	}
	$search[] = ('/&*osCsid.*/'); $search[] = ('/\?\z/');	
	if ($rem_index) $search[] = ('/index.php\/*/');	
	$request_uri = preg_replace('/\?&/', '?', preg_replace($search, '', $request_uri )); 	
 
	echo $domain . $request_uri . PHP_EOL; // this one I modified
} 
///

Place where you want to show Like button in product_info.php this code:

<iframe src="http://www.facebook.com/plugins/like.php?href=<?php CanonicalLink( $xhtml = false, 'SSL' ) ?>&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>

Thats all, works in every browser and browser version

:thumbsup:

#47 Suppleme

  • Community Member
  • 23 posts
  • Real Name:Johnny Boy
  • Gender:Male

Posted 04 November 2010, 16:54

Has anybody managed to get this to work with STS?

Putting the code in the footer works when STS is turned off but not when it is turned on.

I am using the product_info template and want the Like box to appear for each different product.

Any ideas how this would be achieved?

#48 nextwave

  • Community Member
  • 41 posts
  • Real Name:K
  • Gender:Male

Posted 10 November 2010, 02:41

fantastic
was wondering why it hasd stopped working
but this iframe version works great
thanks heaps spear!!!!!
K

#49 smickyb

  • Community Member
  • 4 posts
  • Real Name:Micky

Posted 01 December 2010, 12:34

aaahhh - what a waste!

Guys, simply go to your product_info.php file (parent folder) and try adding the following:

<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like href="<?php echo HTTP_SERVER . $_SERVER['REQUEST_URI']; ?>" show_faces="false" align="right" width="350"></fb:like>

This will quirey the server for the product URL and in turn use the full url as the link on FB to your site.
The 'like' box within your product page will also use a 1+1+1 etc method, as more people like the product the box will add each.

I recommend the code be added in/around that of the product part number section. Looks good and seems to fit well.

Dont see any need to change any of the other code, and this has been tested in Win Enviro's - running IE, Firefox as well as Linux OS running Chrome and Firefox, also works on the Galaxy Sgoogle browser!

Enjoy!
:thumbsup:

#50 surfinagain

  • Community Member
  • 97 posts
  • Real Name:Ken

Posted 04 December 2010, 23:31

View Postsmickyb, on 01 December 2010, 12:34, said:

aaahhh - what a waste!

Guys, simply go to your product_info.php file (parent folder) and try adding the following:

<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like href="<?php echo HTTP_SERVER . $_SERVER['REQUEST_URI']; ?>" show_faces="false" align="right" width="350"></fb:like>

This will quirey the server for the product URL and in turn use the full url as the link on FB to your site.
The 'like' box within your product page will also use a 1+1+1 etc method, as more people like the product the box will add each.

I recommend the code be added in/around that of the product part number section. Looks good and seems to fit well.

Dont see any need to change any of the other code, and this has been tested in Win Enviro's - running IE, Firefox as well as Linux OS running Chrome and Firefox, also works on the Galaxy Sgoogle browser!

Enjoy!
:thumbsup:

this worked perfectly with the exception of IE8. is it working for anyone else in IE8? working perfectly in Firefox, Safari, Opera a Chrome.

#51 surfinagain

  • Community Member
  • 97 posts
  • Real Name:Ken

Posted 04 December 2010, 23:51

View Postsurfinagain, on 04 December 2010, 23:31, said:

this worked perfectly with the exception of IE8. is it working for anyone else in IE8? working perfectly in Firefox, Safari, Opera a Chrome.

i was able to resolve the issue. it was an code location issue. not sure why it mattered to IE8 but moved it and it's working now in all browsers. thanks for the code!

#52 mafiouso

  • Community Member
  • 141 posts
  • Real Name:mafiouso

Posted 26 December 2010, 18:06

some one needs to make a contirb
and is there a link to working site or a screenshot

#53 diy

  • Community Member
  • 352 posts
  • Real Name:kosmas
  • Gender:Male

Posted 29 December 2010, 13:50

I was using the XFBML code as given on facebook page

<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like layout="button_count" show_faces="false" width="450"></fb:like>

on my product info but then i noticed the problem with the fb_xd_fragment pages (people were landing on my site as
http://www.mysite.com/product_info.php?products_id=945?fb_xd_fragment

and i couldnot understand why


Has the problem with fb_xd_fragment been resolved????

** people landing on
http://www.mysite.com/product_info.php?products_id=945?fb_xd_fragment 
get a blank page

Edited by diy, 29 December 2010, 13:51.


#54 data2700

  • Community Member
  • 56 posts
  • Real Name:Data

Posted 23 February 2011, 12:01

View Postsmickyb, on 01 December 2010, 12:34, said:

aaahhh - what a waste!

Guys, simply go to your product_info.php file (parent folder) and try adding the following:

<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like href="<?php echo HTTP_SERVER . $_SERVER['REQUEST_URI']; ?>" show_faces="false" align="right" width="350"></fb:like>

This will quirey the server for the product URL and in turn use the full url as the link on FB to your site.
The 'like' box within your product page will also use a 1+1+1 etc method, as more people like the product the box will add each.

I recommend the code be added in/around that of the product part number section. Looks good and seems to fit well.

Dont see any need to change any of the other code, and this has been tested in Win Enviro's - running IE, Firefox as well as Linux OS running Chrome and Firefox, also works on the Galaxy Sgoogle browser!

This is great! Are there any disadvantages to doing it this way? For example, with the other methods that require a facebook developer ID are you able to track the number of likes by product or something like that which you perhaps cannot do using this method? This method is really easy and looks great on my products listing.

Enjoy!
:thumbsup:


#55 data2700

  • Community Member
  • 56 posts
  • Real Name:Data

Posted 23 February 2011, 14:50

View Postsurfinagain, on 04 December 2010, 23:51, said:

i was able to resolve the issue. it was an code location issue. not sure why it mattered to IE8 but moved it and it's working now in all browsers. thanks for the code!


Can you post where in the code you located the FB code? I am still not able to get it to display in IE8. UPDATED

thanks to surfinagain I kept poking around and trying it in different locations to get it to work in IE8. My site is pretty modified, but the code worked well for me when place in these lines


if (tep_not_null($product_info['products_model'])) {
$products_name = $product_info['products_name'] . '<br><span class="smallText">[' . $product_info['products_id'] . ']</span>';
} else {
$products_name = $product_info['products_name'];
}
?>
<tr>
<td><table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td class="pageHeading" valign="top"><?php echo $products_name; ?></td>
<td class="pageHeading" align="right" valign="top"><?php echo $products_price; ?></td>
</tr>

</table></td>
</tr>
<tr>
<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
</tr>
<tr>
<td class="main">



<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like href="<?php echo HTTP_SERVER . $_SERVER['REQUEST_URI']; ?>" show_faces="false" align="right" width="350"></fb:like>


<?php
if (tep_not_null($product_info['products_image'])) {
?>
<table border="0" cellspacing="0" cellpadding="2" align="right">
<tr>
<td align="center" class="smallText">

Edited by data2700, 23 February 2011, 15:04.


#56 xciso

  • Community Member
  • 140 posts
  • Real Name:xciso

Posted 01 March 2011, 20:28

Anyone know how to make a "like" button to product page.

I have STS and SEO Header tags installed.
I think it has to mod beacuse the url are not the orginal when I use Header tags.

Big thnaks!

#57 bharti

  • Community Member
  • 32 posts
  • Real Name:bharti

Posted 11 March 2011, 08:38

I am trying to add the likes this button to an infobox but no luck... does anyone know how to do this

#58 selpaw

  • Community Member
  • 28 posts
  • Real Name:Luke

Posted 27 March 2011, 03:16

This partially works for me.....

However I have one.. issue...
the image that facebook uses for the link is not of the product? (its using one of the banner links/adverts)
how do i force facebook to use the product image?

Cheers
Luke


View Postspear, on 01 November 2010, 16:15, said:

Problem solved with correct URL, Big thanks to Sam's contribution "Sam's Remove & Prevent duplicate content with the canonical tag": http://addons.oscommerce.com/info/7163

So here are the steps to install the Like button iFrame version:
Add, at the very bottom, before the last ?> in catalog/includes/functions/html_output.php this code:

// remove duplicate content with canonical tag by Spooks 12/2009
function CanonicalLink( $xhtml = false , $ssl = 'SSL' ) {
global $request_type;
$rem_index = false; // Set to true to additionally remove index.php from the uri
$close_tag = ( false === $xhtml ? ' >' : ' />' ); $spage = '';
$domain = ( $request_type == 'SSL' && $ssl == 'SSL' ? HTTPS_SERVER : HTTP_SERVER ); // gets the base URI

// Find the file basename safely = PHP_SELF is unreliable - SCRIPT_NAME can show path to phpcgi
	if ( array_key_exists( 'SCRIPT_NAME', $_SERVER ) 
			&& ( substr( basename( $_SERVER['SCRIPT_NAME'] ), -4, 4 ) == '.php' ) ) {
			$basefile = basename( $_SERVER['SCRIPT_NAME'] );
	} elseif ( array_key_exists( 'PHP_SELF', $_SERVER )
			&& ( substr( basename( $_SERVER['PHP_SELF'] ), -4, 4 ) == '.php' ) ) {
			$basefile = basename( $_SERVER['PHP_SELF'] );
	} else {
	// No base file so we have to return nothing
	return false;
	}
// Don't produce canonicals for SSL pages that bots shouldn't see
$ignore_array = array( 'account', 'address', 'checkout', 'login', 'password', 'logoff' );
// partial match to ssl filenames
	foreach ( $ignore_array as $value ) {
		$spage .= '(' . $value . ')|';
	}
	$spage = rtrim($spage,'|');	
	if (preg_match("/$spage/", $basefile)) return false;
	
// REQUEST_URI usually doesn't exist on Windows servers ( sometimes ORIG_PATH_INFO doesn't either )
	if ( array_key_exists( 'REQUEST_URI', $_SERVER ) ) {
			$request_uri = $_SERVER['REQUEST_URI'];
	} elseif( array_key_exists( 'ORIG_PATH_INFO', $_SERVER ) ) {
			$request_uri = $_SERVER['ORIG_PATH_INFO'];
	} else {
// we need to fail here as we have no REQUEST_URI and return no canonical link html
	return false;
	}	
$remove_array = array( 'currency','language','main_page','page','sort','ref','affiliate_banner_id','max');	
// Add to this array any additional params you need to remove in the same format as the existing

	$page_remove_array = array(FILENAME_PRODUCT_INFO => array('manufacturers_id', 'cPath'),
			          FILENAME_DEFAULT	     => array() );
								
// remove page specific params, should be in same format as previous, given is manufacturers_id & cPath 
// have to be removed in product_info.php only

	if (is_array($page_remove_array[$basefile])) $remove_array = array_merge($remove_array, $page_remove_array[$basefile]);
	
	foreach ( $remove_array as $value ) {
			$search[] = '/&*' . $value . '[=\/]+[\w%..\+]*\/?/i';
	}
	$search[] = ('/&*osCsid.*/'); $search[] = ('/\?\z/');	
	if ($rem_index) $search[] = ('/index.php\/*/');	
	$request_uri = preg_replace('/\?&/', '?', preg_replace($search, '', $request_uri )); 	
 
	echo $domain . $request_uri . PHP_EOL; // this one I modified
} 
///

Place where you want to show Like button in product_info.php this code:

<iframe src="http://www.facebook.com/plugins/like.php?href=<?php CanonicalLink( $xhtml = false, 'SSL' ) ?>&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>

Thats all, works in every browser and browser version

:thumbsup:

Edited by selpaw, 27 March 2011, 03:24.

luke

#59 JoePyler

  • Community Member
  • 14 posts
  • Real Name:Alain Herremans

Posted 02 April 2011, 16:53

I'm using the following code as instructed here:

View Postdata2700, on 23 February 2011, 14:50, said:

Can you post where in the code you located the FB code? I am still not able to get it to display in IE8. UPDATEDthanks to surfinagain I kept poking around and trying it in different locations to get it to work in IE8. My site is pretty modified, but the code worked well for me when place in these lines if (tep_not_null($product_info['products_model'])) { $products_name = $product_info['products_name'] . '<br><span class="smallText">[' . $product_info['products_id'] . ']</span>'; } else { $products_name = $product_info['products_name']; }?> <tr> <td><table border="0" width="100%" cellspacing="0" cellpadding="0"> <tr> <td class="pageHeading" valign="top"><?php echo $products_name; ?></td> <td class="pageHeading" align="right" valign="top"><?php echo $products_price; ?></td> </tr> </table></td> </tr> <tr> <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td> </tr> <tr> <td class="main"><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like href="<?php echo HTTP_SERVER . $_SERVER['REQUEST_URI']; ?>" show_faces="false" align="right" width="350"></fb:like><?php if (tep_not_null($product_info['products_image'])) {?> <table border="0" cellspacing="0" cellpadding="2" align="right"> <tr> <td align="center" class="smallText">

Seems to work good, except a similar problem as mentioned here:

View Postselpaw, on 27 March 2011, 03:16, said:

This partially works for me.....However I have one.. issue...the image that facebook uses for the link is not of the product? (its using one of the banner links/adverts)how do i force facebook to use the product image?CheersLuke

... and another remark is that the text on facebook is also not OK. > The title isn't what I'm expecting and the first part of the text is missing.

So, the message isn't good at all. What can we do about that?

You can check here...

#60 JoePyler

  • Community Member
  • 14 posts
  • Real Name:Alain Herremans

Posted 03 April 2011, 18:18

In the meantime I've been trying some things out.
- When trying with the Facebook iframe code my hole page went wrong... but on facebook I saw the correct product picture :blink:
- Searching the net I've seemed to have found a solution, but I don't know how to implement it... Can someone help me out... here is the link