1

Can someone please answer this for me.

If I create my own version of a Mage/core file in the local code pool, does it completely overwrite the Mage/core file? Or will the methods that have not been re-defined in my code still be inherited from the core file?

Example. The following file (Exception.php) contains several methods (functions).

~ app
->  code
  ->  core
    ->  Mage
      ->  Customer
        ->  Exception.php

I want to put my own version here:

~ app
->  code
  ->  local
    ->  Mage
      ->  Customer
        ->  Exception.php

My version only contains 1 method (_beforeSave()). The core file contains many. Will all the other methods still be available to Mage from the original file?

Hope that's clear! Thanks.

1

If you place a file in the folder local (or community) with the same path as some file from core the core file will be rendered useless.
The order Magento searches for a file is app/code/local, app/code/community, app/code/core, lib. If you want to override only one method do not copy the file in the local folder.
Here is a nice tutorial that shows you how to properly override something.

1
  • 2
    A little more background: The autoloader looks in the include_path, so every path will be checked for the file and then the file is loaded. PHP can not handle two classes with the same name and Magento doesn't touch class definitions in any manner. Jun 5 '13 at 12:02
0

There are basically three different "valid" ways of program logic modification in Magento

  1. Using Events
  2. Using Class or Controller Rewrites
  3. By copying the full file to the local code pool and then modifying it.

I would recommend to prefer 1. over 2. over 3. as with events you can properly isolate your change and this is less likely to cause problems when updating your Magento version. 2. (as Marius) mentioned is still better than copying to local, in respect to not risk that other extensions or updates break things.

When using the local pool, you always have to maintain the full class code (in case of updates).

In your case you should check if the code you apply can be added using an event which is - for the Mage_Customer object called customer_save_before.

2

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.