繁体   English   中英

Magento-如何使用自定义模块覆盖永久billing.phtml

[英]Magento - How to override persistent billing.phtml using custom module

坚持了很长时间:(我正在尝试覆盖核心模板文件

app / design / frontend / base / default / template / persistent / checkout / onepage / billing.phtml

使用已成功激活的自定义模块,新模块的配置文件位于

app / code / local / CustomCheckout / Checkout / etc / config.xml。

以下是内容

<config>
    <modules>
        <CustomCheckout_Checkout>
            <version>1.0.0</version>
        </CustomCheckout_Checkout>
    </modules>
    <frontend>
        <routers>
            <checkout>
                <args>
                    <modules>
                         <CustomCheckout_Checkout before="Mage_Checkout">CustomCheckout_Checkout</CustomCheckout_Checkout>
                    </modules>
                </args>
            </checkout>
        </routers>
        <layout>
            <updates>
                <checkout>
                    <file>persistent.xml</file>
                </checkout>
            </updates>
        </layout>       
    </frontend>
</config>

我正在尝试覆盖persistent.xml布局,后者依次调用所述billing.phtml文件。 我将新的布局文件放置在以下位置

app / design / frontend / default / CustomCheckout / layout / persistent.xml。

以下是内容

<layout version="0.1.0">
    <checkout_onepage_index>
        <reference name="checkout.onepage.billing">
            <action method="setTemplate">
                <template>checkout/onepage/billing.phtml</template>
            </action>
        </reference>
    </checkout_onepage_index>
</layout>

我将修改后的billing.phtml文件放在

app / design / frontend / default / CustomCheckout / template / checkout / onepage / billing.phtml

但它没有被捡起。 我挠头...任何帮助表示赞赏。

希望您现在已经找到了答案,但是为了后代...

这里的问题是“ Persistent”模块已经覆盖了该模板。 如果查看persistent.xml布局文件,则会看到以下内容:

    <reference name="checkout.onepage.billing">
        <action method="setTemplate"><template>persistent/checkout/onepage/billing.phtml</template></action>
        <block type="persistent/form_remember" name="persistent.remember.me" template="persistent/remember_me.phtml" />
        <block type="core/template" name="persistent.remember.me.tooltip" template="persistent/remember_me_tooltip.phtml" />
    </reference>

Magento的默认加载顺序为字母顺序。 因此,由于Persistent模块是“ Mage_Persistent”,而您的模块是“ CustomCheckout_Checkout”,因此Persistent模块最后被加载,并且它的替代项是持久性模块。

有几种解决方案。 一种是重命名您的模块,使其在字母表中的Mage_Persistent之后。

更好的解决方案是使用Magento的依赖功能。 在您的模块声明文件(app / etc / modules / CustomCheckout_Checkout.xml)中,您可能会有类似以下内容:

<?xml version="1.0"?>
<config>
    <modules>
        <CustomCheckout_Checkout>
            <active>true</active>
            <codePool>local</codePool>
        </CustomCheckout_Checkout>
    </modules>
</config>

如下所示进行修改:

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

这向Magento指示您的模块“依赖” Mage_Persistent,因此应在其后加载。

如果这对您不起作用,另一种方法是在布局xml中使用“删除”节点来摆脱原始的结算块:

<remove name="checkout.onepage.billing" />

然后使用checkout.xml中的其他名称重新添加它。 确保从各种布局文件中在其下方添加所有必要的块和动作,并使用相同的别名(as =“ billing”)。

最后,如果该模块不打算重复使用(更改仅适用于当前安装),则可以将phtml文件复制到自定义package / theme文件夹中的相同路径中。

我是magento开发人员。 我确实在localhost上实现了您的问题并找到了解决方案。 我只是创建kinex / links(命名空间/模块)。 在此模块布局文件中包含以下代码:

<checkout_onepage_index>
    <reference name="checkout.onepage.billing">
        <action method="setTemplate">
            <template>kinex/links/billing.phtml</template>
        </action>
    </reference>
</checkout_onepage_index>

这非常简单,您只需将xml编写为:

 <checkout_onepage_index>
    <reference name="checkout.onepage.billing">
        <action method="setTemplate">
            <template>your-module/checkout/onepage/billing.phtml</template>
        </action>
        <block type="persistent/form_remember" name="persistent.remember.me" template="persistent/remember_me.phtml" />
        <block type="core/template" name="persistent.remember.me.tooltip" template="persistent/remember_me_tooltip.phtml" />
    </reference>
</checkout_onepage_index>

如果结帐页面有错误,则表示缺少billing或shipping.phtml文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM