如何覆盖Magento社区模型?

Arn*_*nie 2 overriding magento

我要覆盖的类是在app\code\community\Dhl\Intraship\Model\Gateway.php中.所以我将该类放在app\code\local\MyCompany\Intraship\Model\Gateway.php中的本地模块中,并相应地更改了类名.

现在我需要添加到我的config.xml文件才能使其工作?

谢谢!

β.ε*_*.βε 6

下面的节点models应匹配相同的节点app\code\community\Dhl\Intraship\etc\config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <Dhl_Intraship>
            <version>13.07.04</version>
        </Dhl_Intraship>
    </modules>
    <!-- some more code here -->
    <global>
        <models>
            <intraship> <!-- this is the node you have to look at -->
                <class>Dhl_Intraship_Model</class>
                <resourceModel>intraship_mysql4</resourceModel>
            </intraship>
            <!-- some more code here -->
        </models>
    <!-- some more code here -->
    <global>
</config>
Run Code Online (Sandbox Code Playgroud)

并且下面的节点rewrite必须匹配要在文件夹Model下重写的文件的路径:所以在你的情况下它只是gateway.但如果你要重写 app\code\community\Dhl\Intraship\Model\Path\To\Some\Model.php节点本来就是path_to_some_model

所以看起来应该是这样的:

<?xml version="1.0"?>
<config>
    <modules>
        <mycompany_intraship>
            <version>0.1.0</version>
        </mycompany_intraship >
    </modules>
    <global>
       <models>
          <intraship>
              <rewrite>
                  <gateway>MyCompany_Intraship_Model_Gateway</gateway>
              </rewrite>
          </intraship>
       </models>
    </global>
</config>
Run Code Online (Sandbox Code Playgroud)