简体   繁体   中英

Magento - cart.phtml - Override issue

I have seen several examples of how to override the cart.phtml, but none of them seem to work in my files.

I have a theme at:

  • app/design/frontend/default/ves_fashion/

The file is located in:

  • app/design/frontend/default/ves_fashion/template/checkout/cart.phtml

I have created a cart.phtml in:

  • app/design/frontend/default/ves_fashion/template/customsite/checkout/cart.phtml

I have then checked the layout.xml of the theme in:

  • app/design/frontend/default/ves_fashion/layout/checkout.xml

And see this:

<layout>
    <checkout_cart_index translate="label">
        <label>Shopping Cart</label>
        <remove name="right"/>
        <remove name="left"/>
        <!-- Mage_Checkout -->
        <reference name="root">
            <action method="setTemplate"><template>page/1column.phtml</template></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>
...

I know wanted to override this cart.phtml with my own one and did the following: I opened the local.xml in

app/etc/local.xml

and inserted:

 <layout>
        <checkout_cart_index translate="label">
            <reference name="content">
                <block type="checkout/cart" name="checkout.cart">
                    <action method="setCartTemplate"><value>customsite/checkout/cart.phtml</value></action>
                    <action method="setEmptyTemplate"><value>customsite/checkout/cart/noItems.phtml</value></action>
                </block>
            </reference>
        </checkout_cart_index>
    </layout>

But this is not working. What do I need to do now? Is the local.xml in app/etc/ the correct one or do I have to use the one in app/design/frontend/default/ves_fashion/layout/local.xml ? I have also seen examples where the Tag has been left out, the value Tag is named and the content is set to checkout.cart - Why should I do this if the original xml file says something different?

Would be great if someone can help me out here. Thanks!

The app/etc/local.xml file is not what you're after. That contains the environment information for your site.

You can feel free to make changes directly in the theme's layout file:

app/design/frontend/default/ves_fashion/layout/checkout.xml

Or you can add a local.xml in that folder if you prefer, and make layout updates there.

As the others have pointed out, adding layout handles to the app/etc/local.xml file is wrong. That is simply for configuration. Your theme should define its own local.xml file in app/design/frontend/{your-package-name}/{your-theme-variation-name}/layout/local.xml , or your module should define its own layout handles in app/design/frontend/base/default/layout/{your-namespace}_{your-module}.xml .

Having written that, however, there is an inherent problem with the layout XML provided in your question. As is, those layout definitions will not work. Calling setCartTemplate and setEmptyTemplate are correct, but they will not work without the essential method call that MUST be called directly after them: chooseTemplate . If you view the app/design/frontend/base/default/layout/checkout.xml file, that method can be seen directly after the first two. This method call alone has been the source of many people's frustrations when modifying the Magento cart templates, made obvious by the number of StackOverflow questions regarding the issue. I've written a thorough explanation of this problem here: https://stackoverflow.com/a/33875491/2973534 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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