[英]Moving Magento “Add to Cart” button to new file not working
I want to move Add to cart button from view.phtml
file to 2columns-right.phtml
file and I am cant make it work. 我想将
view.phtml
文件中的添加到购物车按钮移动到2columns-right.phtml
文件,我无法使其工作。 What I did is that I copied <?php echo $this->getChildHtml('addtocart') ?>
from view.phtml
file to 2columns-right.phtml
and it does not appear at all. 我做的是我将
view.phtml
文件中的<?php echo $this->getChildHtml('addtocart') ?>
view.phtml
到2columns-right.phtml
,它根本没有出现。 I did Flush Magento cache too but nothing again. 我也做了Flush Magento缓存,但没有再说。
Any suggestions on how to make this work? 有关如何使这项工作的任何建议?
You should get familiar with magento layout system. 你应该熟悉magento布局系统。 To make possible
<?php echo $this->getChildHtml('addtocart') ?>
work in 2columns-right.phtml
this block should be declared as child block of root block (the root is the block that is rendered with 2columns-right.phtml
). 为了使
<?php echo $this->getChildHtml('addtocart') ?>
在2columns-right.phtml
工作,这个块应该被声明为根块的子块(root是用2columns-right.phtml
渲染的块2columns-right.phtml
)。 Actually, I don't see much sense in moving add to cart to other template, because addtocart.phtml
itself is just a button that submits whole form that is located at catalog/product/view.phtml
. 实际上,我认为将添加到购物车添加到其他模板没有多大意义,因为
addtocart.phtml
本身只是一个提交位于catalog/product/view.phtml
整个表单的按钮。 If you take it out of there it won't work. 如果你把它带出那里它将无法工作。
First of all i agree with nevermourn you can not get childhtml if you havn't declared it. 首先,我同意永远不会,如果你没有宣布它,你就不能得到childhtml。 But you can use
但你可以使用
<?php echo $this->getLayout()->createBlock('catalog/product_view')->setTemplate('catalog/product/view/addtocart.phtml')->toHtml(); ?>
By using this in 2columns-right.phtml
you will get addtocart.phtml
for sure. 通过在
2columns-right.phtml
使用它,你肯定会得到addtocart.phtml
。
in order to call add to cart button by using 为了通过使用调用添加到购物车按钮
<?php echo $this->getChildHtml('addtocart') ?>
on the page you desire in layout/local.xml 在layout / local.xml中您需要的页面上
<yourModule_YourController_yourAction>
<reference name="content">
<block type="catalog/product_view" name="product.info.addtocart" as="addtocart" template="catalog/product/view/addtocart.phtml"/>
</reference>
</yourModule_YourController_yourAction>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.