Do I Have to Copy the Full Class to the “local” code pool when Making Modifications

magento.stackexchange https://magento.stackexchange.com/questions/4460

  •  16-10-2019
  •  | 
  •  

سؤال

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.

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top