Magento-如何使用模块在产品详细信息页面中添加新的自定义模块 [英] Magento- How can i add a new custom block in product details page using module

查看:70
本文介绍了Magento-如何使用模块在产品详细信息页面中添加新的自定义模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个magento定制站点,我需要添加产品的其他属性,例如类型,版本等.我是magento的新手,如何将新的自定义块添加到产品详细信息页面.我已经创建了一个模块,并且正在使用以下代码.

I am doing a magento customaization site, I need to add the products addtional attributes like it's type,version etc .I am new to magento , How can i add the new custom block to product details page. I have created a module , and i am using below coding.

app \ code \ local \ SmartGrowth \ CompatibleWith \ Block \ compatible.php

app\code\local\SmartGrowth\CompatibleWith\Block\compatible.php

SmartGrowth_CompatibleWith_Block_CompatibleWith类扩展了Mage_Catalog_Block_Product_View

class SmartGrowth_CompatibleWith_Block_CompatibleWith extends Mage_Catalog_Block_Product_View

{

protected function _prepareLayout()
    {

            //$this->getProduct()->setName($this->getProduct()->getPrice());
            $this->getProduct()->setName($this->getProduct()->getShortDescription());


      parent::_prepareLayout();
  } 


}

我在_prepareLayout()中使用了以下编码,但似乎重复了该块5次,并且该块出现的位置是一个概率问题

I have used the below coding in _prepareLayout() but it seem to be repeat the block 5 times and the location of the block appeared is a probs

$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的新手,我们将不胜感激.

Please help how can i do this , I am new to magento , Any help will be appreciated.

推荐答案

不需要在代码中添加块,应该使用配置XML文件来完成.

There's no need to add the block in code, it should be done using config XML files.

为您的模块创建XML配置(有关此主题的大量教程).

Create an XML config for your module (plenty of tutorials on this).

检查catalog.xml(应用/设计/前端/基本/默认/布局/)

check catalog.xml (app/design/frontend/base/default/layout/)

<catalog_product_view translate="label">
 ....
</catalog_product_view>

在此处设置块以在产品视图页面上显示.您可以使用自己的模块XML文件对此进行修改,如下所示:

This is where the blocks are setup for display on the product view page. You can modify this using your own modules XML file, something like this:

<catalog_product_view translate="label">
    <reference name="content">
        <block type="compatiblewith/compatible" name="my.block" template="compatiblewith/compatible/template.phtml" />
    </reference>
</catalog_product_view>

这将在内容区域内的产品视图页面上显示您的自定义块.

this will show your custom block on the product view page, inside the content area.

如果将其命名为Compatible.php,您的块命名也将出错,该类应为SmartGrowth_CompatibleWith_Block_Compatible

这篇关于Magento-如何使用模块在产品详细信息页面中添加新的自定义模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆