class
Inchoo_Dispatcher_Model_Observer
{
//this is hook to Magento's event dispatched before action is run
public
function
hookToControllerActionPreDispatch(
$observer
)
{
//we compare action name to see if that's action for which we want to add our own event
if
(
$observer
->getEvent()->getControllerAction()->getFullActionName() ==
'checkout_cart_add'
)
{
//We are dispatching our own event before action ADD is run and sending parameters we need
Mage::dispatchEvent(
"add_to_cart_before"
,
array
(
'request'
=>
$observer
->getControllerAction()->getRequest()));
}
}
public
function
hookToControllerActionPostDispatch(
$observer
)
{
//we compare action name to see if that's action for which we want to add our own event
if
(
$observer
->getEvent()->getControllerAction()->getFullActionName() ==
'checkout_cart_add'
)
{
//We are dispatching our own event before action ADD is run and sending parameters we need
Mage::dispatchEvent(
"add_to_cart_after"
,
array
(
'request'
=>
$observer
->getControllerAction()->getRequest()));
}
}
public
function
hookToAddToCartBefore(
$observer
)
{
//Hooking to our own event
$request
=
$observer
->getEvent()->getRequest()->getParams();
// do something with product
Mage::log(
"Product "
.
$request
[
'product'
].
" will be added to cart."
);
}
public
function
hookToAddToCartAfter(
$observer
)
{
//Hooking to our own event
$request
=
$observer
->getEvent()->getRequest()->getParams();
// do something with product
Mage::log(
"Product "
.
$request
[
'product'
].
" is added to cart."
);
}
}