Search code examples
magentomoduleblock

I am writing my first Magento module and need to overide a default template file


I am trying to override the shipping block in the cart page. However, my code just duplicates the shipping file twice. The weird thing is it duplicates my shipping file twice and not one of each. How can I disable the original shipping.phtml file and make magento only use my layout?

Here is my code:

app/etc/modules/config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
    <Module_Name>

        <!-- Whether our module is active: true or false -->
        <active>true</active>

        <!-- Which code pool to use: core, community or local -->
        <codePool>local</codePool>

    </Module_Name>
  </modules>
</config>

etc/config.xml

<?xml version="1.0" encoding="UTF-8"?>

<!-- The root node for Magento module configuration -->
<config> 

<!-- 
    The module's node contains basic 
    information about each Magento module
-->
<modules>

    <!--
        This must exactly match the namespace and module's folder
        names, with directory separators replaced by underscores
    -->
    <Module_Name>

        <!-- The version of our module, starting at 0.0.1 -->
        <version>0.0.1</version>

    </Module_Name>

</modules>

<frontend>
    <layout>
        <updates>
            <brands>
                <file>shipping.xml</file>
            </brands>
        </updates>
    </layout>
</frontend>

</config>

My theme Layout XML File:

<?xml version="1.0"?>

<layout version="0.1.0">

<!--
Default layout, loads most of the pages
-->

<checkout_cart_index translate="label">
    <label>Shopping Cart</label>
    <remove name="right"/>
    <remove name="left"/>
    <!-- Mage_Checkout -->
<reference name="head">
    <action method="addCss"><stylesheet>css/shipping.css</stylesheet>  </action> 
</reference>
    <reference name="content">
        <block type="checkout/cart" name="checkout.cart">
            <action method="setCartTemplate"><value>checkout/cart.phtml</value></action>
            <action method="setEmptyTemplate"><value>checkout/cart/noItems.phtml</value></action>
            <action method="chooseTemplate"/>
            <action method="addItemRender"><type>simple</type><block>checkout/cart_item_renderer</block><template>checkout/cart/item/default.phtml</template></action>
            <action method="addItemRender"><type>grouped</type><block>checkout/cart_item_renderer_grouped</block><template>checkout/cart/item/default.phtml</template></action>
            <action method="addItemRender"><type>configurable</type><block>checkout/cart_item_renderer_configurable</block><template>checkout/cart/item/default.phtml</template></action>

            <block type="core/text_list" name="checkout.cart.top_methods" as="top_methods" translate="label">
                <label>Payment Methods Before Checkout Button</label>
                <block type="checkout/onepage_link" name="checkout.cart.methods.onepage" template="checkout/onepage/link.phtml"/>
            </block>

            <block type="page/html_wrapper" name="checkout.cart.form.before" as="form_before" translate="label">
                <label>Shopping Cart Form Before</label>
            </block>

            <block type="core/text_list" name="checkout.cart.methods" as="methods" translate="label">
                <label>Payment Methods After Checkout Button</label>
                <block type="checkout/onepage_link" name="checkout.cart.methods.onepage" template="checkout/onepage/link.phtml"/>
                <block type="checkout/multishipping_link" name="checkout.cart.methods.multishipping" template="checkout/multishipping/link.phtml"/>
            </block>

            <block type="checkout/cart_coupon" name="checkout.cart.coupon" as="coupon" template="checkout/cart/coupon.phtml"/>
            <block type="checkout/cart_shipping" name="checkout.cart.shipping" as="shipping" template="module/shipping.phtml"/>
            <block type="checkout/cart_crosssell" name="checkout.cart.crosssell" as="crosssell" template="checkout/cart/crosssell.phtml"/>

            <block type="checkout/cart_totals" name="checkout.cart.totals" as="totals" template="checkout/cart/totals.phtml"/>
        </block>
    </reference>
    <block type="core/text_list" name="additional.product.info" translate="label">
        <label>Additional Product Info</label>
    </block>
 </checkout_cart_index>

</layout> 

Solution

  • You don't need to copy all that layout code. Just change the template:

    <reference name="checkout.cart.shipping">
        <action method="setTemplate"><template>path/to/template.phtml</template></action>
    </reference>