【问题标题】:Magento - unexpected template being usedMagento - 使用了意外的模板
【发布时间】:2013-08-08 18:55:57
【问题描述】:

为了迎合 Magento (1.7.0.2) 在结帐过程中省略折扣代码(疯狂!),我安装了一个小扩展来添加相同的内容。效果很好,但由于 Magento 对增强单个块的支持有限,扩展提供了一个全新的 checkout/onepage/progress.phtml 文件,该文件的实现与主题(包)提供的进度完全不同盒子。因此,为了解决这个问题,我必须将扩展单页 progress.phtml 与我的主题的 progress.phtml 文件合并并改用它。

但这不是问题!问题是为什么商店现在使用扩展程序 progress.phtml 文件而不是我的主题的 progress.phtml 文件?

我以为我已经掌握了 Magento 的超级复杂模板,但显然没有!为了解决这个问题,我需要它恢复到我的主题的progress.phtml。详细说明...

扩展安装到 frontend/base/default 并包含一个布局 XML,指定:

<layout>
    <checkout_onepage_index translate="label">
        <reference name="checkout.onepage">
            <block type="greenacorn_checkoutcoupon/onepage_coupon" name="greenacorn_checkoutcoupon.onepage.coupon" as="coupon" template="greenacorn/checkoutcoupon/onepage/coupon.phtml"/>
        </reference>
        <reference name="checkout.progress">
            <action method='setTemplate'>
                <template>greenacorn/checkoutcoupon/onepage/progress.phtml</template>
            </action>
        </reference>
    </checkout_onepage_index>
    <checkout_onepage_progress>
        <reference name='root'>
            <action method='setTemplate'>
                <template>greenacorn/checkoutcoupon/onepage/progress.phtml</template>
            </action>
        </reference>
    </checkout_onepage_progress>
</layout>

谁能解释为什么开发者显然设置了两次进度模板?

现在我的主题在 frontend/[theme]/default/layout/checkout.xml 中指定了以下内容

<checkout_onepage_progress>
    <!-- Mage_Checkout -->
    <remove name="right"/>
    <remove name="left"/>

    <block type="checkout/onepage_progress" name="root" output="toHtml" template="checkout/onepage/progress.phtml">
        <block type="checkout/onepage_payment_info" name="payment_info">
            <action method="setInfoTemplate"><method></method><template></template></action>
        </block>
    </block>
</checkout_onepage_progress>

我的理解是配置主题中定义的内容优先于前端/默认中定义的内容,而前端/默认中定义的内容优先于前端/基础中定义的内容。那么扩展中定义的模板如何优先于主题中定义的模板呢?

【问题讨论】:

    标签: magento xml-layout


    【解决方案1】:

    checkout/index 和 checkout/progress 是两个不同的页面:这就是开发人员设置它们的原因。

    应该有另一个 .xml 文件(可能是 /app/code/community/greenacorn/checkoutcoupon/etc/config.xml)在如下节点中定义布局覆盖:

    <layout>
        <updates>
            <extensionname>
                <file>developer_extensionname.xml</file>
            </extensionname>
        </updates>
    </layout>
    

    【讨论】:

    • 是的,你是对的,在扩展 etc 文件夹中,并指定了包含上面第一个 XML 块的 XML 文件。第二个 XML 块(主题)在主题的 checkout.xml 中定义为 的子项。所以这意味着 总是胜过 ?
    • 是的,layout>default 是基础,layout>updates 是它的更新。
    • 非常感谢您的澄清 - 又一点 Magento 理解了!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-02
    • 2021-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-16
    • 2020-08-29
    相关资源
    最近更新 更多