2015-04-15 72 views
2

我想重寫的類是app \ code \ community \ Dhl \ Intraship \ Model \ Gateway.php。因此,我將該類放在我的本地模塊app \ code \ local \ MyCompany \ Intraship \ Model \ Gateway.php中,並相應地更改了類名。如何覆蓋Magento社區模型?

現在我需要添加到我的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> 

而且rewrite下的節點已經以適應所要的文件夾模式下的改寫文件的路徑:所以在你區分它只是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> 
+0

感謝@ b.enoit.be - 這正是我一直在尋找的解釋和幫助我嘗試了幾個小時後。 – Torben