coding


12
Nov 09

How to install Google Affiliate pixel tracking code in Magento

Took me a day of scouring the web to figure out how to get this to work. After adding this code do a test order and view source and confirm it worked.

#copy and paste to the bottom of
#app/design/frontend/default/theme_name/template/checkout/success.phtml
$companyID = "K123456"; #provided by Google
$category = urlencode("Your product category");
$lastorderid = Mage::getSingleton('checkout/session')->getLastOrderId();
$_order = Mage::getModel('sales/order')->load($lastorderid);
$orderID = $this->getOrderId(); #get the order ID
$aProduct = array();
$totalAmt = 0;
$prdsku = "";
$prdnm = "";
$prdqn = "";
$prdpr = "";
$prcatid = "";

###########store order data in array of objects###########
foreach ($_order->getAllItems() as $item) {
	$oProduct = new stdClass();
	$oProduct->sku = $item->getSku(); #sku
	$oProduct->price = $item->getPrice(); #price
	$totalAmt = $totalAmt + ($oProduct->price * $item->getQtyOrdered()); #total amt (excl.tax/shipping)
	$oProduct->qty = $item->getQtyOrdered(); #quantity
	$oProduct->name = $item->getName(); #product name
	$oProduct->category = $category;
	array_push($aProduct, $oProduct);
	$oProduct = NULL; #nuke it
}
###########build query string variables###########
for ($i=0; $i < count($aProduct); $i++) {
	if ($i == count($aProduct)-1) {
		$prdsku .= urlencode($aProduct[$i]->sku);
		$prdnm .= urlencode($aProduct[$i]->name);
		$prdqn .= urlencode($aProduct[$i]->qty);
		$prdpr .= urlencode($aProduct[$i]->price);
		$prcatid .= urlencode($aProduct[$i]->category);
	} else {
		$prdsku .= urlencode($aProduct[$i]->sku) . "^";
		$prdnm .= urlencode($aProduct[$i]->name) . "^";
		$prdqn .= urlencode($aProduct[$i]->qty) . "^";
		$prdpr .= urlencode($aProduct[$i]->price) . "^";
		$prcatid .= urlencode($aProduct[$i]->category) ."^";
	}
}
?>



5
Feb 09

My letter to Go Transit

For those not from the Toronto area, GO transit provides commuter train & bus services from the burbs to union station (downtown hub). Now, GO is waaaaaay behind technologically speaking, and is plagued by constant delays & technical difficulties. As a web developer, i was excited when i learned today that BART in San Francisco is now exposing it’s data to the community. It got me thinking, and a little bit angry though. Why aren’t our transit companies offering the same things? If they are i want to know when we can expect it.

So… i sent them an email with a few recommendations:

1. Create a http://code.google.com/transit/spec/transit_feed_specification.html for the trains, which would get the detailed station & scheduling information into Google Maps.

2. For each train station, come up with a way to track the # of mins until the next train arrives and publish/maintain this information as XML for the developer community on the GO website.

3. Publish/maintain the Go Transit train schedule as XML for the developer community.

4. Publish/maintain all service advisories in XML format for the developer community in realtime.

I doubt i will get a response, but i will update if i do.

February 17th, 2009: Update – i received a response from Metrolinx (who i also sent my inquiry too). Here is what they had to say:

Note that you have sent your comments to Metrolinx. We are a provincial agency created by the Government of Ontario in 2006 and are tasked with addressing the urgent need to improve and integrate transportation in the Greater Toronto and Hamilton Area (GTHA). Our mission is to develop a state-of-the-art transportation system that moves people and goods efficiently, economically and in an environmentally sustainable way. In doing so we are working closely with all of the transit authorities in the GTHA. However we are not involved in their day-to-day operations.

The GO Transit website is administered by GO Transit and as such I have passed your inquiry on to their Public Relations department publicrelations@gotransit.com. If you wish you can send further comments on their website to this e-mail address.

Metrolinx continues to maintain a close relationship with GO Transit as reflected in “The Big Move”, our regional transportation plan for the GTHA. You can review and/or download “The Big Move” at: http://www.metrolinx.com/thebigmove/index.html .

Best Regards,
Jacquie

Jacquie Menezes
Senior Associate, Public Affairs and Media
Metrolinx (Greater Toronto Transportation Authority)
Jacquie.Menezes@metrolinx.com
416.874.5923
www.metrolinx.com

And the response from GO Transit directly:

Thanks for writing about the GO Transit Web site. I have forwarded your suggestions to our Web committee for review. In the meantime, thanks again for sending valuable feedback — we appreciate your ideas and links to other sites.

Allison Derin
Webmaster
GO Transit
mailto:webmaster@gotransit.com

Again, i will update as i receive updates. Follow me on Twitter and i will send a Tweet as/if it happens.


16
Oct 08

How to setup a linux cronjob in 3 steps

Since web apps are executed only after an HTTP request, you may have situations where scripts need to run in the background on a scheduled basis. On Linux, to do this you’ll need to get to know the crontab. The way it works is kind of like an airport. The service is always running, however planes only depart at their scheduled times. The crontab is kinda like that, a daemon that runs constantly in the background and checks once a minute to see if any jobs need to be executed.

Let’s say you have a script located at http://www.acme.com/myscript.php that needs to run the first of every month at 9am. Here’s how you’d set it up:

1. Look for a file in your /etc folder called crontab.
2. You need to install a new crontab job, to do this type crontab -e.
3. Now the tricky part, the syntax:

and here’s how that translates in our example:

0 9 1 * * curl http://www.acme.com/myscript.php

Lets break it down. 0 is for the minute, 9 is the hour – so 9 hours & 0 minutes which is 9am. Day of the month, 1 – easy. We want to do this for every month & week, which is accomplished using the wildcard or * character. Next comes what we want to execute. It’s not enough to just type the URL of the script, you’ll need to use the CURL system function to make the HTTP request for you.

Here is some more information on CURL & Cron jobs for your reading pleasure, hope this tutorial helps!


5
May 08

Sendmail says: stat=Deferred: Connection reset

I have been struggling with this problem for the last 2 days and finally figured out the solution. Your mileage may vary depending on your network configuration but first some background on mine. I have a Lighttpd web server that i am running some PHP mail scripts on. We are trying to use our company’s MTA to relay messages so i had this line in the sendmail.cf file, with 10.0.0.116 being the IP address of our MTA.

define(`SMART_HOST', `10.0.0.116')dnl

Still, things didn’t seem to want to work. My network administrator wasn’t evening seeing the mail attempts on our mail server so the problem was definitely on the webserver.
Turns out (as these things often are) that it was a dumb syntax problem. The following change fixed everything:

define(`SMART_HOST', `[10.0.0.116]')dnl

Hope this helps if you are having a similar problem.


31
Mar 08

Phpmyadmin error: “Cannot start session without errors”

I have been trying to get phpmyadmin working on my Fedora 8 server i’ve been setting up, and struggled for the past day or so on this error:

Cannot start session without errors, please check errors given in your PHP and/or webserver log file and configure your PHP installation properly.

Turns out it’s very easy to fix. First thing you’ll want to do is have a look at your error logs. For me this was in /var/log/lighttpd/error.log (i’m using lighttpd instead of Apache). Have a look at your error log and you will probably see errors referencing permission errors writing to your session directory.

Simply chmod 777 that directory and you should be good to go.


4
Mar 08

How to setup a static route in OSX Leopard

I am in a situation at my office where i need a few static routes to reach external webservers. I had this working in 10.4 thanks to the tip over @ Macosxhints however after upgrading to Leopard my routes didn’t seem to get added to my routing table. I called Apple support this morning and they had no idea and actually said they don’t support this sort of thing either. Google searches came up dry however i figured out via a few terminal commands you can get it working manually. Here’s how. Pop open Terminal, and type:

su

You’ll then need to enter your root password. Strangely this didn’t work for me at first. If you have this problem too, open up Directory Utility (apps/utilities) and then click on ‘edit’ and ‘enable root user’.
Once you have root access, you can create your static routes, here is the command:

route add –net 192.168.5.0 10.0.1.5

192.168.5.0 is the network i’m trying to reach, via the gateway 10.0.1.5.

Update: Recently this stopped working for me, not sure if it was an OSX update or something with our internal network. In any case, this solved the problem for me:

sudo route add -net 192.168.5.0/24 10.0.1.5