I'm developing a Magento extension and having trouble trying to get it to run javascript when an item is added to cart.
In config.xml I have an observer
<checkout_cart_product_add_after>
In Observer.php
public function itemAddedToCart(Varien_Event_Observer $observer){}
This is firing (I can test by echo-ing). But how do I get it to inject a block of javascript (preferably into the footer)?
Thanks in advance.
UPDATE: Used Chris' solution, but instead of registry I used the session to avoid potential multi-user issues:
In Observer.php
public function itemAddedToCart(Varien_Event_Observer $observer){}
$itemAddedToCart = 'true';
Mage::getSingleton('core/session')->setItemAddedToCart($itemAddedToCart);
In my custom block (script.phtml):
<?php if($itemAddedToCart) : ?>
<script type="text/javascript">
alert(<?php echo '"' . $this->__($itemAddedToCart) . '"' ?>);
</script>
<?php
// Clear itemAddedToCart session variable:
Mage::getSingleton('core/session')->unsItemAddedToCart();
?>
<?php endif; ?>
Hope this helps others.