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

发布于 2024-10-16 11:49:38 字数 338 浏览 0 评论 0原文

好吧,我不知道如何表达这个问题,所以希望我能清楚地解释这一点。我在使用事件来添加/修改几乎所有内容的功能方面做得非常好。我的任务是修改估计送货、帐单和送货地址表格中国家/地区列表下拉列表中列出的国家/地区。该功能是根据客户端的一些业务规则添加的。

我确信我可以轻松地重写该方法,但我正在尽最大努力找出使用所有事件来执行操作的方法,所以我问你们是否想使用事件来更改下拉列表显示的内容Mage_Directory_Helper_Data 内部的方法 getRegionJson() ,你会怎么做?

我希望在加载集合时发生一个事件,但我没有看到这样做的可能性,但也许我错过了一些东西。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

临走之时 2024-10-23 11:49:38

这并不完全是有关如何使用事件攻击帮助程序类的问题的答案,但它确实回答了我的问题。我错了,因为我需要修改 getRegionJson 的 JSON 输出。如果我错了,请纠正我,但这仅在您选择不同的国家/地区时使用,然后州/省下拉列表将会改变。由于我只需要从选择菜单中删除选项,因此 JSON 输出可以保持原样,因为如果我删除国家/地区选项,用户将永远没有机会选择它来需要该 javascript。

所以我确实找到了一种方法来通过设置一个事件观察器来改变这个下拉列表,如下所示

        <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>

所以你可以看到我是 core_block_abstract_to_html_before 事件的观察者,然后在我的代码中我看到了该块Mage_Core_Block_Html_Select 在该块上,您可以搜索如下名称

 if($observer->getBlock()->getName() == 'country_id' || $observer->getBlock()->getName() == 'billing[country_id]' || $observer->getBlock()->getName() == 'shipping[country_id]'){

         $options = $observer->getBlock()->getOptions();
         code here
        }

,其中选项是我可以执行任何操作的所有不同选择菜单选项。

虽然我这样做了,但如果我们确实想更改带有观察者的辅助类输出的 json 字符串,那么知道该怎么做就好了。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文