Important alert: (current site time 5/21/2013 5:45:07 PM EDT)
 

VB icon

Google Feed Script for sunshop

Email
Submitted on: 10/9/2007 10:27:37 AM
By: Maheshkarekar  
Level: Beginner
User Rating: By 1 Users
Compatibility: PHP 4.0
Views: 21145
author picture
(About the author)
 
     Mod for Sunshop 3.5 to feed data to Google base

 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
// for :Google Feed Script for sunshop
//**************************************
Ftp code was borrowed from oscommerce contrib rest i coded.Thanks to opensource community.
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: Google Feed Script for sunshop
// Description:Mod for Sunshop 3.5 to feed data to Google base
// By: Maheshkarekar
//
// Inputs:http://www.yourdomain.com/sunshop/index.php?action=googlefeed
Live Example at http://www.mayoo.com
//
// Returns:Creates a data feed and ftps to uploads.google.com
//
// Assumes:Following files need modification index.php,global.php
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=2362&lngWId=8//for details.//**************************************

//Author Mahesh Kaekar
//Note: This is a Mod to Sunshop 3.5 
You need to modify a few files from sunshop folder
The way this works is we add a new action googlefeed to our index.php script
http://www.yourdomain.com/sunshop/index.php?action=googlefeed
1. Modify /sunshop/index.php - Add the following code after "elseif ($action == "item") {...}"
elseif ($action == "googlefeed") {
 	$show_categories = showcategories ();
		$navigation = "Google Feed";
		$feed = google_feed();
		eval("\$googlefeed_message = \"".$feed."\";");
		$main_content = stripslashes($googlefeed_message);
		start();
}
2. Modify /sunshop/global.php add Method googlerfeed()
Note ftp code I borrowed from som osccommerce website patch
// ###################### Google feed #######################
function google_feed(){
 global $DB_site, $dbprefix;
 $temp=$DB_site->query("Select title As Title,title As Description, substr(title,1,locate(' ',title)) as Brand,	'Used' As Condition,''	As ISBN,concat(concat('http://www.mayoo.com/sunshop/index.php?action=item&id=',itemid), '&prevaction=pricelist') As Link,'' Mpn,format(if(sprice=0,price,sprice),2) As Price,'Computers' Product_type,concat('US:Ground:',format(fship,2)) as Shipping,'' UPC,'Paypal' Payment_Accepted,if (length(thumb) >0,concat('http://www.mayoo.com/sunshop/images/products/',thumb),'') As Image_link FROM ".$dbprefix."items");	
	//Open file to write
	$filename = "mayoostoredb.txt";
	$tab = "\t";
	$cr = "\n";
	$data = "Title".$tab."Description".$tab."Brand".$tab."Condition".$tab."ISBN".$tab."Link".$tab."Mpn".$tab."Price".$tab."Product_type".$tab."Shipping".$tab."UPC".$tab."Payment_Accepted".$tab."image_link".$cr;
	$fp = fopen($filename,"w"); // $fp is now the file pointer to file $filename 
	if($fp){
	
	//Write headings 
	fwrite($fp,$data); 
	while ($row=$DB_site->fetch_array($temp)) {
		$title = $row[Title];
		$description = $row[Description];
		$brand=$row[Brand];
		$condition=$row[Condition];
		$isbn = $row[ISBN];
		$link = $row[Link];
		$mpn = $row[Mpn];
		$price = $row[Price];
		$product_type = $row[Product_type];
		$shipping = $row[Shipping];
		$upc = $row[UPC];
		$payment_accepted = $row[Payment_Accepted];
		$image_link=$row[Image_link];
		//Prepare data
		$data = $title.$tab.$description.$tab.$brand.$tab.$condition.$tab.$isbn.$tab.$link.$tab.$mpn.$tab.$price.$tab.$product_type.$tab.$shipping.$tab.$upc.$tab.$payment_accepted.$tab.$image_link.$cr;
		
		//write data 
		fwrite($fp,$data); 
		} //while
		//Close File
		fclose($fp);
	} //if
	//ftp file
	$ftp_ip= "uploads.google.com";
	$ftp_username = "yourftpid";
	$ftp_password = "yourpassword";
	$ftp_directory = "/";
	chmod($filename, 0777);
	// set up basic connection
	$conn_id = ftp_connect($ftp_ip);
	if ( $conn_id == false )
	{
	$out = "FTP open connection failed to $ftp_ip <BR>\n" ;
	return $out;
	}
	// login with username and password
	$login_result = ftp_login($conn_id, $ftp_username, $ftp_password);
	// check connection
	if ((!$conn_id) || (!$login_result)) {
	$out = "FTP connection has failed!<BR>\nAttempted to connect to " . $ftp_ip . " for user " . $ftp_username . "<BR>\n";
	return $out;
	} else {
	$out = "Connected to " . $ftp_ip . ", for user " . $ftp_username . "<BR>\n";
	}
	if ( strlen( $ftpdirectory ) > 0 )
	{
	if (ftp_chdir($conn_id, $ftp_directory )) {
	$out = $out . "Current directory is now: " . ftp_pwd($conn_id) . "<BR>\n";
	} else {
	$out = $out . "Couldn't change directory on" . $ftp_ip . "<BR>\n";
	return $out;
	}
	}
	ftp_pasv ( $conn_id, true ) ;
	// upload the file
	$upload = ftp_put( $conn_id, $filename, $filename, FTP_ASCII );
	// check upload status
	if (!$upload) {
	$out = $out . "$ftp_ip: FTP upload has failed!<BR>\n";
	return false;
	} else {
	$out = $out . "Uploaded " . $filename . " to " . $ftp_ip . " as " . $filename . "<BR>\n";
	chmod($filename, 0755);
	}
	
	
	return $out;
}
3. Now type the sunshop index url with actin=googlefeed in your browser
http://wwww.yourdomain.com/sunshop/index.php?action=googlefeed
Thanks
Mahesh Karekar 
MaheshKarekar@yahoo.com


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

9/13/2010 1:47:45 PMjayendra

good this project
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.