移动Magento "添加到Cart"新建文件按钮不起作用


Moving Magento "Add to Cart" button to new file not working

我想将添加到购物车按钮从view.phtml文件到2columns-right.phtml文件,我不能使它工作。我所做的是我把<?php echo $this->getChildHtml('addtocart') ?>view.phtml文件复制到2columns-right.phtml,它根本不出现。我也做了Flush Magento缓存,但又没有。

有什么建议吗?

您应该熟悉magento布局系统。为了使<?php echo $this->getChildHtml('addtocart') ?>能够在2columns-right.phtml中工作,这个块应该被声明为根块的子块(根块是用2columns-right.phtml呈现的块)。实际上,我不认为移动添加到购物车到其他模板有多大意义,因为addtocart.phtml本身只是一个提交整个表单的按钮,位于catalog/product/view.phtml。如果你把它去掉,它就不能工作了

首先我同意never哀伤,如果你没有声明它,你就不能得到childtml。但是你可以用

<?php echo $this->getLayout()->createBlock('catalog/product_view')->setTemplate('catalog/product/view/addtocart.phtml')->toHtml(); ?>

2columns-right.phtml中使用此方法,您将获得addtocart.phtml

通过使用

来调用添加到购物车按钮
<?php echo $this->getChildHtml('addtocart') ?>

在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>
相关文章: