Magento - 如何将自定义块添加到结账成功页面
我想通过向页面添加一个块来向结帐成功页面添加一些信息(无需复制模板页面并进行更改)。
我查看了可下载模块并尝试复制它,但没有成功。 我有一个自定义模块,我尝试这样做:
1)添加一个块文件: ...\app\code\local\SHANI\MyModule\Block\checkout\Details.php
class SHANI_MyModule_Block_Checkout_Details extends Mage_Checkout_Block_Onepage_Success
{
}
2) 添加模板文件到: ...\app\design\frontend\default\default\template\mymodule\checkout\details.phtml
<?php
echo "test ffdagdf";
?>
3) 将块添加到: ...\app\design\frontend\default\default\layout\mymodule.xml
<default>
</default>
....
....
....
<checkout_onepage_success>
<reference name="checkout.success">
<block type="mymodule/checkout_success" name="mymodule.checkout.details" template="mymodule/checkout/details.phtml"/>
</reference>
</checkout_onepage_success>
是否那是怎么做的呢?我缺少什么?
///////////////////////////////////////// 更新//////// /////////////////////////////////
我尝试像 Lrrr 写的那样更改 mymodule.xml 但仍然没有运气...
<checkout_onepage_success>
<reference name="checkout.success">
<block type="mymodule/checkout_details" name="mymodule.checkout.details" template="mymodule/checkout/details.phtml"/>
</reference>
</checkout_onepage_success>
还有其他想法是什么问题吗?
我正在尝试对产品视图页面执行相同的操作,并且我能够向“product.info.additional”添加一个块 但不是“product.info”。
这是有效的:
<catalog_product_view>
<reference name="product.info.additional">
<block type="catalog/product_view" name="mymodule.saledetails" before="-" template="mymodule/product/details.phtml"/>
<block type="mymodule/product_participant_list" name="mymodule.participants" before="-" template="mymodule/product/participant/list.phtml"/>
</reference>
</catalog_product_view>
但这不是
<catalog_product_view>
<reference name="product.info">
<block type="catalog/product_view" name="mymodule.saledetails" before="-" template="mymodule/product/details.phtml"/>
</reference>
<reference name="product.info.additional">
<block type="mymodule/product_participant_list" name="mymodule.participants" before="-" template="mymodule/product/participant/list.phtml"/>
</reference>
</catalog_product_view>
我试图将这个块从“product.info.additional”移动到“product.info”,因为我想在下面显示这个块 快速概述(在默认模板中)而不是详细信息下。 为什么它在“product.info”下不起作用?
I want to add some information to the checkout success page by adding a block to the page (without duplicating the template page and changing it).
I've looked at the downloadable module and tried to copy it but that didn't work.
I have a custom module and I've tried to do this :
1) adding a block file to :
...\app\code\local\SHANI\MyModule\Block\checkout\Details.php
class SHANI_MyModule_Block_Checkout_Details extends Mage_Checkout_Block_Onepage_Success
{
}
2) adding a template file to :
...\app\design\frontend\default\default\template\mymodule\checkout\details.phtml
<?php
echo "test ffdagdf";
?>
3) adding the block to : ...\app\design\frontend\default\default\layout\mymodule.xml
<default>
</default>
....
....
....
<checkout_onepage_success>
<reference name="checkout.success">
<block type="mymodule/checkout_success" name="mymodule.checkout.details" template="mymodule/checkout/details.phtml"/>
</reference>
</checkout_onepage_success>
Does that the way to do it? What am I missing?
///////////////////////////////////////// update/////////////////////////////////////////
I've tried to change the mymodule.xml like Lrrr wrote but still no luck...
<checkout_onepage_success>
<reference name="checkout.success">
<block type="mymodule/checkout_details" name="mymodule.checkout.details" template="mymodule/checkout/details.phtml"/>
</reference>
</checkout_onepage_success>
any other ideas what is the problem?
I'm trying to do the same thing with the product view page and I was able to add a block to the "product.info.additional"
but not to the "product.info".
This is working:
<catalog_product_view>
<reference name="product.info.additional">
<block type="catalog/product_view" name="mymodule.saledetails" before="-" template="mymodule/product/details.phtml"/>
<block type="mymodule/product_participant_list" name="mymodule.participants" before="-" template="mymodule/product/participant/list.phtml"/>
</reference>
</catalog_product_view>
But this isn't
<catalog_product_view>
<reference name="product.info">
<block type="catalog/product_view" name="mymodule.saledetails" before="-" template="mymodule/product/details.phtml"/>
</reference>
<reference name="product.info.additional">
<block type="mymodule/product_participant_list" name="mymodule.participants" before="-" template="mymodule/product/participant/list.phtml"/>
</reference>
</catalog_product_view>
I'm trying to move this block from "product.info.additional" to "product.info" because I want to show this block under
the Quick Overview (in the default template) and not under the Details.
Why doesn't it work under the "product.info"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试在成功页面布局中引用内容块
而不是 checkout.success ,您可能需要在模板中调用
$this->getChildHtml('yourblockname')
或添加output="toHtml "
到布局中的块try to reference the content block in success page layout
instead checkout.success and you probably will need to call
$this->getChildHtml('yourblockname')
in template or addoutput="toHtml"
to your block in layout尝试
在父模板中不使用 xml 中的 output="" 。
您还可以检查日志以获取其他信息。
为了确保现在是您的模块的错误,请将其替换为“
如果您的模块是,
则类型应该是”
Try
inside parent template without output="" in xml.
You can also check log for aditional info.
And to be sure it's now fault of Your block replace it with
If Your module is
then type should be
"core/template" name="child" template=" child" />
如果您将其放入parent.phtml
print $this->getChildHtml('child')
Magento 应该在parent.phtml中渲染child.phtml至于您的其他问题...有些块渲染所有属于它们的子块,但有些块仅渲染在其模板内回显的那些块,因此“product.info.additional”。可以使用
echo $this->getChildHtml()
和 'product.info' 可以使用echo $this->getChildHtml('block_name')
请向我提供您的模块配置文件
<block type="core/template" name="parent" template="parent.phtml>
<block type="core/template" name="child" template="child" />
</block>
If You put in parent.phtml this
print $this->getChildHtml('child')
Magento should render child.phtml inside parent.phtmlAs for Your other question... Some block render all blocks that are childs to them, but some renders only those blocks that are echo'ed inside their template. So 'product.info.additional' can use
echo $this->getChildHtml()
and 'product.info' can useecho $this->getChildHtml('block_name')
Please provide me Your module config.xml