September 19, 2008

random code

Tags:
Filed under: ZenMagick — DerManoMann @ 10:05 am

In my (in)frequent series of random posts I present today a small piece of code to manipulate the label of the tax order total line during checkout.

Now, that wouldn’t be soo exicting, however it doesn’t require any template changes :)

Let’s start with the code:

class GSTPatcher {
public function onZMViewStart($args=null) {
global $order;

$key = 'GST';
if (isset($order->info['tax_groups'][$key])) {
$order->info['tax_groups']['Includes GST'] = $order->info['tax_groups'][$key];
unset($order->info['tax_groups'][$key]);
}
}
}
ZMEvents::instance()->attach(new GSTPatcher());

So, what is happening here? To begin with, a small class is defined with a single method onZMViewStart(). As the name suggests, the method is a callback function. In order to have it called an instance is registered (attached) to the ZenMagick event service ZMEvents.

The event view_start is raised? right before the actual page content is generated. The event service will then try all registered objects for a matching callback method. If found, it is called.

The method itself is rather simple. All it does is to modify the map of order totals of the current cart (in an $order object!).

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment