Magento – can’t override checkout/total/default.phtml

blockscheckoutlayoutmodulephtml

If I copy the file default.phtml from design/frontend/base/default/template/checkout/total/ to my theme folder (design/frontend/my_package/my_theme/template/checkout/total/default.phtml) everything is fine, my changes are applied and I can see them on the front end. But what I want to do is different. I need this default.phtml file to be in a module that can be easily switched off when not needed; to achieve this I need to override the template file but here I got stuck because I couldn't find any reference to this template in checkout.xml

I also tried to modify the renderTotal() function in Mage/Checkout/Block/Cart/Totals.php (I copied the file in my module, didn't altered the core files) and I was able to apply some changes (I needed a colspan=2 instead of 1) but not all of them (the second cell is still being displayed when the colspan is set to 2 while I want only the cell with the colspan=2 to be shown). So the only way I can achieve what I need is to modify the default.phtml file.

So my question is: how can i override the dedault.phtml?

Best Answer

The template is set in app/code/core/Mage/Checkout/Block/Total/Default.php. That's why you have to modify directly this file or to copy it in app/code/local and then to modify it or to overwrite it in your own custom module:

config.xml

<global>
    <blocks>
        <namespace_modulename>
            <class>Namespace_Modulename_Block</class>
        </namespace_modulename>
        <checkout>
            <rewrite>
                <total_default>Namespace_Modulename_Block_Total_Default</total_default>
            </rewrite>
        </checkout>
    </blocks>
</global>

Namespace/Modulename/Block/Total/Default.php

class Namespace_Modulename_Block_Total_Default extends Mage_Checkout_Block_Total_Default
{
    protected $_template = 'checkout/total/your_default.phtml';
    protected $_store;

    protected function _construct()
    {
        $this->setTemplate($this->_template);
        $this->_store = Mage::app()->getStore();
    }
}

I didn't test it but it should be working. :)