Search code examples
phpmagentomagento-1.7magento-1.9

Overwrite block core file without custom module in Magento


I just want to know if I can create Product block in local code pool (i.e. \app\code\local\Mage\Catalog\Block\Product.php) without making my custom module just place this single file?

If so, will this local code pool block call or the core one call? If it would be the local one, please let me know why.


Solution

  • If you copy a code/core file to the code/local repository, the core file will be overwritten by the local file.

    This is because of the include path order to load system files specified in app/Mage.php:

    $paths = array();
    $paths[] = BP . DS . 'app' . DS . 'code' . DS . 'local';
    $paths[] = BP . DS . 'app' . DS . 'code' . DS . 'community';
    $paths[] = BP . DS . 'app' . DS . 'code' . DS . 'core';
    $paths[] = BP . DS . 'lib';
    

    So in your case the system will search for the Product.php in following order:

    1. app/code/local/Mage/Catalog/Block/Product.php
    2. app/code/community/Mage/Catalog/Block/Product.php
    3. app/code/core/Mage/Catalog/Block/Product.php
    4. lib/Mage/Catalog/Block/Product.php

    If the system cannot find any of these files, it will throw an error.