Magento - How to override persistent billing.phtml

2019-06-06 13:43发布

Stuck on this for a long now :( I am trying to override a core template file

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

using custom module which I have successfully activated and the config file for my new module is located at

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

Below are the content

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

I am trying to override the persistent.xml layout which in turn calls the said billing.phtml file. I placed the new layout file at following location

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

Below are the content

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

I have placed my modified billing.phtml file under

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

but it is not being picked up. I am scratching my head...any help is appreciated.

3条回答
走好不送
2楼-- · 2019-06-06 14:22

I am magento developer. I did implement your problem at localhost & find solution. I just create kinex/links (namespace/module). In this module layout file contain the following code:

<checkout_onepage_index>
    <reference name="checkout.onepage.billing">
        <action method="setTemplate">
            <template>kinex/links/billing.phtml</template>
        </action>
    </reference>
</checkout_onepage_index>
查看更多
甜甜的少女心
3楼-- · 2019-06-06 14:24

This is very Simple, You can simply write the xml as:

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

If there is some error in checkout page, then it means billing or shipping.phtml file is missing.

查看更多
祖国的老花朵
4楼-- · 2019-06-06 14:31

Hopefully you've found an answer by now, but for posterity...

The issue here is that the "Persistent" module is already overriding that template. If you look in the persistent.xml layout file you see the following:

    <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's default loading order is alphabetical. So, since the Persistent module is "Mage_Persistent" and your module is "CustomCheckout_Checkout", the Persistent module is loaded last, and it's override is the one that sticks.

There are several solutions. One is to rename your module so that it's after Mage_Persistent in the alphabet.

A better solution is to use Magento's dependency functionality. In your module declaration file (app/etc/modules/CustomCheckout_Checkout.xml), you probably have something like this:

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

Modify this as shown here:

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

This indicates to Magento that your module "depends" on Mage_Persistent and should therefore be loaded after it.

If that does not work for you, another technique would be to use a "remove" node in your layout xml to get rid of the original billing block:

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

Then re-add it with a different name, as it is in checkout.xml. Make sure to add all necessary blocks and actions underneath it from various layout files and use the same alias (as="billing").

Finally, if this module is not intended for re-use (the change is just for your current install) you could simply copy the phtml file into the same path in your custom package/theme folder.

查看更多
登录 后发表回答