I am trying to use observers in Magento 1.7.0.2 to catch when a product is added to cart.
After that event has happened (I believe it is the event checkout_cart_add_product_complete) I would like to show a popup that gives an overview of the product that the customer has just bought, as it would be seen in an item line in the cart.
I have tried to build a module that would catch this event, but I can't find a way to test if I have the same event, what models I need to use or pretty much anything.
So far, I have this written
public function checkoutCartAddProductComplete (Varien_Event_Observer $observer)
{
$product = $observer->getEvent()->getProduct();
$session = Mage::getSingleton("checkout/session")->addSuccess($message);
$message = $this->__('Changed! You added %s to your shopping cart.', Mage::helper('core')->escapeHtml($product->getName()));
$session->addSuccess($message);
}
However I took that code from the Internet, and it doesn't seem to be working.
There is something in \app\code\core\Mage\Checkout\controllers\CartController.php (around line 205) that shows the eventDispatcher and then the code that displays a message - however I'm not sure how to actually transplant this to a module, short of copying the whole file and overwriting it.
I'm trying to do this as a module so I can take it across various projects, but it is turning out to be a project on it's own...