Jump to content



Latest News: (loading..)

- - - - -

Export orders into csv


  • Please log in to reply
100 replies to this topic

#81   kcmstrpc

kcmstrpc
  • Members
  • 1 posts
  • Real Name:Karl

Posted 25 June 2009 - 08:41 PM

:sweating:   Hello,  I've been reading through all the posts on oscommerc's forums and I've benefited a lot from it in terms of setting up my first store etc.  Adding modifications etc.  I'm by no means a php coder.  I'm out of work and trying to start a business to have an income as well it has a charitable function as well to help give back to the community.  I have no budget since I'm unemployed and barely making it by right now.

Is there someone who could take a look at this code and tell me how to get attributes into the export CVS report?  I've seen this asked by many people on here and never a straight here's the code >>> answer.  I only saw it once and now can't find it again.  Though i copied it it lists the same purchase 3 times in a row with all customer information but on the last line it actually lists the attributes.  But the 2nd  code box below format is way better and has an least i think 6 or 7 items with order name, comment headers etc.

The one csv export i wanted had the option drop downs  order status, start and finish date.  But including the attributes.  As the business will start by selling t-shirts with different sizes.  Eventually it will have different color t-shirts available for the same shirt etc.

I'm sure for a true PHP experienced coder, not a want to be hack like myself this is a simple adjustment.

The one export_orders.php i found on the site had this addition after listing the products but when i try as i might i can't get it to work without parsing errors etc.

//on liste les options des produits dans la boucle article
$option = tep_db_query("select products_options,products_options_values,options_values_price,price_prefix from ".TABLE_ORDERS_PRODUCTS_ATTRIBUTES."
where orders_products_id= " . $idrelationattribut);


//where orders_id = " . $Orders_id);

while($row_option = mysql_fetch_array($option)) {



$idproduitoscommerce = $row_orders_products[0] ;

Code I would like this correctly added to:

<?php
/*
  $Id: exportorders.php,v 1.1 April 21, 2006 Harris Ahmed (Original Contribution)  $

  Edited and enhanced by Nico Maurer 12-12-2006
/************************************************************************
/* Changed By Gil Dvir 04-01-2008 admin at hebnuker dot org   			*
/* Addind some featurs to the original code				   			*
/*	  Improved selection of orders Display Type:						*
/*		1. Create CSV file												*
/*		2. Print to screen in table format								*
/* 		3. Adding heading to the CSV / Html output			  			*
/*		4. Sorting & group orders by customers id (name)	  			*
/*		5. Link on the order number, from the Html output page		  *
/*		direct to the customer order Details.						   *
/*		********************  Instructions  **********************	  *
/*	  Please change to your site URL at line 170					  *
/*		I choose for my site the Data to be showed as follows			*
/*	  		a. Order number												*
/*	  		b. Date Purchased				  							*
/*	  		c. Country													*
/*	  		d. Customer name											*
/*	  		e. Model number												*
/*	  		f. Quantity ordered											*
/*	  		g. Product name												*
/*	  		h. Comments													*
/* 		You can change it to your preferring							*
/************************************************************************
   osCommerce, Open Source E-Commerce Solutions
  [url="http://www.oscommerce.com"]http://www.oscommerce.com[/url]

  Copyright © 2004 Oscommerce

  Installation and Use: Put the file in the Admin Folder and Call the script: www.yourstore.com/catalog/admin/export_orders_csv.php
  In the Start field put the first oder no. to export,
  in the end field the last order no. (or choose a big number for export of all orders up to the current date). In the status field
  put the number of the order status to export (the status numbers may vary from shop to shop). For my store status 1 means "processing", which
  is the status orders need to be exported for my store.
  Still very hard coded but it works for my ressource planning software.

  In order to make a link in your reports section of admin do the following, after uploading the file

1.	Insert this line in admin/includes/filenames.php: Under Definitions

	  // Export orders to CSV
		  define('FILENAME_EXPORT_ORDERS_CSV', 'export_orders_csv.php');
		  // End Export orders to csv

2.	Insert this line in admin/includes/languages/english.php: under definitions

	 // EXPORT_ORDERS_CSV
		 define('BOX_EXPORT_ORDERS_CSV', 'Export my orders to CSV');
		 // End EXPORT_ORDERS_CSV

3.	In admin/includes/boxes/reports.php, change this (or whichever line is NOT last in the menu):

	 // add export orders to csv
		 '<a href="' . tep_href_link(FILENAME_EXPORT_ORDERS_CSV, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_EXPORT_ORDERS_CSV . '</a><br>' .
		 // end export orders to csv
*/

require('../admin/includes/application_top.php');
// Check if the form is submitted
if (!$submitted || ($submitted != 1 && $submitted != 2))
{
?>
<!-- header_eof //-->
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="../Documents/projectA/PjA/pad/includes/stylesheet.css">
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->
<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
  <tr>
	<td width="<?php echo BOX_WIDTH; ?>" valign="top">
 <table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
<!-- left_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
<!-- left_navigation_eof //-->
	</table>
 </td>
<!-- body_text //-->
	<td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
	  <tr>
		<td><table border="0" width="100%" cellspacing="0" cellpadding="0">
		  <tr>
			<td class="pageHeading"><?php echo "Export Order" ?></td>
			<td class="pageHeading" align="left"></td>
		  </tr>
		</table>
  </td>
	  </tr>
   <!-- first ends // -->
	  <tr>
		<td>

<table border="0" style="font-family:verdana;font-size:11px;" width="100%" cellspacing="2" cellpadding="2">
<tr>
<td>

<form method="GET" action="<?php echo $PHP_SELF; ?>">
<table border="0" style="font-family:verdana;font-size:11px;" cellpadding="3">
<tr>
<td><?php echo "Start Order #:"; ?></td>
<td><input name="start" size="5" value="<?php echo $start; ?>">
</tr>
<tr>
<td><?php echo "End Order #:" ; ?></td>
<td><input name="end" size="5" value="<?php echo $end; ?>">
</tr>
<tr>
<td><?php echo "Order Status:"; ?></td>
<?php
  $orders_statuses = array();
  $orders_status_array = array();
  $orders_status_query = tep_db_query("select orders_status_id, orders_status_name from " . TABLE_ORDERS_STATUS . " where language_id = '" . (int)$languages_id . "'");
  while ($orders_status = tep_db_fetch_array($orders_status_query)) {
	$orders_statuses[] = array('id' => $orders_status['orders_status_id'],
							   'text' => $orders_status['orders_status_name']);
	$orders_status_array[$orders_status['orders_status_id']] = $orders_status['orders_status_name'];
  }
?>
<td><?php echo tep_draw_pull_down_menu('status', array_merge(array(array('id' => '', 'text' => 'All Orders')), $orders_statuses), $status); ?>
</tr>
	
<tr>
<td><?php echo "Display Type:"; ?></td>
<td>
<select name="submitted">
	<option value="1">Create CSV File</option>
	<option value="2">Print to Screen</option>
</select>
</td></tr>

<tr>
<td>&nbsp;</td>
<td><input type="submit" value="<?php echo "Generate"; ?>"></td>
</tr>
</table></form>
	</td></tr></table>
	</td></tr></table>
	</td></tr>
<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>

<?php
}
// submitted so generate csv if the form is submitted
else
{
generatecsv($start, $end, $status, $submitted);
}

// generates csv file from $start order to $end order, inclusive
function generatecsv($start, $end, $status, $submitted)
{

 $order_edit = "&action=edit";
 $order_url = "http://www.ohjacky.com/pad/orders.php?oID=$order_num";
 $space = " ";
 
 $open_table = $submitted == 1 ? '' : '<table width=100% border=1 cellspacing=0 cellpadding=0>';
 $close_table = $submitted == 1 ? '' : '</table>';
 $open_header = $submitted == 1 ? '' : '<tr bgcolor=#cccccc>';
 $close_header = $submitted == 1 ? '' : '</tr>';
 $open_row = $submitted == 1 ? '' : '<tr>';
 $close_row = $submitted == 1 ? '' : '</tr>';
 $open_column = $submitted == 1 ? '' : '<td><font face=verdana size=2>';
 $delim = $submitted == 1 ? ',' : '</font></td>';

if($submitted == 1){ //  Heading CSV output file
	$csv_output .= "Num".$delim;
	$csv_output .= "Date".$delim;
	$csv_output .= "Bill Name".$delim;
	$csv_output .= "Last".$delim;
	$csv_output .= "Address1".$delim;
	$csv_output .= "Address2".$delim;
	$csv_output .= "City".$delim;
	$csv_output .= "State".$delim;
	$csv_output .= "Zip".$delim;
	$csv_output .= "Phone".$delim;
	$csv_output .= "Ship Name".$delim;
	$csv_output .= "Address1".$delim;
	$csv_output .= "Address2".$delim;
	$csv_output .= "City".$delim;
	$csv_output .= "State".$delim;
	$csv_output .= "Zip".$delim;
	$csv_output .= "Model".$delim;
	$csv_output .= "Qty".$delim;
	$csv_output .= "Product".$delim;
$csv_output .=filter_text($row_option["products_options"]). $delim; //préfixe
		$csv_output .=filter_text($row_option["products_options_values"] ). $delim;	
$csv_output .= "Comments".$delim;
		$csv_output .= "Model".$delim;
	$csv_output .= "Qty".$delim;
	$csv_output .= "Product".$delim;
$csv_output .=filter_text($row_option["products_options"]). $delim; //préfixe
		$csv_output .=filter_text($row_option["products_options_values"] ). $delim;
	$csv_output .= "Comments".$delim;
		$csv_output .= "Model".$delim;
	$csv_output .= "Qty".$delim;
	$csv_output .= "Product".$delim;
$csv_output .=filter_text($row_option["products_options"]). $delim; //préfixe
		$csv_output .=filter_text($row_option["products_options_values"] ). $delim;
	$csv_output .= "Comments".$delim;
		$csv_output .= "Model".$delim;
	$csv_output .= "Qty".$delim;
	$csv_output .= "Product".$delim;
$csv_output .=filter_text($row_option["products_options"]). $delim; //préfixe
		$csv_output .=filter_text($row_option["products_options_values"] ). $delim;
	$csv_output .= "Comments".$delim;
		$csv_output .= "Model".$delim;
	$csv_output .= "Qty".$delim;
	$csv_output .= "Product".$delim;
$csv_output .=filter_text($row_option["products_options"]). $delim; //préfixe
		$csv_output .=filter_text($row_option["products_options_values"] ). $delim;
	$csv_output .= "Comments".$delim;
		$csv_output .= "Model".$delim;
	$csv_output .= "Qty".$delim;
	$csv_output .= "Product".$delim;
$csv_output .=filter_text($row_option["products_options"]). $delim; //préfixe
		$csv_output .=filter_text($row_option["products_options_values"] ). $delim;
	$csv_output .= "Comments".$delim;
		$csv_output .= "Model".$delim;
	$csv_output .= "Qty".$delim;
	$csv_output .= "Product".$delim;
$csv_output .=filter_text($row_option["products_options"]). $delim; //préfixe
		$csv_output .=filter_text($row_option["products_options_values"] ). $delim;
	$csv_output .= "Comments".$delim;
		$csv_output .= "Model".$delim;
	$csv_output .= "Qty".$delim;
	$csv_output .= "Product".$delim;
$csv_output .=filter_text($row_option["products_options"]). $delim; //préfixe
		$csv_output .=filter_text($row_option["products_options_values"] ). $delim;
	$csv_output .= "Comments".$delim;
		$csv_output .= "Model".$delim;
	$csv_output .= "Qty".$delim;
	$csv_output .= "Product".$delim;
$csv_output .=filter_text($row_option["products_options"]). $delim; //préfixe
		$csv_output .=filter_text($row_option["products_options_values"] ). $delim;
	$csv_output .= "Comments".$delim;
		$csv_output .= "Model".$delim;
	$csv_output .= "Qty".$delim;
	$csv_output .= "Product".$delim;
$csv_output .=filter_text($row_option["products_options"]). $delim; //préfixe
		$csv_output .=filter_text($row_option["products_options_values"] ). $delim;
	$csv_output .= "Comments".$delim;
	$csv_output .= "\n";
}

 $orders = tep_db_query("select customers_id, orders_id, date_purchased, customers_name
 , cc_owner, customers_company, customers_email_address,
billing_street_address, billing_city, billing_state, billing_postcode,
billing_country, customers_telephone, delivery_name,
delivery_company, delivery_street_address, delivery_city, delivery_state,
delivery_postcode, delivery_country, cc_type, cc_number, cc_expires, payment_method, orders_status
from " . TABLE_ORDERS . " where 1 " . ($start ? "and orders_id >= $start " : "") . ($end ? "and orders_id <= $end " : "") . ($status ? "and orders_status = $status " : "") . "order by customers_id");

while ($row_orders = mysql_fetch_array($orders)) { //start one loop

$Orders_id = $row_orders["orders_id"];
$orders_status = $row_orders["orders_status"];
$customers_id = $row_orders["customers_id"];
$customers_gender = $row_orders["customers_gender"];
$Date1 = $row_orders["date_purchased"];
//list($Date, $Time) = explode (' ',$Date1);
$Date = date('m.d.Y', strtotime($Date1));
$Time= date('H:i:s', strtotime($Date1));
$Name_On_Card1 = $row_orders["customers_name"];
$Name_On_Card = filter_text($Name_On_Card1);// order changed
list($First_Name,$Last_Name) = explode(', ',$Name_On_Card1); // order changed
$Company = filter_text($row_orders["customers_company"]);
$email = filter_text($row_orders["customers_email_address"]);
$payment = filter_text($row_orders["payment_method"]);
$Billing_Address_1 = filter_text($row_orders["billing_street_address"]);
$Billing_Address_2 = "";
$Billing_City = filter_text($row_orders["billing_city"]);
$Billing_State = filter_text($row_orders["billing_state"]);
$Billing_Zip = filter_text($row_orders["billing_postcode"]);
$Billing_Country = str_replace("(48 Contiguous Sta", "", $row_orders["billing_country"]);
$Billing_Phone = filter_text($row_orders["customers_telephone"]);
$ShipTo_Name1 = $row_orders["delivery_name"];
$ShipTo_Name = filter_text($ShipTo_Name1); // order changed
list($ShipTo_First_Name,$ShipTo_Last_Name) = explode(', ',$ShipTo_Name1); // order changed
$ShipTo_Company = filter_text($row_orders["delivery_company"]);
$ShipTo_Address_1 = filter_text($row_orders["delivery_street_address"]);
$ShipTo_Address_2 = "";
$ShipTo_City = filter_text($row_orders["delivery_city"]);
$ShipTo_State = filter_text($row_orders["delivery_state"]);
$ShipTo_Zip = filter_text($row_orders["delivery_postcode"]);
$ShipTo_Country = str_replace("(48 Contiguous Sta", "", $row_orders["delivery_country"]);
$ShipTo_Phone = "";
$Card_Type = $row_orders["cc_type"];
$Card_Number = $row_orders["cc_number"];
$Exp_Date = $row_orders["cc_expires"];
$Bank_Name = "";
$Gateway  = "";
$AVS_Code = "";
$Transaction_ID = "";
$Order_Special_Notes = "";
// --------------------	QUERIES 1  ------------------------------------//
//Orders_status_history for comments
 $orders_status_history = tep_db_query("select comments from " . TABLE_ORDERS_STATUS_HISTORY . "
 where orders_id = " . $Orders_id);
 //$row_orders_status_history = tep_db_fetch_array($comments);
 while($row_orders_status_history = mysql_fetch_array($orders_status_history)) {
 // end //

$Comments = filter_text($row_orders_status_history["comments"]);

}
// --------------------	QUERIES 2  ------------------------------------//
//Orders_subtotal
$orders_subtotal = tep_db_query("select value from " . TABLE_ORDERS_TOTAL . "
where class = 'ot_subtotal' and orders_id = " . $Orders_id);
//$row_orders_subtotal = tep_db_fetch_array($orders_subtotal);
while($row_orders_subtotal = mysql_fetch_array($orders_subtotal)) {
 // end //
$Order_Subtotal = filter_text($row_orders_subtotal["value"]);
}
// --------------------	QUERIES 3  ------------------------------------//
//Orders_tax
$Order_Tax = '0';
$orders_tax = tep_db_query("select value from " . TABLE_ORDERS_TOTAL . "
where class = 'ot_tax' and orders_id = " . $Orders_id);
//$row_orders_tax = tep_db_fetch_array($orders_tax);
while($row_orders_tax = mysql_fetch_array($orders_tax)) {
 // end //
$Order_Tax = filter_text($row_orders_tax["value"]);
}
// --------------------	QUERIES 4  ------------------------------------//
//Orders_Insurance
$orders_insurance = tep_db_query("select value from " . TABLE_ORDERS_TOTAL . "
where class = 'ot_insurance' and orders_id = " . $Orders_id);
//$row_orders_insurance = tep_db_fetch_array($orders_insurance);
while($row_orders_insurance = mysql_fetch_array($orders_insurance)) {
 // end //
$Order_Insurance = filter_text($row_orders_insurance["value"]);
}
$Tax_Exempt_Message = "";
// --------------------	QUERIES 5a  ------------------------------------//
//Orders_Shipping Versandkosten
$orders_shipping = tep_db_query("select title, value from " . TABLE_ORDERS_TOTAL . "
where class = 'ot_shipping' and orders_id = " . $Orders_id);
//$row_orders_shipping = tep_db_fetch_array($orders_shipping);
while($row_orders_shipping = mysql_fetch_array($orders_shipping)) {
 // end //
$Order_Shipping_Total = $row_orders_shipping["value"];
$Shipping_Method = filter_text($row_orders_shipping["title"]); // Shipping method from query 5
}
// --------------------	QUERIES 5b  ------------------------------------//
//Orders_Shipping_Nachnahme
unset($nn_gebuehr);
$orders_shipping_nn = tep_db_query("select value from " . TABLE_ORDERS_TOTAL . "
where class = 'ot_cod_fee' and orders_id = " . $Orders_id);
//$row_orders_shipping_nn = tep_db_fetch_array($orders_shipping_nn);
while($row_orders_shipping_nn = mysql_fetch_array($orders_shipping_nn)) {
 // end //
$nn_gebuehr = $row_orders_shipping_nn["value"];

}
// --------------------	QUERIES 5c  ------------------------------------//
//Orders_Shipping_Minderwert bei Auslandsaufträgen
unset($minderwert);
$orders_shipping_minderwert = tep_db_query("select value from " . TABLE_ORDERS_TOTAL . "
where class = 'ot_loworderfee' and orders_id = " . $Orders_id);
//$row_orders_shipping_minderwert = tep_db_fetch_array($orders_shipping_minderwert);
while($row_orders_shipping_minderwert = mysql_fetch_array($orders_shipping_minderwert)) {
 // end //
$minderwert = $row_orders_shipping_minderwert["value"];

}
// --------------------	QUERIES 5d  ------------------------------------//
//Orders_Coupon Rabatt bei Couponeinsatz
unset($coupon);
$orders_coupon = tep_db_query("select value from " . TABLE_ORDERS_TOTAL . "
where class = 'ot_discount_coupon' and orders_id = " . $Orders_id);
//$row_orders_coupon = tep_db_fetch_array($orders_coupon);
while($row_orders_coupon = mysql_fetch_array($orders_coupon)) {
 // end //
$coupon = $row_orders_coupon["value"];

}

// --------------------	QUERIES 6  ------------------------------------//
//Orders_Residential Del Fee (Giftwrap)
$orders_residential_fee = tep_db_query("select value from " . TABLE_ORDERS_TOTAL . "
where class = 'ot_giftwrap' and orders_id = " . $Orders_id);
//$row_orders_residential_fee = tep_db_fetch_array($orders_residential_fee);
while($row_orders_residential_fee = mysql_fetch_array($orders_residential_fee)) {
 // end //
$Small_Order_Fee = $row_orders_residential_fee["value"];
}
////////////////////////////////////
$Discount_Rate = "";
$Discount_Message  = "";
$CODAmount  = "";
// --------------------	QUERIES 7  ------------------------------------//
//Orders_Total Gesamtbetrag der Bestellung wird noch nicht gebraucht
$orders_total = tep_db_query("select value from " . TABLE_ORDERS_TOTAL . "
where class = 'ot_total' and orders_id = " . $Orders_id);
//$row_orders_total = tep_db_fetch_array($orders_total);
while($row_orders_total = mysql_fetch_array($orders_total)) {
 // end //
$Order_Grand_Total = $row_orders_total["value"];
}
// --------------------	QUERIES 8  ------------------------------------//
//Kundendaten wie Name, Faxnummer und Refferer
$customers = tep_db_query("select customers_gender, customers_firstname, customers_lastname, customers_fax from " . TABLE_CUSTOMERS . "
where customers_id = " . $customers_id);
//$row_customers = tep_db_fetch_array($customers);
while($row_customers = mysql_fetch_array($customers)) {
	// end //
$fax = $row_customers["customers_fax"];
$gender = $row_customers["customers_gender"];
$kvorname = $row_customers["customers_firstname"];
$knachname = $row_customers["customers_lastname"];
}

// --------------------	QUERIES 10  ------------------------------------//
//Products COunt
$orders_count = tep_db_query("select count(products_quantity) as o_count from " . TABLE_ORDERS_PRODUCTS . "
where orders_id = " . $Orders_id);
//$row_orders_total = tep_db_fetch_array($orders_total);
while($row_orders_count = mysql_fetch_array($orders_count)) {
 // end //
$Number_of_Items = $row_orders_count[0]; // used array to show the number of items ordered
}
//
$Shipping_Weight = "";
$Coupon_Code = "";
$Order_security_msg = "";
$Order_Surcharge_Amount = "";
$Order_Surcharge_Something = "";
$Affiliate_code = "";
$Sentiment_message = "";
$Checkout_form_type = "";
$future1  = " ";
$future2 = "";
$future3 = "";
$future4 = "";
$future5 = "";
$future6 = "";
$future7 = "";
$future8 = "";
$future9 = "";
// csv settings
//$CSV_SEPARATOR = ";";
//$CSV_NEWLINE = "\r\n";
//$csv_output .= $Orders_id . $delim ;
//$csv_output .= $Date . $delim ;
//$csv_output .= $Time . $delim ;
//$csv_output .= $customers_id . $delim ;
//$csv_output .= $gender . $delim ;
//$csv_output .= $kvorname . $delim ;
//$csv_output .= $knachname . $delim ;
//$csv_output .= $Company . $delim ;
//$csv_output .= $email . $delim ;
//$csv_output .= $Billing_Address_1 . $delim ;
//$csv_output .= $Billing_Address_2 . $delim ;
//$csv_output .= $Billing_City . $delim ;
//$csv_output .= $Billing_State . $delim ;
//$csv_output .= $Billing_Zip . $delim ;
//$csv_output .= $Billing_Country . $delim ;
//$csv_output .= $Billing_Phone . $delim ;
//$csv_output .= $fax . $delim ;
//$csv_output .= $ShipTo_First_Name . $delim ;
//$csv_output .= $ShipTo_Last_Name . $delim ;
//$csv_output .= $ShipTo_Name . $delim ;
//$csv_output .= $ShipTo_Company . $delim ;
//$csv_output .= $ShipTo_Address_1 . $delim ;
//$csv_output .= $ShipTo_Address_2 . $delim ;
//$csv_output .= $ShipTo_City . $delim ;
//$csv_output .= $ShipTo_State . $delim ;
//$csv_output .= $ShipTo_Zip . $delim ;
//$csv_output .= $ShipTo_Country . $delim ;
//$csv_output .= $ShipTo_Phone . $delim ;
//$csv_output .= $Card_Type . $delim ;
//$csv_output .= $Card_Number . $delim ;
//$csv_output .= $Exp_Date . $delim ;
//$csv_output .= $Bank_Name . $delim ;
//$csv_output .= $Gateway . $delim ;
//$csv_output .= $AVS_Code . $delim ;
//$csv_output .= $Transaction_ID . $delim ;
//$csv_output .= $payment . $delim ;
//$csv_output .= $Order_Special_Notes . $delim ;
//$csv_output .= $Comments . $delim ;
//$csv_output .= $Order_Subtotal . $delim ;
//$csv_output .= $Order_Tax . $delim ;
//$csv_output .= $Order_Insurance . $delim ;
//$csv_output .= $Tax_Exempt_Message . $delim ;
//$csv_output .= $Order_Shipping_Total . $delim ;
//$csv_output .= $nn_gebuehr . $delim ;
//$csv_output .= $minderwert . $delim ;
//$csv_output .= $coupon . $delim ;
//$csv_output .= $Small_Order_Fee . $delim ;
//$csv_output .= $Discount_Rate . $delim ;
//$csv_output .= $Discount_Message . $delim ;
//$csv_output .= $CODAmount . $delim ;
//$csv_output .= $Order_Grand_Total . $delim ;
//$csv_output .= $Number_of_Items . $delim ;
//$csv_output .= $Shipping_Method . $delim ;
//$csv_output .= $Shipping_Weight . $delim ;
//$csv_output .= $Coupon_Code . $delim ;
//$csv_output .= $Order_security_msg . $delim ;
//$csv_output .= $Order_Surcharge_Amount . $delim ;
//$csv_output .= $Order_Surcharge_Something . $delim ;
//$csv_output .= $Affiliate_code . $delim ;
//$csv_output .= $Sentiment_message . $delim ;
//$csv_output .= $Checkout_form_type . $delim ;
//$csv_output .= $productname . $delim ;
//$csv_output .= $productattribut .$delim;
// --------------------	QUERIES 9  ------------------------------------//
//Get list of products ordered
	
$orders_products = tep_db_query("select products_model, products_price, products_quantity, products_name from " . TABLE_ORDERS_PRODUCTS . "
where orders_id = " . $Orders_id);
$productname = $row_customers["products_name"];
$order_num = $Orders_id;
// While loop to list the item
$csv_output .= $open_table;

$csv_output .= $open_header;
if($submitted == 2){ // Html output to screen
	$csv_output .= "<td width=20>Num".$delim;
	$csv_output .= "<td width=50>Date".$delim;
	$csv_output .= "<td width=100>Bill Name".$delim;
	$csv_output .= "<td width=100>Last".$delim;
	$csv_output .= "<td width=100>Address1".$delim;
	$csv_output .= "<td width=25>Address2".$delim;
	$csv_output .= "<td width=100>City".$delim;
	$csv_output .= "<td width=100>State".$delim;
	$csv_output .= "<td width=25>Zip".$delim;
	$csv_output .= "<td width=100>Phone".$delim;
	$csv_output .= "<td width=100>Ship Name".$delim;
	$csv_output .= "<td width=100>Address1".$delim;
	$csv_output .= "<td width=25>Address2".$delim;
	$csv_output .= "<td width=100>City".$delim;
	$csv_output .= "<td width=100>State".$delim;
	$csv_output .= "<td width=25>Zip".$delim;
}
$csv_output .= $close_header;
$csv_output .= $submitted == 1 ? $open_column.$order_num.$delim : $open_column."<a href=".$order_url.$order_num.$order_edit.">".$order_num."</a>".$delim;
$csv_output .= $open_column.$Date . $delim ;
$csv_output .= $open_column.$kvorname . $delim ;
$csv_output .= $open_column.$knachname . $delim ;
$csv_output .= $open_column.$Billing_Address_1 . $delim ;
$csv_output .= $open_column.$Billing_Address_2 . $delim ;
$csv_output .= $open_column.$Billing_City . $delim ;
$csv_output .= $open_column.$Billing_State . $delim ;
$csv_output .= $open_column.$Billing_Zip . $delim ;
$csv_output .= $open_column.$Billing_Phone . $delim ;

$csv_output .= $open_column.$ShipTo_First_Name . " " .$ShipTo_Last_Name. $delim ;
$csv_output .= $open_column.$ShipTo_Address_1 . $delim ;
$csv_output .= $open_column.$ShipTo_Address_2 . $delim ;
$csv_output .= $open_column.$ShipTo_City . $delim ;
$csv_output .= $open_column.$ShipTo_State . $delim ;
$csv_output .= $open_column.$ShipTo_Zip . $delim ;


$csv_output .= $open_header;
if($submitted == 2){ // Html output to screen
	$csv_output .= "<td width=100>Model".$delim;
	$csv_output .= "<td width=25>Qty".$delim;
	$csv_output .= "<td width=250>Product".$delim;
	$csv_output .= "<td width=200>Comments".$delim;
}
$csv_output .= $close_header;
while($row_orders_products = mysql_fetch_array($orders_products)) {

//$csv_output .= $open_column.$order_url.$order_num.$order_edit . $delim ;
$csv_output .= $open_column.filter_text($row_orders_products[0]) . $delim ;
$csv_output .= $open_column.$row_orders_products[2] . $delim ;
$csv_output .= $open_column.filter_text($row_orders_products[3]) . $delim ;
$csv_output .= $open_column.$Comments . $delim ;
$csv_output .= $submitted == 1 ? "" : "";

} // end while loop for products
$csv_output .= $close_table;
$csv_output .= $submitted == 1 ? "" : "<br>";

// --------------------------------------------------------------------------//




$csv_output .= "\n";
} // while loop main first


//BOF OUTPUT
if($submitted == 1){
	header("Content-Type: application/force-download\n");
	header("Cache-Control: cache, must-revalidate");
	header("Pragma: public");
	header("Content-Disposition: attachment; filename=orders_" . date("mdY") . ".csv");
	print $csv_output;
}
elseif($submitted == 2){
	$csv_output = str_replace("\n", "<br>", $csv_output);
	echo "<p dir=rtl>".$csv_output."</p>";
}
exit;
//EOF OUTPUT
}//function main

function filter_text($text) {
$filter_array = array(",","\r","\n","\t");
return str_replace($filter_array,"",$text);
} // function for the filter
?>
  

Thank you for taking the time to read my post and consider my request for help.

Edited by Jan Zonjee, 25 June 2009 - 10:05 PM.


#82   pippikalze

pippikalze
  • Members
  • 2 posts
  • Real Name:dino

Posted 04 August 2009 - 03:42 PM

// --------------------	QUERIES n. 9  MERCE + attributi ------------------------------------//

//prende lista dei prodotti ordinati


$orders_products = tep_db_query("select products_quantity, products_name from orders_products where orders_id = " . $Orders_id);
$orders_products_attributes = tep_db_query("select products_options, products_options_values from orders_products_attributes where orders_id = " . $Orders_id);

//  start loop oggetti

while($row_orders_products = mysql_fetch_array($orders_products)) {
$csv_output .= "n." . filter_text($row_orders_products[0]) . "  ---->  " . filter_text($row_orders_products[1]); 

while($row_orders_products_attributes = mysql_fetch_array($orders_products_attributes)) {
$csv_output .= " --- " . filter_text($row_orders_products_attributes[0]) . "--" . filter_text($row_orders_products_attributes[1]);


// $csv_output .= $orders_products_attributes;
$csv_output .= "\n" . ",,,,,,,,,,,,,,,,,";

}  } // end loop oggetti


#83   nudylady

nudylady
  • Members
  • 234 posts
  • Real Name:nudylady

Posted 10 August 2009 - 11:46 AM

View Posthavalok, on Mar 4 2009, 03:39 PM, said:

osCommerce export orders to csv file doesn't seem to work?

The contribution installed ok - but when I hit the 'Export to CSV' button nothing seemed to work, just a screen refresh

This was bugging me for a while - even on a vanilla v2.2 RC2a install...

Try this: create a text file called php.ini and in this file have one line of text:
register_globals=on

Upload this file to the root of your osCommerce installation - e.g. catalog/php.ini

That should do it

Place a php.ini into catalog does not change my register_globals setting. I can check this in admin-tool-Server Info.
I am on VPS plan with PHP 5.2.8. I have to go to WHM to set register_globals=on. Now it downloads. But this left a secutity problem?
what about for people used register global off addon. there is no solution.  EP .csv download doesn't need register_globals=on.

#84   jasonabc

jasonabc
  • Members
  • 1,964 posts
  • Real Name:Jason
  • Location:London, now Los Angeles

Posted 12 November 2009 - 10:40 PM

Hi - thanks for the contribution. For some reason it is populating the Order_Tax column with weird data? I have a California based store so the California data is correct. For out of state orders though (which are not charged CA Sales tax) the column should be empty but it's not - there's all kinds of numbers in there:

13.1625
6.1425
7.8

and so on...

Any ideas? Also - how to get a discount code column in there?

#85   jennyb

jennyb
  • Members
  • 35 posts
  • Real Name:Jenny Beaumont

Posted 14 April 2010 - 01:06 PM

hello - don't know if this thread is still active...had installed an older version of the contrib on a site a couple years back and worked great. just installed the more recent version with various fixes to another site, and a weird thing happens : when i hit the export order buttons, i get logged out of the admin. when i go to log back on, the prompt to download the file suddenly appears. so, ultimately the thing works, but i obviously can't deliver the site to the client in this state.

any ideas folks ?? don't think it's necessarily a prob with this contrib - the prob could be elsewhere, but i don't know where to start. appreciate any feedback.

thanks,
-jennyb

#86   swheeler

swheeler
  • Members
  • 6 posts
  • Real Name:Scott Wheeler

Posted 08 July 2010 - 06:53 PM

Hi,

I've installed this contribution into two directories: admin\includes\languages\english and the base directory of the cart (where all of the other PHP scripts are located). I'm getting the following error message in the browser window when I attempt to execute the script:


Fatal error: Cannot redeclare generatecsv() (previously declared in ..../htdocs/pricon/oph/exportorders.php:120) in .../htdocs/pricon/oph/includes/languages/english/exportorders.php on line 488

Not having much experience in PHP, I'm not certain why this error is presenting. generatecsv() is only declared once and only called once in the script. Has anyone else experience this problem? Any luck resolving? Could it be that I haven't installed to the correct directory?

Any guidance would be greatly appreciated.

Thanks,
Scott

#87   brentmags

brentmags
  • Members
  • 11 posts
  • Real Name:Brent
  • Gender:Male
  • Location:auckland, new zealand

Posted 03 September 2010 - 06:04 AM

View Postswheeler, on 08 July 2010 - 06:53 PM, said:

Hi,

I've installed this contribution into two directories: admin\includes\languages\english and the base directory of the cart (where all of the other PHP scripts are located). I'm getting the following error message in the browser window when I attempt to execute the script:


Fatal error: Cannot redeclare generatecsv() (previously declared in ..../htdocs/pricon/oph/exportorders.php:120) in .../htdocs/pricon/oph/includes/languages/english/exportorders.php on line 488

Not having much experience in PHP, I'm not certain why this error is presenting. generatecsv() is only declared once and only called once in the script. Has anyone else experience this problem? Any luck resolving? Could it be that I haven't installed to the correct directory?

Any guidance would be greatly appreciated.

Thanks,
Scott

Hi Scott,

i am NO php coder, but have just installed this contribution and despite the fact it took ages to do it, i started from the beginning working through each change as directed getting the result we are after.

actually totals 8 downloads in all to different folders, and i am wondering if you started off right in the first place. I am assuming you didn't jump to the start of the queue (like me) at just download/upload - make the necessary changes and 'hey presto'. Don't worry i did it and then started again...making sure i had backed up the files i was using or just leaving them open just in case i had to Ctrl + Z etc and then refresh to see what was happening.

on all accounts you should be minimally uploading (i take it you have a modified store)these files:
catalog/admin/exportorders.php
catalog/admin/includes/languages/english/exportorders.php

and made changes to these files:
catalog/admin/includes/boxes/customers.php
catalog/admin/includes/filenames.php
catalog/admin/includes/languages/french.php
catalog/admin/includes/languages/english.php

hope this helps

#88   kelleyfoods

kelleyfoods
  • Members
  • 3 posts
  • Real Name:Greg Padgett

Posted 19 October 2010 - 11:18 PM

Does anyone have an idea on how to have checkout_success.php or a file in that portion of the order process trigger this program to use current order number and dump in a folder on the server?  I need this info to process through our main software for inventory purposes.

#89   kelleyfoods

kelleyfoods
  • Members
  • 3 posts
  • Real Name:Greg Padgett

Posted 27 October 2010 - 03:53 PM

Is this forum dead?

#90 ONLINE   geoffreywalton

geoffreywalton

    Contact me for Support

  • Community Sponsor
  • 8,037 posts
  • Real Name:Geoffrey Walton
  • Gender:Male
  • Location:Norfolk, UK (close to the centre of the universe)

Posted 27 October 2010 - 04:07 PM

Greg

You can add some code in the same place as the extra order email is generated.

Just depends what you want output and the order of the fields.

HTH

G
Need help installing add ons/contributions, cleaning a hacked site or a bespoke development, check my profile

Virus Threat Scanner
My Contributions
Basic install answers.
Click here for Contributions / Add Ons.
UK your site.
Site Move.
Basic design info.

For links mentioned in old answers that are no longer here follow this link Useful Threads.

If this post was useful, click the Like This button over there ======>>>>>.

#91   skorsun

skorsun
  • Members
  • 1 posts
  • Real Name:Serge

Posted 24 November 2010 - 09:46 AM

I've added the export order function to osCommerce for integration with Golden Inventory System. I put the small php script in the  folder "catalog" for creation a xml stream  with last orders. Then, the inventory system connects to the php file and reads the xml stream. The program downloads the sales ordrers in the inventory database. It maybe MS SQL server Express Edition or MS Access database file. After that, I can create invoices, work orders and print different documents and reports in the desktop program.

#92   eberswine

eberswine
  • Members
  • 39 posts
  • Real Name:josh

Posted 13 May 2011 - 05:27 PM

Is there a way we can separate the first name and last name for the CSV file?

I noticed that it uses the $row_orders["customers_name"]

I wonder if we can change that to $row_customers["customers_firstname"] . $row_customers["customers_lastname"]  

We print this off for the USPS and they need all rows seperated.

Right now we just get :

First_Name   |    Last_Name    |    Name_On_Card

John Doe     |                 |    John Doe


Thanks for the help!!

#93   IWAS

IWAS
  • Members
  • 58 posts
  • Real Name:Dave
  • Gender:Male

Posted 25 October 2011 - 04:04 AM

View Posteberswine, on 13 May 2011 - 05:27 PM, said:

Is there a way we can separate the first name and last name for the CSV file?

I noticed that it uses the $row_orders["customers_name"]

I wonder if we can change that to $row_customers["customers_firstname"] . $row_customers["customers_lastname"]  

We print this off for the USPS and they need all rows seperated.

Right now we just get :

First_Name   | Last_Name | Name_On_Card

John Doe | | John Doe


Thanks for the help!!


There was a stray comma in the list code that was not separating them properly.  I took it out and am uploading the fixed copy.

#94   Swingy

Swingy
  • Members
  • 29 posts
  • Real Name:Jaccie

Posted 07 November 2011 - 02:52 PM

Hai, I want to use this addon with my store v 2.3. But the alteration I have to make in the admin/includes/boxes/customers.php isn't correct. Is there somebody who knows how it  has to be?

This is what I have to do:
replace with :
// BOF Export Orders to CSV
$contents[] = array('text' => '<a href="' . tep_href_link(FILENAME_CUSTOMERS, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_CUSTOMERS_CUSTOMERS . '</a><br>' .
'<a href="' . tep_href_link(FILENAME_ORDERS, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_CUSTOMERS_ORDERS . '</a><br>' .
'<a href="' . tep_href_link(FILENAME_EXPORTORDERS, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_CUSTOMERS_EXPORTORDERS . '</a>');
// EOF Export Orders to CSV

And this is how it look like in the file of v 2.3
<?php
/*
  $Id$
  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com
  Copyright (c) 2010 osCommerce
  Released under the GNU General Public License
*/
  $cl_box_groups[] = array(
	'heading' => BOX_HEADING_CUSTOMERS,
	'apps' => array(
	  array(
		'code' => FILENAME_CUSTOMERS,
		'title' => BOX_CUSTOMERS_CUSTOMERS,
		'link' => tep_href_link(FILENAME_CUSTOMERS)
	  ),
	  array(
		'code' => FILENAME_ORDERS,
		'title' => BOX_CUSTOMERS_ORDERS,
		'link' => tep_href_link(FILENAME_ORDERS)
	  )
	)
  );
?>


#95   Swingy

Swingy
  • Members
  • 29 posts
  • Real Name:Jaccie

Posted 07 November 2011 - 03:57 PM

Hm it looks like there is something wrong with the exportorders.php
I've tried to alter the customer.php to:
<?php
/*
  $Id$
  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com
  Copyright (c) 2010 osCommerce
  Released under the GNU General Public License
*/
  $cl_box_groups[] = array(
	'heading' => BOX_HEADING_CUSTOMERS,
	'apps' => array(
	  array(
		'code' => FILENAME_CUSTOMERS,
		'title' => BOX_CUSTOMERS_CUSTOMERS,
		'link' => tep_href_link(FILENAME_CUSTOMERS)
	  ),
	  array(
		'code' => FILENAME_ORDERS,
		'title' => BOX_CUSTOMERS_ORDERS,
		'link' => tep_href_link(FILENAME_ORDERS)
	  ),
	 array(
	 'code'=> FILENAME_CUSTOMERS_EXPORT,
	'title'=> BOX_CUSTOMERS_EXPORTORDERS,
	'link' => tep_href_link(FILENAME_EXPORTORDERS)
   )
)
 
  );
?>

But if I click the option export in the admin the server returns with: HTTP Error 500 (Internal Server Error): An unexpected condition found when the server would execute the request.

Who can help?

#96   Swingy

Swingy
  • Members
  • 29 posts
  • Real Name:Jaccie

Posted 18 November 2011 - 12:44 PM

Nobody who can help me?

#97   SeekersDK

SeekersDK
  • Members
  • 8 posts
  • Real Name:Emil Larsen

Posted 18 November 2011 - 10:50 PM

View PostSwingy, on 18 November 2011 - 12:44 PM, said:


Nobody who can help me?


You actually almost had it right, you just forgot a 2x spacebar [img]http://forums.oscommerce.com//public/style_emoticons/default/smile.png[/img]


<?php
/*
  $Id$
  osCommerce, Open Source E-Commerce Solutions
  [url="http://www.oscommerce.com"]http://www.oscommerce.com[/url]
  Copyright (c) 2010 osCommerce
  Released under the GNU General Public License
*/
  $cl_box_groups[] = array(
	'heading' => BOX_HEADING_CUSTOMERS,
	'apps' => array(
	  array(
		'code' => FILENAME_CUSTOMERS,
		'title' => BOX_CUSTOMERS_CUSTOMERS,
		'link' => tep_href_link(FILENAME_CUSTOMERS)
	  ),
	  array(
		'code' => FILENAME_ORDERS,
		'title' => BOX_CUSTOMERS_ORDERS,
		'link' => tep_href_link(FILENAME_ORDERS)
	  ),
	  array(
		 'code' => FILENAME_CUSTOMERS_EXPORT,
		 'title' => BOX_CUSTOMERS_EXPORTORDERS,
		 'link' => tep_href_link(FILENAME_EXPORTORDERS)  
	  )
	)
  );
?>


Tested and working with 2.3 :D Time to do a little "excel programming" :P

Edited by SeekersDK, 18 November 2011 - 10:52 PM.


#98   SeekersDK

SeekersDK
  • Members
  • 8 posts
  • Real Name:Emil Larsen

Posted 19 November 2011 - 02:13 AM

Spent a few hours now on making Excel make the invoices automatic (and finally got it working...). I changed some stuff in the exportorders.php. Among other things, i chagned so its seperated by ; now, instead of commas (gave some issues with adresses), and i enabled the part that also exports the product. For the pricing issue, i just divided the price with 10000 in my excel macro, think the issue with the price is due to the price being listed like: 12.00 in my danish Excel. Nothing i will spend any more time on now :) Simple fix ftw!

Good luck.

<?php
/*
  $Id: exportorders.php,v 1.1 April 21, 2006 Harris Ahmed $
  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com
  Copyright (c) 2004 Oscommerce
  Use this module on your own risk. I will be updating a new one soon. This template is used to create
  the csv export for Ideal Computer Systems Accounting Software
*/
  define('FILENAME_EXPORTORDERS', 'exportorders.php');

require('includes/application_top.php');
require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_EXPORTORDERS);
// Check if the form is submitted
if (!$_GET['submitted'])
{
?>
<!-- header_eof //-->
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->
<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
  <tr>
	<td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
		<!-- left_navigation //-->
		<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
		<!-- left_navigation_eof //-->
	  </table></td>
	<!-- body_text //-->
	<td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
		<tr>
		  <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
			  <tr>
				<td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
				<td class="pageHeading" align="right"></td>
			  </tr>
			</table></td>
		</tr>
		<!-- first ends // -->
		<tr>
		  <td><table border="0" style="font-family:tahoma;font-size:11px;" width="100%" cellspacing="2" cellpadding="2">
			  <tr>
				<td><form method="GET" action="<?php echo $PHP_SELF; ?>">
					<table border="0" style="font-family:tahoma;font-size:11px;" cellpadding="3">
					  <tr>
						<td><?php echo INPUT_START; ?></td>
						<td><!-- input name="start" size="5" value="<?php echo $start; ?>"> -->
						  <?php
						 $orders_list_query = tep_db_query("SELECT orders_id, date_purchased FROM orders ORDER BY orders_id");
		  $orders_list_array = array();
	   $orders_list_array[] = array('id' => '', 'text' => '---');
			 while ($orders_list = tep_db_fetch_array($orders_list_query)) {
				$orders_list_array[] = array('id' => $orders_list['orders_id'],
									   'text' => $orders_list['orders_id']." - ".tep_date_short($orders_list['date_purchased']));
	   } 
	   echo '  ' . tep_draw_pull_down_menu('start', $orders_list_array, (isset($_GET['orders_id']) ? $_GET['orders_id'] : ''), 'size="1"') . '   ';
	  ?></td>
					  </tr>
					  <tr>
						<td><?php echo INPUT_END; ?></td>
						<td><!-- <input name="end" size="5" value="<?php echo $end; ?>"> -->
						  <?php
	  echo '  ' . tep_draw_pull_down_menu('end', $orders_list_array, (isset($_GET['orders_id']) ? $_GET['orders_id'] : ''), 'size="1"') . '   ';
	  ?></td>
					  </tr>
					  <tr>
						<td> </td>
						<td><input type="submit" value="<?php echo INPUT_VALID; ?>"></td>
					  </tr>
					</table>
					<input type="hidden" name="submitted" value="1">
				  </form></td>
			  </tr>
			  <tr>
				<td><?php echo INPUT_DESC; ?></td>
			  </tr>
			  <tr>
				<td> </td>
			  </tr>
			  <tr>
				<td> </td>
			  </tr>
			</table></td>
		</tr>
	  </table></td>
  </tr>
</table>
<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
<?php
}
// submitted so generate csv if the form is submitted
else
{
generatecsv($_GET['start'], $_GET['end']);
}
// generates csv file from $start order to $end order, inclusive
function generatecsv($start, $end)
{
//Placing columns names in first row
$delim =  ';' ;
$csv_output .= "Orders_id".$delim;
$csv_output .= "Date".$delim;
$csv_output .= "Time".$delim;
$csv_output .= "First_Name".$delim;
$csv_output .= "Last_Name".$delim;
$csv_output .= "Name_On_Card".$delim;
$csv_output .= "Company".$delim;
$csv_output .= "email".$delim;
$csv_output .= "Billing_Address_1".$delim;
$csv_output .= "Billing_Address_2".$delim;
$csv_output .= "Billing_City".$delim;
$csv_output .= "Billing_State".$delim;
$csv_output .= "Billing_Zip".$delim;
$csv_output .= "Billing_Country".$delim;
$csv_output .= "Billing_Phone".$delim;
$csv_output .= "ShipTo_First_Name".$delim;
$csv_output .= "ShipTo_Last_Name".$delim;
$csv_output .= "ShipTo_Name".$delim;
$csv_output .= "ShipTo_Company".$delim;
$csv_output .= "ShipTo_Address_1".$delim;
$csv_output .= "ShipTo_Address_2".$delim;
$csv_output .= "ShipTo_City".$delim;
$csv_output .= "ShipTo_State".$delim;
$csv_output .= "ShipTo_Zip".$delim;
$csv_output .= "ShipTo_Country".$delim;
$csv_output .= "ShipTo_Phone".$delim;
//$csv_output .= "Card_Type".$delim;
//$csv_output .= "Card_Number".$delim;
//$csv_output .= "Exp_Date".$delim;
//$csv_output .= "Bank_Name".$delim;
//$csv_output .= "Gateway".$delim;
//$csv_output .= "AVS_Code".$delim;
$csv_output .= "Transaction_ID".$delim;
$csv_output .= "Order_Special_Notes".$delim;
$csv_output .= "Comments".$delim;
$csv_output .= "Order_Subtotal".$delim;
$csv_output .= "Order_Tax".$delim;
$csv_output .= "Order_Insurance".$delim;
$csv_output .= "Tax_Exempt_Message".$delim;
$csv_output .= "Order_Shipping_Total".$delim;
//$csv_output .= "Small_Order_Fee".$delim;
//$csv_output .= "Discount_Rate".$delim;
//$csv_output .= "Discount_Message".$delim;
//$csv_output .= "CODAmount".$delim;
$csv_output .= "Order_Grand_Total".$delim;
$csv_output .= "Number_of_Items".$delim;
$csv_output .= "Shipping_Method".$delim;
$csv_output .= "Shipping_Weight".$delim;
//$csv_output .= "Coupon_Code".$delim;
//$csv_output .= "Order_security_msg.".$delim;
//$csv_output .= "Order_Surcharge_Amount".$delim;
//$csv_output .= "Order_Surcharge_Something".$delim;
//$csv_output .= "Affiliate_code".$delim;
//$csv_output .= "Sentiment_message".$delim;
//$csv_output .= "Checkout_form_type".$delim;
//$csv_output .= "Card_CVV_value".$delim;
//$csv_output .= "future1".$delim;
//$csv_output .= "future2".$delim;
//$csv_output .= "future3".$delim;
//$csv_output .= "future4".$delim;
//$csv_output .= "future5".$delim;
//$csv_output .= "future6".$delim;
//$csv_output .= "future7".$delim;
//$csv_output .= "future8".$delim;
//$csv_output .= "future9".$delim;
//$csv_output .= "Remarks".$delim;
//$csv_output .= "ProductId".$delim;
$csv_output .= "Product_Price".$delim;
//$csv_output .= "Number".$delim;
$csv_output .= "Product".$delim;
//$csv_output .= "Attribute".$delim;
//$csv_output .= "Attribute_Value".$delim;
$csv_output .= "\n";

//End Placing columns in first row
// Patch dlan
// if both fields are empty we select all orders
if ($start=="" && $end=="") {
$orders = tep_db_query("SELECT orders_id, date_purchased, customers_name, customers_id, cc_owner, customers_company, customers_email_address, billing_street_address, billing_city, billing_state, billing_postcode, billing_country, customers_telephone, delivery_name, delivery_company, delivery_street_address, delivery_city, delivery_state, delivery_postcode, delivery_country, cc_type, cc_number, cc_expires
FROM orders ORDER BY orders_id");
// if $start is empty we select all orders up to $end
} else if($start=="" && $end!="") {
$orders = tep_db_query("SELECT orders_id, date_purchased, customers_name, customers_id, cc_owner, customers_company, customers_email_address, billing_street_address, billing_city, billing_state, billing_postcode, billing_country, customers_telephone, delivery_name, delivery_company, delivery_street_address, delivery_city, delivery_state, delivery_postcode, delivery_country, cc_type, cc_number, cc_expires
FROM orders WHERE orders_id <= $end ORDER BY orders_id");
// if $end is empty we select all orders from $start
} else if($start!="" && $end=="") {
$orders = tep_db_query("SELECT orders_id, date_purchased, customers_name, customers_id, cc_owner, customers_company, customers_email_address, billing_street_address, billing_city, billing_state, billing_postcode, billing_country, customers_telephone, delivery_name, delivery_company, delivery_street_address, delivery_city, delivery_state, delivery_postcode, delivery_country, cc_type, cc_number, cc_expires
FROM orders WHERE orders_id >= $start ORDER BY orders_id");
// if both fields are filed in we select orders betwenn $start and $end
} else {
$orders = tep_db_query("SELECT orders_id, date_purchased, customers_name, customers_id, cc_owner, customers_company, customers_email_address, billing_street_address, billing_city, billing_state, billing_postcode, billing_country, customers_telephone, delivery_name, delivery_company, delivery_street_address, delivery_city, delivery_state, delivery_postcode, delivery_country, cc_type, cc_number, cc_expires
FROM orders WHERE orders_id >= $start AND orders_id <= $end ORDER BY orders_id");
}
//patch
//$csv_output ="\n";
while ($row_orders = mysql_fetch_array($orders)) { //start one loop

$csv_output_ordersbefore = $csv_output;
$Orders_id = $row_orders["orders_id"];
$customers_id = $row_orders["customers_id"];
$Date1 = $row_orders["date_purchased"];
//list($Date, $Time) = explode (' ',$Date1);
$Date = date('m/d/Y', strtotime($Date1));
$Time= date('H:i:s', strtotime($Date1));
$Name_On_Card1 = $row_orders["customers_name"];
$Name_On_Card = filter_text($Name_On_Card1);// order changed
list($First_Name,$Last_Name) = explode(' ',$Name_On_Card1); // order changed
$Company = filter_text($row_orders["customers_company"]);
$email = filter_text($row_orders["customers_email_address"]);
$Billing_Address_1 = filter_text($row_orders["billing_street_address"]);
$Billing_Address_2 = "";
$Billing_City = filter_text($row_orders["billing_city"]);
$Billing_State = filter_text($row_orders["billing_state"]);
$Billing_Zip = filter_text($row_orders["billing_postcode"]);
$Billing_Country = str_replace("(48 Contiguous Sta", "", $row_orders["billing_country"]);
$Billing_Phone = filter_text($row_orders["customers_telephone"]);
$ShipTo_Name1 = $row_orders["delivery_name"];
$ShipTo_Name = filter_text($ShipTo_Name1); // order changed
list($ShipTo_First_Name,$ShipTo_Last_Name) = explode(' ',$ShipTo_Name1); // order changed
$ShipTo_Company = filter_text($row_orders["delivery_company"]);
$ShipTo_Address_1 = filter_text($row_orders["delivery_street_address"]);
$ShipTo_Address_2 = "";
$ShipTo_City = filter_text($row_orders["delivery_city"]);
$ShipTo_State = filter_text($row_orders["delivery_state"]);
$ShipTo_Zip = filter_text($row_orders["delivery_postcode"]);
$ShipTo_Country = str_replace("(48 Contiguous Sta", "", $row_orders["delivery_country"]);
$ShipTo_Phone = "";
$Card_Type = $row_orders["cc_type"];
$Card_Number = $row_orders["cc_number"];
$Exp_Date = $row_orders["cc_expires"];
$Bank_Name = "";
$Gateway  = "";
$AVS_Code = "";
$Transaction_ID = "";
$Order_Special_Notes = "";
 
// --------------------	QUERIES 1  ------------------------------------//
//Orders_status_history for comments
$orders_status_history = tep_db_query("select comments from orders_status_history
where orders_id = " . $Orders_id);
//$row_orders_status_history = tep_db_fetch_array($comments);
while($row_orders_status_history = mysql_fetch_array($orders_status_history)) {
// end //
$Comments = filter_text($row_orders_status_history["comments"]);
}
// --------------------	QUERIES 2  ------------------------------------//
//Orders_subtotal
$orders_subtotal = tep_db_query("select value from orders_total
where class = 'ot_subtotal' and orders_id = " . $Orders_id);
//$row_orders_subtotal = tep_db_fetch_array($orders_subtotal);
while($row_orders_subtotal = mysql_fetch_array($orders_subtotal)) {
// end //
$Order_Subtotal = filter_text($row_orders_subtotal["value"]);
}
// --------------------	QUERIES 3  ------------------------------------//
//Orders_tax
$orders_tax = tep_db_query("select value from orders_total
where class = 'ot_tax' and orders_id = " . $Orders_id);
//$row_orders_tax = tep_db_fetch_array($orders_tax);
while($row_orders_tax = mysql_fetch_array($orders_tax)) {
// end //
$Order_Tax = filter_text($row_orders_tax["value"]);
}
// --------------------	QUERIES 4  ------------------------------------//
//Orders_Insurance
$orders_insurance = tep_db_query("select value from orders_total
where class = 'ot_insurance' and orders_id = " . $Orders_id);
//$row_orders_insurance = tep_db_fetch_array($orders_insurance);
while($row_orders_insurance = mysql_fetch_array($orders_insurance)) {
// end //
$Order_Insurance = filter_text($row_orders_insurance["value"]);
}
$Tax_Exempt_Message = "";
// --------------------	QUERIES 5  ------------------------------------//
//Orders_Shipping
$orders_shipping = tep_db_query("select title, value from orders_total
where class = 'ot_shipping' and orders_id = " . $Orders_id);
//$row_orders_shipping = tep_db_fetch_array($orders_shipping);
while($row_orders_shipping = mysql_fetch_array($orders_shipping)) {
// end //
$Order_Shipping_Total = $row_orders_shipping["value"];
$Shipping_Method = filter_text($row_orders_shipping["title"]); // Shipping method from query 5
}
// --------------------	QUERIES 6  ------------------------------------//
//Orders_Residential Del Fee (Giftwrap)
$orders_residential_fee = tep_db_query("select value from orders_total
where class = 'ot_giftwrap' and orders_id = " . $Orders_id);
//$row_orders_residential_fee = tep_db_fetch_array($orders_residential_fee);
while($row_orders_residential_fee = mysql_fetch_array($orders_residential_fee)) {
// end //
$Small_Order_Fee = $row_orders_residential_fee["value"];
}
////////////////////////////////////
$Discount_Rate = "";
$Discount_Message  = "";
$CODAmount  = "";
// --------------------	QUERIES 7  ------------------------------------//
//Orders_Total
$orders_total = tep_db_query("select value from orders_total
where class = 'ot_total' and orders_id = " . $Orders_id);
//$row_orders_total = tep_db_fetch_array($orders_total);
while($row_orders_total = mysql_fetch_array($orders_total)) {
// end //
$Order_Grand_Total = $row_orders_total["value"];
}
// --------------------	QUERIES 8  ------------------------------------//
//Products COunt
$orders_count = tep_db_query("select count(products_quantity) as o_count from orders_products
where orders_id = " . $Orders_id);
//$row_orders_total = tep_db_fetch_array($orders_total);
while($row_orders_count = mysql_fetch_array($orders_count)) {
// end //
$Number_of_Items = $row_orders_count[0]; // used array to show the number of items ordered
}
//
$Shipping_Weight = "";
$Coupon_Code = "";
$Order_security_msg = "";
$Order_Surcharge_Amount = "";
$Order_Surcharge_Something = "";
$Affiliate_code = "";
$Sentiment_message = "";
$Checkout_form_type = "";
$Card_CVV_value = $row_orders["cvvnumber"];
$future1  = "";
$future2 = "";
$future3 = "";
$future4 = "";
$future5 = "";
$future6 = "";
$future7 = "";
$future8 = "";
$future9 = "";
// csv settings
$CSV_SEPARATOR = ";";
$CSV_NEWLINE = "\r\n";
$csv_output .= $Orders_id . ";" ;
$csv_output .= $Date . ";" ;
$csv_output .= $Time . ";" ;
$csv_output .= $First_Name . ";" ;
$csv_output .= $Last_Name . ";" ;
$csv_output .= $Name_On_Card . ";" ;
$csv_output .= $Company . ";" ;
$csv_output .= $email . ";" ;
$csv_output .= $Billing_Address_1 . ";" ;
$csv_output .= $Billing_Address_2 . ";" ;
$csv_output .= $Billing_City . ";" ;
$csv_output .= $Billing_State . ";" ;
$csv_output .= $Billing_Zip . ";" ;
$csv_output .= $Billing_Country . ";" ;
$csv_output .= $Billing_Phone . ";" ;
$csv_output .= $ShipTo_First_Name . ";" ;
$csv_output .= $ShipTo_Last_Name . ";" ;
$csv_output .= $ShipTo_Name . ";" ;
$csv_output .= $ShipTo_Company . ";" ;
$csv_output .= $ShipTo_Address_1 . ";" ;
$csv_output .= $ShipTo_Address_2 . ";" ;
$csv_output .= $ShipTo_City . ";" ;
$csv_output .= $ShipTo_State . ";" ;
$csv_output .= $ShipTo_Zip . ";" ;
$csv_output .= $ShipTo_Country . ";" ;
$csv_output .= $ShipTo_Phone . ";" ;
//$csv_output .= $Card_Type . ";" ;
//$csv_output .= $Card_Number . ";" ;
//$csv_output .= $Exp_Date . ";" ;
//$csv_output .= $Bank_Name . ";" ;
//$csv_output .= $Gateway . ";" ;
//$csv_output .= $AVS_Code . ";" ;
$csv_output .= $Transaction_ID . ";" ;
$csv_output .= $Order_Special_Notes . ";" ;
$csv_output .= $Comments . ";" ;
$csv_output .= $Order_Subtotal . ";" ;
$csv_output .= $Order_Tax . ";" ;
$csv_output .= $Order_Insurance . ";" ;
$csv_output .= $Tax_Exempt_Message . ";" ;
$csv_output .= $Order_Shipping_Total . ";" ;
//$csv_output .= $Small_Order_Fee . ";" ;
//$csv_output .= $Discount_Rate . ";" ;
//$csv_output .= $Discount_Message . ";" ;
//$csv_output .= $CODAmount . ";" ;
$csv_output .= $Order_Grand_Total . ";" ;
$csv_output .= $Number_of_Items . ";" ;
$csv_output .= $Shipping_Method . ";" ;
$csv_output .= $Shipping_Weight . ";" ;
//$csv_output .= $Coupon_Code . ";" ;
//$csv_output .= $Order_security_msg . ";" ;
//$csv_output .= $Order_Surcharge_Amount . ";" ;
//$csv_output .= $Order_Surcharge_Something . ";" ;
//$csv_output .= $Affiliate_code . ";" ;
//$csv_output .= $Sentiment_message . ";" ;
//$csv_output .= $Checkout_form_type . ";" ;
//$csv_output .= $Card_CVV_value . ";" ;
//$csv_output .= $future1 . ";" ;
//$csv_output .= $future2 . ";" ;
//$csv_output .= $future3 . ";" ;
//$csv_output .= $future4 . ";" ;
//$csv_output .= $future5 . ";" ;
//$csv_output .= $future6 . ";" ;
//$csv_output .= $future7 . ";" ;
//$csv_output .= $future8 . ";" ;
//$csv_output .= $future9 ;
// --------------------	QUERIES 9  ------------------------------------//
//Get list of products ordered
$orders_products = tep_db_query("select products_model, products_price, products_quantity, products_name, orders_products_id from orders_products
where orders_id = " . $Orders_id);
// While loop to list the item

$countproducts = 0;
$csv_output_item = "";
$csv_output_order = str_replace($csv_output_ordersbefore, "", $csv_output);
while($row_orders_products = mysql_fetch_array($orders_products)) {
// loop through orders
// More than one product per order, new line

if ($countproducts>0){
  $csv_output .= "\n";
 
  $csv_output .= $csv_output_order;
  
  $csv_output_item = "";
}

$csv_output_item .= "," . "BEGIN_ITEM". "," ;
$csv_output_item .= ",";
$csv_output_item .= filter_text($row_orders_products[0]) . ";" ;
$csv_output_item .= $row_orders_products[1] . ";" ;
$csv_output_item .= $row_orders_products[2] . ";" ;
$csv_output_item .= filter_text($row_orders_products[3]) . ";" ;
$Products_id = $row_orders_products[4];
$orders_products_attributes = tep_db_query("select products_options, products_options_values from orders_products_attributes
where orders_id = " . $Orders_id . " and orders_products_id  = " . $Products_id);

while($row_orders_products_attributes = mysql_fetch_array($orders_products_attributes)) {
  $csv_output_item .= filter_text($row_orders_products_attributes[0]) . "," ;
  $csv_output_item .= filter_text($row_orders_products_attributes[1]) . "," ;
}
$csv_output_item .= "END_ITEM";

$csv_output .= $csv_output_item;

$countproducts += 1;
}
// end while loop for products
// --------------------------------------------------------------------------//
$csv_output .= "\n";
} // while loop main first
//print
header("Content-Type: application/force-download\n");
header("Cache-Control: cache, must-revalidate");  
header("Pragma: public");
header("Content-Disposition: attachment; filename=ordersexports_" . date("Ymd") . ".csv");
print $csv_output;
  exit;
}//function main
function filter_text($text) {
$filter_array = array(",","\r","\n","\t");
return str_replace($filter_array,"",$text);
} // function for the filter
?>


#99   Swingy

Swingy
  • Members
  • 29 posts
  • Real Name:Jaccie

Posted 21 November 2011 - 11:50 PM

Great!
Thank You!!!!!
I will test it tomorrow!

#100   Swingy

Swingy
  • Members
  • 29 posts
  • Real Name:Jaccie

Posted 24 November 2011 - 01:40 AM

Hm works in a fresh shop now. I think that my shop is damaged from a servercrash recently. But thx for the help!