2010-05-29 189 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