2010-05-29 275 views
10

我對Magento很陌生,所以原諒我的愚蠢問題!據我所知,Magento的整個概念是基於覆蓋Magento中可用的基本組件。Magento佈局覆蓋!

所以根據我的理解,我決定更新Magento中onepage checkout的佈局。我已經創建了自己的佈局,並且在配置文件集中佈局更新了結帳模塊佈局。但問題是它實際上並沒有更新基礎佈局,而是用基礎佈局替換了它自己!應該是這樣的行爲還是我錯了?

+1

請將佈局標籤添加到您的佈局文件中,以便我們可以幫助您。 – 2010-05-29 18:23:35

回答

19

實際上,config.xml文件中的節點不會執行「更新」。 作爲事實上,我認爲你這樣做,在你的config.xml:

<config> 
    <frontend> 
     <layout> 
      <updates> 
        <checkout> 
         <file>mylayout.xml</file> 
        </checkout> 
      </updates> 
     </layout> 
    </frontend> 
</config> 

和你做在mylayout.xml您的修改。

事實上,你所要做的:

<config> 
    <frontend> 
     <layout> 
      <updates> 
        <mymodule> 
         <file>mylayout.xml</file> 
        </mymodule> 
      </updates> 
     </layout> 
    </frontend> 
</config> 

,然後在mylayout.xml:

<checkout_cart_index> <!-- this corresponds to the section where you want to add your block (or modify an existing block --> 
     <reference name="content"> 
      <reference name="checkout.cart"> 
       <block type="mymodule/myblock" name="checkout.mymodule.myblock"></block> 
      </reference> 
     </reference> 
</checkout_cart_index> 

通過看我的代碼和文件互相比較,你就會明白更好地運作。

事實上,不要忘記所有的xml文件在magento中連接在一起。 因此,所有配置文件中的所有節點都將按照相同的順序排列。

例如,在我們的情況下,Magento的的的config.xml文件將被連接起來,其結果是一個文件包含:

<config> 
<!-- some nodes... --> 
<!-- some nodes... --> 
<!-- some nodes... --> 
    <frontend> 
     <layout> 
      <updates> 
        <mymodule> 
         <file>mylayout.xml</file> 
        </mymodule> 
        <checkout> <!-- this is the node from the config.xml of the Checkout Module--> 
         <file>checkout.xml</file> 
        </checkout> 
        <!-- some layout updates nodes from other config files... --> 
      </updates> 
     </layout> 
    </frontend> 
<!-- some nodes... --> 
<!-- some nodes... --> 
</config> 

如果已經通過<checkout>取代<mymodule>產生的文件看起來會是:

<config> 
<!-- some nodes... --> 
<!-- some nodes... --> 
<!-- some nodes... --> 
    <frontend> 
     <layout> 
      <updates> 
        <checkout> 
         <file>mylayout.xml</file> 
        </checkout> 
        <!-- some layout updates nodes from other config files... --> 
      </updates> 
     </layout> 
    </frontend> 
<!-- some nodes... --> 
<!-- some nodes... --> 
</config> 

請注意mylayout.xml。 這就是爲什麼原來的佈局文件完全由自己的佈局:)

希望是十分明顯的,在法國這本來是我更容易解釋替換的原因;)

雨果。

+6

我想你用英文解釋得很好,連母牛都能理解你的解釋:D!感謝您的驚人完整回覆。 – Farid 2010-06-01 10:45:44

+2

值得注意的是,合併XML文件的順序可以使用標記由模塊的應用程序/ etc/modules/My_Module.xml文件控制。在你的情況下,你會希望你的模塊到,這樣它就與checkout模塊後的最終配置合併。 – ColinM 2010-11-02 17:53:53

1

我認爲這取決於你如何命名你的佈局。如果您將其命名爲checkout.xml,我認爲它將用基本佈局替換它自己。它選擇了另一個名字,我認爲它應該只覆蓋你指定的部分。編輯:不要忘記清除緩存。順便說一句,你怎麼知道xml文件實際上被替換?瞭解這一點的最佳方式可能是在重新生成緩存後檢查緩存。

+0

據我測試它,它不依賴於文件的名稱!因爲即使當我將名稱更改爲mytest.xml並在配置文件中設置路徑時,它仍然取代了整個佈局! – Farid 2010-05-29 17:31:28