views:

729

answers:

1

Think of an small and basic affliate system. I want an url like "www.myshop.com/mynewproduct.html?afid=123".

Every time "afid" is found in the url an method has to be called. (Basicly to save "afid" in an session an when the customer buys stuff i want to track it.)

Someone here who knows how to do that? Every hint is accepted ;-)

greetings, dexcs....

+2  A: 

You don't need a router for this. You'll want to setup an event listener that fires for every page load, and then access the variables in the request collection. The controller_front_init_routers event should do.

So, setup your module's config with the following

<global>
 <events>
  <controller_front_init_routers>
   <observers>
    <packagename_modulename_observer>
     <type>singleton</type>
     <class>Packagename_Modulename_Model_Observer</class>
     <method>interceptMethod</method>
    </packagename_modulename_observer>
   </observers>
  </controller_front_init_routers> 
 </events>
</global>

And then create the following class

app/code/local/Packagename/Modulename/Model/Observer.php
class Packagename_Modulename_Model_Observer {
 public function interceptMethod($observer) {
  $request  = $observer->getEvent()->getData('front')->getRequest();
  $afid  = $request->afid;

  //do whatever you want with your variable here
 }
}

The interceptMethod can be named whatever you want.

Alan Storm
Thanks! That THE way ;-)
Max

related questions