Class overrides

1. Model

Example: override Mage_Catalog_Model_Product

<global>
    ...
    <models>
        ...
        <catalog>
            <rewrite>
                <product>Relu_Tester_Model_Catalog_Product</product>
            </rewrite>
        </catalog>
    </models>
</global>

Create a Product.php file in app/code/local/Relu/Tester/Model/Catalog/ with the new class extending the original one

class Relu_Tester_Model_Catalog_Product extends Mage_Catalog_Model_Product {}

2. Helper

Example: override Mage_Catalog_Helper_Product

<global>
    ...
    <helpers>
        ...
        <catalog>
            <rewrite>
                <product_view>Relu_Tester_Block_Catalog_Product_View</product_view>
            </rewrite>
        </catalog>
    </helpers>
</global>

Create a Product.php file in app/code/local/Relu/Helper/Model/Catalog/ with the new class extending the original one

class Relu_Tester_Helper_Catalog_Product extends Mage_Catalog_Helper_Product {}

3. Block

Example: override Mage_Catalog_Block_Product_View

<global>
    ...
    <blocks>
        ...
        <catalog>
            <rewrite>
                <product>Relu_Tester_Model_Catalog_Product</product>
            </rewrite>
        </catalog>
    </blocks>
</global>

Create a View.php file in app/code/local/Relu/Tester/Block/Catalog/Product/ with the new class extending the original one

class Relu_Tester_Block_Catalog_Product_View extends Mage_Catalog_Block_Product_View {}

4. ResourceModel

Example: override Mage_Cms_Model_Resource_Page

<global>
    ...
    <models>
        ...
        <cms_resource> <!-- this is a config value that comes from global/models/cms/resourceModel xpath in app/core/Mage/Cms/etc/config.xml -->
            <rewrite>
                <page>Relu_Tester_Model_Cms_Resource_Page</page>
            </rewrite>
        </cms_resource>
    </models>
</global>

Create a Page.php file in app/code/local/Relu/Tester/Model/Cms/Resource with the new class extending the original one

class Relu_Tester_Model_Cms_Resource_Page extends Mage_Cms_Model_Resource_Page {}

Instantiate models, helpers and blocks using factory methods

Example config.xml code:

<config>
    ...
    <global>
        <models>
            <relu_tester>
                <class>Relu_Tester_Model</class>
                <resourceModel>relu_tester_resource</resourceModel>
            </relu_tester>
            <relu_tester_resource>
                <class>Relu_Tester_Model_Resource</class>
            </relu_tester_resource>
        </models>
        <helpers>
            <relu_tester>
                <class>Relu_Tester_Helper</class>
            </relu_tester>
        </helpers>
        <blocks>
            <relu_tester>
                <class>Relu_Tester_Block</class>
            </relu_tester>
        </blocks>
    </global>
</config>

get the model

Mage::getModel('relu_tester/path_to_file');

get the resource model

Mage::getResourceModel('relu_tester/path_to_file');

get the helper

default path_to_file is ‘data’, i.e. if no path_to_file is specified, the factory method will instantiate the class Relu_Tester_Helper_Data

Mage::helper('relu_tester[/path_to_file]');

get the block

Mage::app()->getLayout()->createBlock('relu_test/path_to_file');

How to access to configuration value

Example config.xml code:

<config>
   ...
    <default>
        <path>
            <to>
                <some>
                    <node>ab</node>
                </some>
            </to>
        </path>
    </default>
    <stores>
        <french>
            <path>
                <to>
                    <some>
                        <node>cd</node>
                    </some>
                </to>
            </path>
        </french>
    </stores>
</config>

To get part of config:

$store->getConfig($path);

To get part of config:

Mage::getStoreConfig($path [, $store]);

example:
  Mage::getStoreConfig('path/to/some/node');
will return ab

and
  Mage::getStoreConfig('path/to/some/node', 'french');
will return cd

To check store flag:

i.e.: check too see if the xml node is defined and is not false

Mage::getStoreConfigFlag($path [, $store]);

example:
  Mage::getStoreConfigFlag('path/to/some/node' [, 'french']);
will return true if the value is set
will return false if the value is false or 0

and
  echo Mage::getStoreConfigFlag('path/to/another/node');
will return false

To access by absolute path:

Mage::getConfig()->getNode($path [, $scope]);

example:
  Mage::getConfig()->getNode('default/path/to/some/node');
and
  Mage::getConfig()->getNode('stores/french/path/to/some/node')
will return a Mage_Core_Model_Config_Element Object containing the node value

Display template path hints in admin

initial:

INSERT INTO core_config_data (scope, scope_id, path, value) VALUES ('default', 0, 'dev/debug/template_hints', 1), ('default', 0, 'dev/debug/template_hints_blocks', 1);

disable:

UPDATE core_config_data SET value = 0 WHERE scope = 'default' AND scope_id = 0 AND path ='dev/debug/template_hints'

reenable

UPDATE core_config_data SET value = 1 WHERE scope = 'default' AND scope_id = 0 AND path ='dev/debug/template_hints'

sursa