【问题标题】:Add a custom content block within an existing content block of Magento Core在 Magento Core 的现有内容块中添加自定义内容块
【发布时间】:2015-07-15 17:02:57
【问题描述】:

我正在尝试添加一个自定义订单属性,用户可以在付款方式列表之后和按钮继续之前在结帐页面上定义该属性。

我想做的事情尽可能干净,所以我创建了自己的模块。

我正在为一些我认为很简单的事情而苦苦挣扎,但我没有成功找到解决方案。

目前我只需要能够在下面的块中显示模板文件。

Mage_Checkout_Block_Onepage_Payment

我创建了我的模板文件,它只为测试显示一个愚蠢的文本 应用程序/设计/默认/默认/模板/mymodule/custom.phtml 我知道这个文件在我的模块的索引操作中使用时没有问题

我认为主要问题是我不能正确地执行 xml 布局声明。

也许你可以帮助我

    <?xml version="1.0"?>
    <layout version="0.1.0">
<!-- this part is working well -->
        <mymodule_index_index>
            <reference name="content">
                <block type="mymodule/mymodule" name="mymodule" template="mymodule/custom.phtml" />
            </reference>
        </mymodule_index_index>
<!-- this part is not working at all -->
        <checkout_onepage_index>
            <reference="checkout.onepage.payment" >
                <block type="core/template" name="mymodule"  template="mymodule/custom.phtml" />
            </reference>
        </checkout_onepage_index>
    </layout>

当然,我的模块已经很好地声明了,因为我的模块的索引方法正在工作。 是不是我的参考标签不好?

先谢谢了,这个布局组织让我头疼,

最好的,

安塞尔

【问题讨论】:

    标签: php magento


    【解决方案1】:

    正如 b.enoit.be 所指出的,您忘记了 name 属性。除此之外,您还需要回显您的块。这是你的更新:

        <checkout_onepage_index>
            <reference name="checkout.onepage.payment" >
                <block type="core/template" name="mymodule"  template="mymodule/custom.phtml" />
            </reference>
        </checkout_onepage_index>
    

    您的块被声明为 checkout.onepage.payment 的子块,它还有另一个子块 (checkout.payment.methods),并且该块在 checkout.onepage.payment 模板 (app/design/frontend /base/default/template/checkout/onepage/payment.phtml):

    <form action="" id="co-payment-form">
        <fieldset>
            <?php echo $this->getChildHtml('methods') ?>
        </fieldset>
    </form>
    

    您需要做的是在 checkout.onepage.payment 块模板中的某个位置回显您的块,例如:

    <?php echo $this->getChildHtml('mymodule') ?>
    

    【讨论】:

    • 感谢大卫,真的很有帮助。但是,在自定义模块中覆盖 checkout.onepage.payment 模板以使其在每个设计中都实现的最干净的方法是什么?
    • 基本包模板真的不应该被修改。与包的默认主题类似。复制 app/design/frontend/base/default/template/checkout/onepage/payment.phtml 并放入您的主题;即 app/design/frontend/rwd/[YOUR_THEME]/template/checkout/onepage/payment.phtml。
    • 谢谢大卫,事情是我将它作为模块而不是特定主题开发我希望在任何主题中默认实现,如果这部分设计没有被修改,如果有人安装模块。我正在考虑将基本文件 payment.html 复制/粘贴到文件夹 app/design/frontend/default/default/template/checkout/onepage/payment.html 中,它不知道什么是最好的尊重和当您在自定义模块中有一些自定义块前端时
    • 其实这是一个很常见的问题,当对父块有依赖时,如何添加子块。如果 parent 是 core/text_list,那么没有问题。我不建议自定义和重新分发 payment.phtml,因为它是一个核心模板,更新和不同的 Magento 版本可能会使您自定义的 payment.phtml 无效。有许多解决此问题的方法,例如观察子块的 core_block_abstract_to_html_after,然后将块 html 附加到该 html。另一种解决方法是覆盖付款块。
    • 好的,谢谢你的建议,大卫,我可能会使用观察者方法,我已经做了一些观察者,似乎覆盖付款块的风险更小。
    【解决方案2】:

    您确实在参考中有问题,您缺少在那里输入错误的属性名称:&lt;reference="checkout.onepage.payment" &gt;

    <reference name="checkout.onepage.payment" >
        <block type="core/template" name="mymodule"  template="mymodule/custom.phtml" />
    </reference>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-05
      • 1970-01-01
      • 2015-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多