dongpixi2648 2013-01-29 03:55
浏览 138

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

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();
  } 


}

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);

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

  • 写回答

2条回答 默认 最新

  • doubiao9775 2013-01-29 16:46
    关注

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

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

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

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

    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.

    You also have an error with the naming of your block if it's called Compatible.php the class should be SmartGrowth_CompatibleWith_Block_Compatible

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器