Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Add new methods to core models & block. Add new action to core controllers in config.xml
 
Qsolutions
Jr. Member
 
Avatar
Total Posts:  13
Joined:  2012-10-15
Poland
 

Hi,

I’ve spend some time lately thinking how can I modify and add some new functionality in config.xml files. Sometimes I dont like to use rewirtes just to add a one method to core model or core block.

I’ve come up with an idea to add new methods to core models/blocks in config.xml file, I’ve done some core modifications and I was able to do it. In config.xml I add new xpath: <methods> under models / blocks

config.xml

<models>
            <
catalog>
                <
product>
                    <
methods>
                        <
dosomethig>
                            <class>
Qsolutions_Core_Methods_New</class>
                            <
method>doSomething</method>
                        </
dosomethig>
                    </
methods>
                </
product>
            </
catalog>
        </
models>


<
blocks>
            <
catalog>
                <
product_view>
                    <
methods>
                        <
dosomethig>
                            <class>
Qsolutions_Core_Methods_New</class>
                            <
method>doSomething</method>
                        </
dosomethig>
                    </
methods>
                </
product_view>
            </
catalog>
        </
blocks>

I even went little further and modified base magento controllers classes and now I am able to add an action to an existing controller from config.xml file

<frontend>
        <
routers>
            <
catalog>
                <
product>
                    <
actions>
                        <
someAction>
                            <class>
Qsolutions_Core_Actions_New</class>
                            <
action>someAction</action>
                        </
someAction>
                    </
actions>
                </
product>
            </
catalog>
        </
routers>
</
frontend>

This way I dont have to overwrite CORE controller, I’m just adding a new action to it in config.xml file.
Same goes for models and blocks.

I’m also planing on extending magento helpers the same way.
If anyone is interested, I can send you modified magento code to your email address.

Jakub

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top