drdyf42880 2011-02-08 19:54
浏览 21
已采纳

触发辅助方法后用于添加功能的事件

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.

  • 写回答

1条回答 默认 最新

  • drpp5680 2011-02-08 21:37
    关注

    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

            <core_block_abstract_to_html_before>
                <observers>
                    <modify_country_dropdown>
                        <type>singleton</type>
                        <class>module/observer</class>
                        <method>modifyCountryDropDown</method>
                    </modify_country_dropdown>
                </observers>
            </core_block_abstract_to_html_before>
    

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP