Which events should I use in Magento?

I want to send a mail when a new product is added depending on some criteria.

Where should I put my code so when a product is saved I can:

  • Get it and its attribute to work with
  • Send an email to some customer

Thanks in advance.

2 thoughts on “Which events should I use in Magento?”

  1. Magento already includes this functionality in the Mage_ProductAlert functionality. You could extend that module to take consideration of your extra criteria. It hooks into the cron system rather than a synchronous call to an Observer which is a much better performance model.

  2. You might want to checkout catalog_product_new_action. Never used it, but it might work for you. Not sure if it works on duplicating a product. I have used another event, catalog_product_save_before catalog_product_before_save, which is fired anytime a product is saved. (use google to search for magento event cheat sheets). But with both you can get the product in your observer function with

    $product = $observer->getEvent()->getProduct();

    Then you can get the attribute from the product.


    where my_attribute is the attribute you are after.

    Sending the email should be simple enough with php’s mail() function. If you want to get all complicated you can use Magento’s way of sending transactional emails, but likely you won’t need that unless you need it to translatable, etc.

Leave a Reply

Your email address will not be published. Required fields are marked *