Event to use to add functionality after a helper method is fired

Ok, I didn’t know how to word the question, so hopefully I can explain this clearly. I have been doing really well with using events to add/modify functionality for just about everything. I have the task with modifying the the countries that are listed in the dropdown for the country list on the estimated shipping, billing and shipping address forms. This functionality is added from some of the business rules of a client.

I am sure I could easily rewrite the method but I am trying my hardest to figure ways to use all of the events to do stuff, so I am asking you guys if you wanted to use an event to change what the dropdown displays based on the method getRegionJson() inside of Mage_Directory_Helper_Data, how would you go about it?

I was hoping there was an event when the collection was being loaded but I didn’t see the possibility of doing it, but maybe I am missing something.

One thought on “Event to use to add functionality after a helper method is fired”

  1. This isn’t exactly an answer to the question about how to use events to attack helper classes but it does answer my problem. I was wrong in the fact that I needed to modify the JSON output for getRegionJson. Correct me if I am wrong but that is only used if you choose a different country and then the state/provice dropdown will change. Since I only needed to remove options from the select menu, that JSON output can stay what it is because if I remove the country option the user never has chance to select it to need that javascript.

    So I did find a way to change this drop down with an observer by setting up an event observer like the following


    So you can see I am observer the core_block_abstract_to_html_before event and then in my code I saw that the block Mage_Core_Block_Html_Select on that block you can search for a name like the following

     if($observer->getBlock()->getName() == 'country_id' || $observer->getBlock()->getName() == 'billing[country_id]' || $observer->getBlock()->getName() == 'shipping[country_id]'){
             $options = $observer->getBlock()->getOptions();
             code here

    Where options are all of the different select menu options that I can do whatever I want with.

    Although I did this, It would be nice to know what if we did want to change that json string that is outputed from the helper class with an observer though.

Leave a Reply

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