0

How do I properly overwrite Magento core functionality? I want to create a module that does it.

I need to edit this file: app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php

I know there is a option to copy this file to app/code/local/Mage/Adminhtml/Model/Sales/Order/Create.php and add my functionality to it which will let Magento read this file from local folder instead of core folder.

It's a easy way of doing but by creating a custom module it's easier to manage all the changes I have done.


So here is what I have done so far:

I have created a /app/etc/modules/MyCompany_MyModule.xml config file with following content:

<?xml version="1.0"?>
 
<config>
    <modules>
        <Vendor_CustomPriceRevert>
            <active>true</active>
            <codePool>local</codePool>
        </Vendore_CustomPriceRevert>
    </modules>
</config>

This is my second file in app/code/local/MyCompany/MyModule/etc/config.xml and it's content:

<?xml version="1.0"?>
 
<config>
    <modules>
        <MyCompany_MyModule>
            <version>0.1.0</version>
        </MyCompany_MyModule>
    </modules>
</config>

I know these two files are essential for any module to work.

Now, what file do I need to create now if I want to overwrite this file? Could someone explain this to me?

1

1 Answer 1

1

Add below code inside <config> tag in config.xml file

<global>
    <models>
        <adminhtml>
            <rewrite>
     <sales_order_create>MyCompany_MyModule_Adminhtml_Model_Sales_Order_Create</sales_order_create>
            </rewrite>
        </adminhtml>
    </models>
</global>

then add below code in MyCompany/MyModule/Adminhtml/Model/Sales/Order/Create.php file

<?php
class MyCompany_MyModule_Adminhtml_Model_Sales_Order_Create extends Mage_Adminhtml_Model_Sales_Order_Create
{
     echo "Hello World!"; die();
}
4
  • Great thank you. In the config.xml file does it have to go between <config> tags or add new <global> tags? I just been reading one tutorial and it was there so just making sure. Commented Nov 1, 2017 at 14:06
  • yeah in the <global> tag inside <config>.forget to mention that.. I updated my answer Commented Nov 1, 2017 at 14:10
  • Great! Thanks for your interest. I actually found some tutorial how to do it now. I was searching wrong. In here, I am overwriting Magento Model and when I was searching for "How to overwrite Magento functionality there was also Helpers etc which got me confused. Anyway, I got the! Thank you one more! Commented Nov 1, 2017 at 14:13
  • You're welcome! Commented Nov 1, 2017 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.