سؤال

Class Test1/Module1/Model/A {

    protectedfunction doSomething(){
        //behaviour
        //behaviour
        //behaviour
    }
}

Class Test2/Module2/Model/B extends Test1/Module1/Model/A {

    protected function doSomething(){
        //behaviour
        //behaviour
        //added behaviour
        //behaviour
    }
}

Now in Test2/Module2/Model/B/etc/config.xml -

<?xml version="1.0"?>
<config>
    <modules>
        <Test2_Module2>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Test1_Module1/>
            </depends>
        <Test2_Module2>
    </modules>
</config>

Now when Test1/Module1/Model/A is called I want Test2/Module2/Model/B to extend its behaviour. Is this the correct way?

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

المحلول

From what I understand, you want to rewrite a model so that Magento uses yours, instead of the original. If that's the case, there are some more steps involved.

Here's an example of a basic module that rewrites a model:

app/code/local/Namespace/Module/Model/Layer.php

<?php
class Namespace_Module_Model_Layer extends Mage_Catalog_Model_Layer
{
    public function getProductCollection($filtered = true)
    {
        //overwrite function from parent class
    }
}

app/code/local/Namespace/Module/etc/config.xml

<?xml version="1.0"?>

<config>
    <modules>
        <Namespace_Module>
            <version>1.0.0</version>
        </Namespace_Module>
    </modules>

    <global>
        <models>
            <catalog>
                <rewrite>
                    <layer>Namespace_Module_Model_Layer</layer>
                </rewrite>
            </catalog>
        </models>
    </global>
</config>

app/etc/modules/Namespace_Module.xml

<?xml version="1.0"?>

<config>
    <modules>
        <Namespace_Module>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Catalog />
            </depends>
        </Namespace_Module>
    </modules>
</config>

Note: you will have to change some of the values, class names etc to match your purposes.

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