RE: ELF log format?
Ian <[email protected]>
| Newsgroups | gmane.comp.web.oscommerce.devel |
|---|---|
| Message-ID | <22b395c23e28b17757736db3d503e2a4@osCommerce-Forums> |
This message was sent from: Development
http://forums.oscommerce.com/viewtopic.php?p=177563#177563
----------------------------------------------------------------
I've just taken a look at the code I did some time ago. It's fairly strightforward. and all continaed in checkout_process.php
the first part of the code goes just after the creation of the order status table and just before the
[code]// initialized for the email confirmation
$products_ordered = '';
$subtotal = 0;
$total_tax = 0;
[/code]
This code creates the elf header string
[code]// create urchin elf header -------------------------------------------------------
$order_string .= "!";
$order_string .= $insert_id ."\t";
$remote .= gethostbyaddr($REMOTE_ADDR);
if (!$remote) $remote = "-";
$order_string .= $remote . "\t";
$order_string .= STORE_NAME . "\t";
$order_string .= $customers_id . "\t";
$total_query = tep_db_query("select value from orders_total where orders_id = '" . $insert_id . "' and title LIKE 'Total:'");
$total = tep_db_fetch_array($total_query);
$tax_query = tep_db_query("select value from orders_total where orders_id = '" . $insert_id . "' and class = 'ot_tax'");
$tax = tep_db_fetch_array($tax_query);
$shipping_query = tep_db_query("select value from orders_total where orders_id = '" . $insert_id . "' and class = 'ot_shipping'");
$shipping = tep_db_fetch_array($shipping_query);
$date = date('d/M/Y:H:i:s O');
$total_v = $total['value'];
$tax_v = $tax['value'];
$ship_v = $shipping['value'];
if (!$total_v) $total_v = '0.00';
if (!$tax_v) $tax_v = '0.00';
if (!$ship_v) $ship_v = '0.00';
$total_v = $total_v * $order->info['currency_value'];
$tax_v = $tax_v * $order->info['currency_value'];
$ship_v = $ship_v * $order->info['currency_value'];
$order_string .= "[" . $date . "]" . "\t";
$order_string .= $total_v . "\t";
$order_string .= $tax_v . "\t";
$order_string .= $ship_v . "\t";
$billing_city = $order->customer['city'];
$billing_state = $order->customer['state'];
$billing_country = $order->customer['country'];
$billing_postcode = $order->customer['postcode'];
if (!$billing_city) $billing_city = '-';
if (!$billing_state) $billing_state = '-';
if (!$billing_postcode) $billing_postcode = '-';
if (!$billing_country) $billing_country = '-';
$order_string .= $billing_city . "\t";
$order_string .= $billing_state . "\t";
$order_string .= $billing_postcode . "\t";
$order_string .= $billing_country;
$order_string .= "\n";
// ---------------------------------------------------------------------------[/code]
next the elf product lines need to be created. This code goes just before
[code]//------insert customer choosen option to order--------
$attributes_exist = '0';
$products_ordered_attributes = '';
if ($order->products[$i]['attributes']) {
[/code]
[code]//urchin elf product lines --------------------------------------------------------------------------
$order_string .= $insert_id . "\t";
$pm = $order->products[$i]['model'];
if (!$pm) $pm = '-';
$order_string .= $pm . "\t";
$order_string .= $order->products[$i]['name'] . "\t";
$order_string .= '-' . "\t";
$order_string .= $order->products[$i]['price'] * $order->info['currency_value'] . "\t";
$order_string .= $order->products[$i]['qty'] . "\t";
$order_string .= '0';
$order_string .= "\n";
[/code]
finally this has to be written to a log file. This is done just before the email is written, ie just before
[code]// lets start with the email confirmation
$email_order = STORE_NAME . "\n" .
[/code]
and looks like
[code]// urchin elf write log file
if ($total_v != 0) {
$fp = fopen('urchin-elf.log', 'a');
fputs($fp, $order_string);
fclose($fp);
}
[/code]
Note the complete lack of error checking in this code :)
Also you would need t edit your Urchin config file too enable ELF logging and point to the file this code creates.