How To: Export ShareASale Datafeed File For Your ISC Store

For articles specific to version 6.x
Post Reply
MegaFemaTron2
Confirmed
Confirmed
Posts: 84
Joined: Thu Oct 13, 2011 8:37 pm

How To: Export ShareASale Datafeed File For Your ISC Store

Post by MegaFemaTron2 »

I went through the trouble of adding fields to the export feature files in ISC so one could create a custom export template for ShareASale. The problem was 1. It got ridiculous, 2. It quickly became harder than it needed to be, 3. There are some static fields like "Status" and "Merchant ID" where the static values could not be added and exported. #3 was really the deal breaker. I wanted the datafeed file to be as complete as possible when exported.

So... I wrote this php script to create the file. Use and tweak it as you wish. Many of the fields will be empty for our store but if you need them, adding values should be pretty easy.

The formatting on this is awesome by the way but a copy and paste jacked it up a bit. :)

Code: Select all

<pre>
<?php
// Make a MySQL Connection
mysql_connect("localhost", "yourusername", "yourpassword") or die(mysql_error());
mysql_select_db("yourdatabase") or die(mysql_error());

$filename = "yourfilename.csv";

$fp = fopen($filename, "w");

// fetch a row and write the column names out to the file
$head = array("SKU"				=>"SKU",
		"Name"				=>"Name",
		"URL to product"		=>"URL to product",
		"Price"				=>"Price",
		"Retail Price"			=>"Retail Price",
		"URL to image"			=>"URL to image",
		"URL to thumbnail image"	=>"URL to thumbnail image",
		"Commission"			=>"Commission",
		"Category"			        =>"Category",
		"SubCategory"			=>"SubCategory",
		"Description"			=>"Description",
		"SearchTerms"			=>"SearchTerms",
		"Status"			        =>"Status",
		"MerchantID"			=>"MerchantID",
		"Custom 1"			=>"Custom 1",
		"Custom 2"			=>"Custom 2",
		"Custom 3"			=>"Custom 3",
		"Custom 4"			=>"Custom 4",
		"Custom 5"			=>"Custom 5",
		"Manufacturer"			=>"Manufacturer",
		"PartNumber"			=>"PartNumber",
		"MerchantCategory"		=>"MerchantCategory",
		"MerchantSubcategory"	=>"MerchantSubcategory",
		"ShortDescription"		=>"ShortDescription",
		"ISBN"				=>"ISBN",
		"UPC"				=>"UPC",
		"CrossSell"			        =>"CrossSell",
		"MerchantGroup"		=>"MerchantGroup",
		"MerchantSubgroup"		=>"MerchantSubgroup",
		"CompatibleWith"		=>"CompatibleWith",
		"CompareTo"			=>"CompareTo",
		"QuantityDiscount"		=>"QuantityDiscount",
		"Bestseller" 			=>"Bestseller",
		"AddToCartURL" 		=>"AddToCartURL",
		"ReviewsRSSURL"		=>"ReviewsRSSURL",
		"Option1"			=>"Option1",
		"Option2"			=>"Option2",
		"Option3"			=>"Option3",
		"Option4"			=>"Option4",
		"Option5"			=>"Option5",
		"ReservedForFutureUse1" 	=>"ReservedForFutureUse",
		"ReservedForFutureUse2" 	=>"ReservedForFutureUse",
		"ReservedForFutureUse3" 	=>"ReservedForFutureUse",
		"ReservedForFutureUse4" 	=>"ReservedForFutureUse",
		"ReservedForFutureUse5" 	=>"ReservedForFutureUse",
		"ReservedForFutureUse6" 	=>"ReservedForFutureUse",
		"ReservedForFutureUse7" 	=>"ReservedForFutureUse",
		"ReservedForFutureUse8" 	=>"ReservedForFutureUse",
		"ReservedForFutureUse9" 	=>"ReservedForFutureUse",
		"ReservedForFutureUse10"	=>"ReservedForFutureUse"
		);
$line = "";

$comma = "";

foreach($head as $name => $value) {
$line .= $comma . '"' . str_replace('"', '""', $name) . '"';
$comma = ",";
}

$line .= "\n";

fputs($fp, $line);

$result = mysql_query("SELECT isc_products.productid, 
				isc_products.prodcode,
				isc_products.prodname,
				isc_products.produrl,
				isc_products.prodprice,
				isc_products.proddesc,
				isc_products.upc,
				isc_categories.catname, 
				isc_product_images.imagefilestd,
				isc_product_images.imagefilethumb,
				isc_brands.brandname
			   FROM isc_products 
 		     INNER JOIN isc_categories 
 			     ON isc_products.prodcatids = isc_categories.categoryid 
 		     INNER JOIN isc_product_images 
 			     ON isc_products.productid = isc_product_images.imageprodid 
 		     INNER JOIN isc_brands 
 			     ON isc_products.prodbrandid = isc_brands.brandid 
 			ORDER BY isc_categories.catname")
or die(mysql_error());

// and loop through the actual data
while($row = mysql_fetch_array( $result )) {

	$prodid = $row['productid'];
	$sku = $row['prodcode'];
	$name = $row['prodname'];
	$produrl = $row['produrl'];
	$urltoproduct = "http://www.yourwebsite.com/$produrl";
	$price = $row['prodprice'];
	$retailprice = ""; 
	$imageurl = $row['imagefilestd'];
	$thumburl = $row['imagefilethumb'];
	$urltoimage = "http://www.yourwebsite.com/$imageurl";
	$urltothumbnailimage = "http://www.yourwebsite.com/$thumburl";
	$commission = ""; 
	$category = ""; 
	$subcategory = "";
	$description = $row['proddesc'];
	$searchterms = ""; 
	$status = "Instock"; 
	$merchantid = "yourid"; 
	$custom1 = ""; 
	$custom2 = ""; 
	$custom3 = ""; 
	$custom4 = ""; 
	$custom5 = ""; 
	$manufacturer = $row['brandname'];
	$partnumber = ""; 
	$merchantcategory = $row['catname'];
	$merchantsubcategory = ""; 
	$shortdescription = ""; 
	$isbn = ""; 	 
	$upc = $row['upc'];
	$crosssell = ""; 
	$merchantgroup = ""; 
	$merchantsubgroup = ""; 
	$compatiblewith = ""; 
	$compareto = ""; 
	$quantitydiscount = ""; 
	$bestseller = ""; 
	$addtocarturl = "http://www.yourwebsite.com/cart.php?action=add&product_id=$prodid"; 
	$reviewsrssurl = ""; 
	$option1 = ""; 
	$option2 = ""; 
	$option3 = ""; 
	$option4 = ""; 
	$option5 = ""; 
	$reservedforfutureuse1 = "";
	$reservedforfutureuse2 = ""; 
	$reservedforfutureuse3 = ""; 
	$reservedforfutureuse4 = ""; 
	$reservedforfutureuse5 = ""; 
	$reservedforfutureuse6 = ""; 
	$reservedforfutureuse7 = ""; 
	$reservedforfutureuse8 = ""; 
	$reservedforfutureuse9 = ""; 
	$reservedforfutureuse10 = "";

	$cols = array($sku,
	$name,
	$urltoproduct,
	$price,
	$retailprice,
	$urltoimage,
	$urltothumbnailimage,
	$commission,
	$category,
	$subcategory,
	$description,
	$searchterms,
	$status,
	$merchantid,
	$custom1,
	$custom2,
	$custom3,
	$custom4,
	$custom5,
	$manufacturer,
	$partnumber,
	$merchantcategory,
	$merchantsubcategory,
	$shortdescription,
	$isbn,
	$upc,
	$crosssell,
	$merchantgroup,
	$merchantsubgroup,
	$compatiblewith,
	$compareto,
	$quantitydiscount,
	$bestseller,
	$addtocarturl,
	$reviewsrssurl,
	$option1,
	$option2,
	$option3,
	$option4,
	$option5,
	$reservedforfutureuse,
	$reservedforfutureuse,
	$reservedforfutureuse,
	$reservedforfutureuse,
	$reservedforfutureuse,
	$reservedforfutureuse,
	$reservedforfutureuse,
	$reservedforfutureuse,
	$reservedforfutureuse,
	$reservedforfutureuse
	);

$line = "";

$comma = "";

foreach($cols as $value) {
$line .= $comma . '"' . str_replace('"', '""', $value) . '"';
$comma = ",";
}

$line .= "\n";

fputs($fp, $line);	
} 

fclose($fp);
?>
There might have been an easier way but I'm no coder and this way works. If you know of an easier way to have done this, please share. :)

NOTE: I have a field called produrl because I use the custom slugs 2.0 mod. If you don't have this mod, then you can use your product name instead since that's natively what ISC uses for the url.

My plan is to tweak this so that it only grabs data for products that are marked as visible and also products that have a stocklevel say higher than 5. But it was such an adventure for me to learn how to write all those joins and what not that I'm not ready to tackle that. hahahahahaha it may be easy (hopefully).
ISC 6.1.1 Ultimate Edition
Post Reply