Guest Posted June 7, 2004 Share Posted June 7, 2004 Is it possible to output ELF2-format urchin logs with osCommerce? I know that this thread refers to ELF, but I will need ELF2 logs. any help appreciated. thanks! jason Quote Link to comment Share on other sites More sharing options...
Guest Posted June 22, 2004 Share Posted June 22, 2004 The following class file isn't ready for distribution as a contribution because I have yet to document it properly or test it with the current milestone, but it should have enough for you to get done what you need to with Urchin using the ELF2 log format. If you have questions about implementation, let me know. (Since our installation of osC was branched in early 2003 and highly customized, I may not be able to give detailed help to integrate with the more current releases.) To integrate it, save it as includes/classes/ecommerce_log.php, then do something similar to the following in checkout_process.php: Near the top of the file... require(DIR_WS_CLASSES . 'ecommerce_log.php'); $ecommerce_log = new ecommerce_log; after updating TABLE_ORDERS... $ecommerce_log->setTRansaction($sql_data_array, $totals_data_array); after updating TABLE_ORDERS_PRODUCTS... $ecommerce_Log->addItem($sql_data_array); and before setting up the email... $ecommerce_log->writeLog(); We have been using the following class on a highly-modified osCommerce installation for about 8 months. We run Urchin 5.5, but this should work fine on any 5.x version of Urchin. <? /* Urchin ELF2 writer Class (urchin.com) Release 0.1 - 2003/09/01 Eric Woods, ericw at sunnywood-designs dot com Usage: $ecommerce_log = new ecommerce_log(); // add the order header $ecommerce_log->setTransaction($order_array, $order_totals_array); // for each product... $ecommerce_log->addItem($product_array); // write the file $ecommerce_log->writeLog(); */ class ecommerce_log { var $logpath; var $logname; var $logfile; var $error; var $debug; var $transaction; var $itemArray; // This method creates the object. function ecommerce_log() { // Initialize the 'object' variables $this->logpath = DIR_FS_VIRTUAL_ROOT . "var/log/httpd/urchin"; $this->logname = "$this->logpath/ecommerce_log"; $this->transaction = ""; $this->itemArray = array(); $this->error = false; $this->debug = false; } // // == PUBLIC FUNCTIONS == // /* NOTES ON FORMAT ELF2 Log Format ELF2 Transaction Line The ELF2 transaction line begins with an '!' exclamation and contains the following tab separated fields (empty fields should contain a '-' character): !%{ORDERID} %{REMOTE_HOST} %{DATE/TIME} %{STORE} %{SESSIONID} %{TOTAL} %{TAX} %{SHIPPING} %{BILL_CITY} %{BILL_STATE} %{BILL_ZIP} %{BILL_COUNTRY} %{USER_AGENT} %{COOKIES} where: %{ORDERID} is the order number -- use <> %{REMOTE_HOST} is the hostname/ip address of the remote machine -- environment %{DATE/TIME} is the time in the common log format [dd/mmm/yyyy:HH:MM:SS +/-ZZZZ] -- function %{STORE} is the name/id of the storefront -- use <> %{SESSIONID} is the unique session identifier of the customer -- n/a %{TOTAL} is the transaction total including tax and shipping (decimal only, no '$' characters) -- use <> %{TAX} is the amount of tax charged to the subtotal %{SHIPPING} is the amount of shipping charges %{BILL_CITY} is the billing city of the customer %{BILL_STATE} is the billing state of the customer %{BILL_ZIP} is the billing zip code of the customer %{BILL_COUNTRY} is the billing country of the customer %{USER_AGENT} is the user agent of the customers browser -- environment %{COOKIES} are the incoming cookies contained in the headers from the customers browser -- environment ELF2 Item Line The ELF2 item line contains the following tab separated fields (empty fields should contain a '-' character): %{ORDERID} %{REMOTE_HOST} %{DATE/TIME} %{PRODUCT_CODE} %{PRODUCT_NAME} %{VARIATION} %{PRICE} %{QUANTITY} %{UPSOLD} %{USER_AGENT} %{COOKIES} where: %{ORDERID} is the order number %{REMOTE_HOST} is the hostname/ip address of the remote machine -- environment %{DATE/TIME} is the time in the common log format [dd/mmm/yyyy:HH:MM:SS +/-ZZZZ] -- function %{PRODUCT_CODE} is the identifier of the product %{PRODUCT_NAME} is the name of the product %{VARIATION} is an optional variation of the product for colors, sizes, etc %{PRICE} is the unit price of the product (decimal only, no '$' signs) %{QUANTITY} is the quantity ordered of this product %{UPSOLD} is a boolean (0|1) if the product was on sale %{USER_AGENT} is the user agent of the customers browser %{COOKIES} are the incoming cookies contained in the headers from the customers browser ELF2 Log File Example !36530 123.123.123.123 [21/Aug/2003:11:31:45 -0800] - - 895.00 - - Virginia Beach VA 23452 US Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;) __utma=171060324.2002410569.1061216915.1061216915.1061490246.2; __utmb=171060324; __utmc=171060324 36530 123.123.123.123 [21/Aug/2003:11:31:45 -0800] U5-BASE Urchin 5 Base License - 895.00 1 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;) __utma=171060324.2002410569.1061216915.1061216915.1061490246.2; __utmb=171060324; __utmc=171060324 */ // These functions handle formatting and writing the data function setTransaction($orderdata=array(), $ordertotals=array()) { $this->error = false; $this->createTransactionLine($orderdata, $ordertotals); if ($this->error) return $this->getError(); return true; } function addItem($productdata=array()) { $this->error = false; $this->createItemLine($productdata); if ($this->error) return $this->getError(); return true; } function writeLog() { $this->error = false; $this->openLog(); $this->flushLines(); $this->closeLog(); if ($this->error) return $this->getError(); return true; } function debug() { $this->debug = true; } function getError() { return $this->error; } // // == INTERNAL FUNCTIONS == // // This subroutine echos debug statements to the browser function echoDebug($heading, $value) { echo "$heading: $value<br>\n"; } // This subroutine makes sure an element without a value uses "-" in its place function parseValue($dirtyVal="") { $cleanVal = ($dirtyVal == "") ? "-" : "$dirtyVal"; return $cleanVal; } // This subroutine creates the transaction line function createTransactionLine($orderdata, $ordertotals) { $ordersid = $this->parseValue($orderdata["orders_id"]); $remote_host = $this->parseValue($_SERVER["REMOTE_ADDR"]); $datetime = $this->parseValue(date("d/M/Y:H:i:s O")); $store = $this->parseValue(STORE_ID); $sessionid = $this->parseValue(); $total = $this->parseValue($ordertotals["total"]); $tax = $this->parseValue($ordertotals["tax"]); $shipping = $this->parseValue($ordertotals["shipping"]); $bill_city = $this->parseValue($orderdata["billing_city"]); $bill_state = $this->parseValue($orderdata["billing_state"]); $bill_zip = $this->parseValue($orderdata["billing_postcode"]); $bill_country = $this->parseValue($orderdata["billing_country"]); $user_agent = $this->parseValue($_SERVER["HTTP_USER_AGENT"]); $cookies = $this->parseValue($_SERVER["HTTP_COOKIE"]); $this->transaction = "!$ordersid\t$remote_host\t[$datetime]\t$store\t$sessionid\t$total\t$tax\t$shipping\t" . "$bill_city\t$bill_state\t$bill_zip\t$bill_country\t$user_agent\t$cookies"; return true; } // This subroutines create an item request string function createItemLine($productdata) { $ordersid = $this->parseValue($productdata["orders_id"]); $remote_host = $this->parseValue($_SERVER["REMOTE_ADDR"]); $datetime = $this->parseValue(date("d/M/Y:H:i:s O")); $product_code = $this->parseValue($productdata["products_model"]); $product_name = $this->parseValue($productdata["products_name"]); $variation = $this->parseValue(); $price = $this->parseValue($productdata["final_price"]); $quantity = $this->parseValue($productdata["products_quantity"]); $upsold = $this->parseValue(); $user_agent = $this->parseValue($_SERVER["HTTP_USER_AGENT"]); $cookies = $this->parseValue($_SERVER["HTTP_COOKIE"]); $this->itemArray[] = "$ordersid\t$remote_host\t[$datetime]\t$product_code\t$product_name\t$variation\t" . "$price\t$quantity\t$upsold\t$user_agent\t$cookies"; return $itemLine; } function flushLines() { $this->writeLine($this->transaction); for ($i=0, $n=count($this->itemArray); $i < $n; $i++) { $this->writeLine($this->itemArray[$i]); } } // These functions handle creating, rotating, and locking / unlocking the logs function openLog() { // Check to see whether today's log file exists if (file_exists($this->logname)) { // If YES, Open Existing Log File $this->logfile = fopen($this->logname,"a"); } else { // If NO, Create a New Log File $this->logfile = fopen($this->logname,"w"); } // Create a "Write" File Lock flock($this->logfile, LOCK_SH); } function closeLog() { // Relinquish File Lock flock($this->logfile, LOCK_UN); // Close Log File fclose($this->logfile); } // This method is invoked to write a line to the log file function writeLine($logLine) { // Write the line if ($this->debug) echoDebug("[$this->logname]", $logLine); fwrite($this->logfile,"$logLine\n"); return true; } } ?> Quote Link to comment Share on other sites More sharing options...
linuxmaster1979 Posted February 11, 2005 Share Posted February 11, 2005 I've used the code here with no luck. Has anyone found a way to get Urchin integrated with OsCommerce? Quote Knowledge Base | Contributions | Tips & Tricks Forum There are things known and there are things unknown, and in between are the doors. -- Jim Morrison Link to comment Share on other sites More sharing options...
metaltoad Posted September 28, 2005 Share Posted September 28, 2005 (edited) I wrote a contribution that generates ELF2 logs for OsCommerce. It can be accessed here: http://www.oscommerce.com/community/contributions,2939 The code should be added to the checkout_success.php page. You must also make sure the log file you setup is readable/writable via the web user. I hope this helps! Edited September 28, 2005 by metaltoad Quote Link to comment Share on other sites More sharing options...
valerka1 Posted January 22, 2007 Share Posted January 22, 2007 Write please manual on setting of this сontribution. How to compel everything to work. Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.