How can I override a Magento controller?

懵懂的女人 提交于 2020-01-11 08:46:11

问题


I need to check the validity of a coupon code on the checkout/cart page with server-side code.

Magento already ships with a similar check in place. However, I need to add one to see if a user is connected or not: what would be the best way to extend/override that action in Magento?

I know I can copy the controller PHP file to the /app/code/local/ folder tree, but I'm wondering whether there's a better way to do it.


回答1:


Anything besides modifying the core is good in my opinion. With that said create a simple module with a controllers directory and etc with config.xml:

<config>
    <frontend>
        <routers>
            <checkout>
                <args>
                    <modules>
                         <My_Module before="Mage_Checkout">My_Module_Checkout</My_Module>
                    </modules>
                </args>
            </checkout>
        </routers>
    </frontend>
</config>

See here for more details on how to extend the frontend controller: http://prattski.com/2010/06/24/magento-overriding-core-files-blocks-models-resources-controllers/



来源:https://stackoverflow.com/questions/6374344/how-can-i-override-a-magento-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!