简体   繁体   English

Magento-cart.phtml-覆盖问题

[英]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. 我已经看到了几个有关如何覆盖cart.phtml的示例,但是它们似乎都无法在我的文件中工作。

I have a theme at: 我有一个主题:

  • app/design/frontend/default/ves_fashion/ 应用/设计/前端/默认/ ves_fashion /

The file is located in: 该文件位于:

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

I have created a cart.phtml in: 我在以下位置创建了cart.phtml:

  • app/design/frontend/default/ves_fashion/template/customsite/checkout/cart.phtml 应用程序/设计/前端/默认/ ves_fashion /模板/customsite/checkout/cart.phtml

I have then checked the layout.xml of the theme in: 然后,我在以下位置检查了主题的layout.xml:

  • app/design/frontend/default/ves_fashion/layout/checkout.xml 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 我知道我想用我自己的一个覆盖这个cart.phtml并执行以下操作:我在其中打开了local.xml

app/etc/local.xml 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 ? app / etc /中的local.xml是正确的还是我必须在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 标签已被忽略,值Tag被命名 and the content is set to checkout.cart - Why should I do this if the original xml file says something different? 并将内容设置为checkout.cart-如果原始xml文件说一些不同的内容,为什么要这样做?

Would be great if someone can help me out here. 如果有人可以在这里帮助我,那就太好了。 Thanks! 谢谢!

The app/etc/local.xml file is not what you're after. app/etc/local.xml文件不是您想要的。 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. 或者,您可以根据local.xml在该文件夹中添加local.xml ,并在那里进行布局更新。

As the others have pointed out, adding layout handles to the app/etc/local.xml file is wrong. 正如其他人指出的那样,将布局句柄添加到app/etc/local.xml文件是错误的。 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 . 您的主题应在app/design/frontend/{your-package-name}/{your-theme-variation-name}/layout/local.xml定义其自己的local.xml文件,或者您的模块应定义其自己的布局句柄在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. 但是,在撰写本文时,问题中提供的布局XML存在一个固有的问题。 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 . 调用setCartTemplatesetEmptyTemplate是正确的,但如果没有必须在它们之后直接调用的基本方法调用,它们将无法工作: chooseTemplate If you view the app/design/frontend/base/default/layout/checkout.xml file, that method can be seen directly after the first two. 如果您查看app/design/frontend/base/default/layout/checkout.xml文件,则可以在前两个之后直接看到该方法。 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. 修改Magento购物车模板时,仅此方法调用已成为许多人感到沮丧的根源,有关该问题的StackOverflow问题数量显而易见。 I've written a thorough explanation of this problem here: https://stackoverflow.com/a/33875491/2973534 . 我在这里写了对此问题的详尽解释: https : //stackoverflow.com/a/33875491/2973534

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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