簡體   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