Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

X-cart file needs changing ro OSC compatible...


CC

Recommended Posts

I have had this file sent from a friend who had a basic script made to pull info out of his X-Cart store and dump it in a .csv file.

 

Now I need it to do the same thing for OSC, but can anyone make this little script compatible?

 

Here is the code:

<?

require "./smarty.php";
require "./config.php";

$products_table = "xcart_products";
$price_table = "xcart_pricing";
$category_table = "xcart_categories";
$directory = "price_feed";

$database = mysql_connect($sql_host, $sql_user, $sql_password);
mysql_select_db($sql_db, $database); 

$product_query = mysql_query("SELECT productid, productcode, product, categoryid, descr, avail FROM ".$products_table);

$file_content = "CODE|TITLE|DESCRIPTION|CATEGORY|PRICEINCVAT|STOCK|IMAGEURL|URL\n";

$i = 0;
while ($row = mysql_fetch_array($product_query)) 
{
$product_id[$i] = $row['productid'];
$price_query = mysql_query("SELECT price FROM ".$price_table." WHERE productid = ".$product_id[$i]);
{
 $price_row = mysql_fetch_array($price_query);
 $price[$i] = str_replace("\n","", $price_row['price']); 
}
$product_code[$i] = trim($row['productcode']);
$product[$i] = trim($row['product']);
$category_id[$i] = $row['categoryid'];
$category_query = mysql_query("SELECT category FROM ".$category_table." WHERE categoryid = ".$category_id[$i]);
{
 $category_row = mysql_fetch_array($category_query);
 $category_row = str_replace("\n","", $category_row['category']);
       $category_row = str_replace("\r","", $category_row);
       $category[$i] = str_replace("\t","", $category_row);
}
($row['avail'] > 0)?$stock[$i] = "Yes":$stock[$i] = "No";
$descr[$i] = trim($row['descr']);
$descr[$i] = str_replace("<br>","",$descr[$i]);
$descr[$i] = str_replace("<li>","",$descr[$i]);
$descr[$i] = str_replace("</li>","",$descr[$i]);
$descr[$i] = ereg_replace (' +', ' ', trim($descr[$i])); 
$descr[$i] = ereg_replace("[\r\t\n]","",$descr[$i]);
$descr[$i] = str_replace("™","",$descr[$i]);
$file_content .= $product_code[$i]."|".$product[$i]."|".$descr[$i]."|".$category[$i]."|".$price[$i]."|".$stock[$i]."|http://".$xcart_http_host."/productimages/".$product_id[$i]."t.jpg|http://".$xcart_http_host."/customer/product.php?productid=".$product_id[$i]."&cat=".$category_id[$i]."\n";
$i++;
}

$export_file = fopen($directory."/products.csv", "w");
$fp = fwrite($export_file, $file_content);
fclose($export_file);	
unset ($file_content);

?>

 

If anyone can make this work with OSC I would appreciate it.

 

ta.

Link to comment
Share on other sites

I have looked at the easypopulate and have cut it down, but I cant get it into this format.

 

This file is laid out the exact way the .csv file needs to look at the end.

 

I can see in theory what needs doing to it, but when it comes to pulling data from mysql db's I fail miserably.

 

Thats why I want to modify this if possible, so the exact format stays the same.

 

All we need is a DB guru... ;)

Link to comment
Share on other sites

DB guru no needed - however a PHP GURU maybe...

 

 

You have to modify easypopulate.php layout fuction (around line 940)

 

function ep_create_filelayout($dltype)

 

Your wanting a layout of:

CODE|TITLE|DESCRIPTION|CATEGORY|PRICEINCVAT|STOCK|IMAGEURL|URL

 

Thus replacing line 948 to 996 (up to '$filelayout_sql = "SELECT') you need somthing like: (based on easypopulate.php,v 1.18 2002/12/05)

 

$filelayout = array(
? 'v_products_model' ? ? ? ? ? ? ? ?=> $iii++,
? );

foreach ($langcode as $key => $lang){
? $l_id = $lang['id'];
? $filelayout ?= tep_array_merge($filelayout , array(
? 'v_products_name_' . $l_id ? ? ? ?=> $iii++,
? 'v_products_description_' . $l_id => $iii++,
? ));
? }

for($i=1;$i<$max_categories+1;$i++){
? $filelayout = tep_array_merge($filelayout, array('v_categories_name_' . $i => $iii++));
? }

$filelayout ?= tep_array_merge($filelayout , array(
? 'v_products_price' ? ? ? ? ? ? ? ?=> $iii++,
? 'v_products_quantity' ? ? ? ? ? ? => $iii++,
? 'v_products_image' ? ? ? ? ? ? ? ?=> $iii++,
? 'v_products_url_' . $l_id ? ? ? ? => $iii++,
? );

 

 

Have not tried this new code but should be close to what you need. Took all of 15 mins to figure it out - so watch it - it may not be 100%. Backup!!!

 

Good Luck

Link to comment
Share on other sites

No matter, thanks for your help but I have modified the easypopulate to do what I need it to now.

 

Should have looked here earlier for your post I suppose, but got engrossed.

 

Job done anyhow.

 

Cheers.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...