我正在做一个magento定制网站,我需要添加产品的其他属性,如类型,版本等。我是magento的新手,如何将新的自定义块添加到产品详细信息页面。我创建了一个模块,我正在使用下面的编码。
app''code''local''SmartGrowth''CompatibleWith''Block''compatible.php
类 SmartGrowth_CompatibleWith_Block_CompatibleWith 扩展Mage_Catalog_Block_Product_View
{
protected function _prepareLayout()
{
//$this->getProduct()->setName($this->getProduct()->getPrice());
$this->getProduct()->setName($this->getProduct()->getShortDescription());
parent::_prepareLayout();
}
}
我在 _prepareLayout() 中使用了以下编码,但它似乎重复了 5 次块,并且出现的块的位置是一个概率
$block = $this->getLayout()->createBlock(
'Mage_Core_Block_Template',
'my_block_name_here',
array('template' => 'catalog/product/compatiblewith.phtml')
);
$this->getLayout()->getBlock('content')->append($block);
请帮忙我该怎么做,我是magento的新手,任何帮助将不胜感激。
无需在代码中添加块,应使用配置 XML 文件完成。
为您的模块创建一个 XML 配置(关于此的大量教程)。
检查目录.xml(应用程序/设计/前端/基本/默认/布局/)
<catalog_product_view translate="label">
....
</catalog_product_view>
这是设置块以显示在产品视图页面上的位置。您可以使用自己的模块 XML 文件对其进行修改,如下所示:
<catalog_product_view translate="label">
<reference name="content">
<block type="compatiblewith/compatible" name="my.block" template="compatiblewith/compatible/template.phtml" />
</reference>
</catalog_product_view>
这将在内容区域内的产品视图页面上显示您的自定义块。
如果块称为"兼容",则块的命名也存在错误.php该类应SmartGrowth_CompatibleWith_Block_Compatible
您可以在快速查看区域下方的产品商店中添加自定义模板(产品图像旁边部分的css类名称),而无需修改核心文件。 在模块的布局文件中,为所需的结果添加以下代码(请将"模块"块"替换为实际的模块和块名称):
<catalog_product_view>
<reference name="content">
<reference name="product.info">
<block type="module/block" name="module_block" as="other" template="module/block.phtml"/>
</reference>
</reference>
</catalog_product_view>
使用的自定义块的目标是"其他",这是在magento的view.phtml(/app/design/frontend/base/default/template/catalog/product/view.phtml)中默认提供的子HTML。
希望它能有所帮助。