1

I need some help moving some edits I made to the core files to my own module. I was able to do this easy enough with my frontend edits but I am unsure how to fully move my core file edits.

I edited files in paypal and shipping including the layout under configuration. I had to add some fields to these forms and how they processed the new fields. I remember all my edits but before I make too many to move them back can someone please help me with the appropriate file structure/location.

I am assuming moving the core edits will be as easy as moving the frontend edits but if I am wrong please be kind. I am still learning the structures for magento. Thanks!

1

There are two "levels" of correctness for fixing your core hacks.

The first is to use the local code pool. Whenever Magento instantiates an object (except for controller objects, which are different), it looks for a class file in four different locations.

 app/code/local/
 app/code/community/
 app/code/core/
 lib/

Core files are in the core code pool. You'll want to move your files there. So if you edited

app/code/core/Mage/Core/Model/Url.php

You would want to copy the file to

app/code/local/Mage/Core/Model/Url.php

and then restore the original

app/code/core/Mage/Core/Model/Url.php

That's code pool overrides. The benefit of a code pool override over a core hack is it allows you to keep track of what changes you've made, and your changes won't be lost when you upgrade the system.

True Magento Modules and Class Rewrites

Code pool overrides aren't perfect. When you upgrade Magento, you still need to merge changes to the core files with your own, and this can be tricky if a file's changed extensively.

The best approach to use is a class rewrite. The high level steps involved here are

  • Create a Magento module
  • Identify the "class alias" for your block, model, and helper (such as catalog/product
  • Add configuration to config.xml that tells Magento "When you instantiate a catalog/product object, use my class instead".
  • In your class redefine only the methods you want, and (based on your needs), call the original method with the parent::methodName

The above is more involved, but it will decrease the likelihood of your customizations breaking updated versions of Magento, and by putting your changes in a module, you can distribute it easily to any Magento system. The how/why of creating a class rewrite is beyond the scope of a single Stack Exchange answer, but there's plenty of tutorials out there on how to do it, and the community here is more than willing to help a motivated developer figure it out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.