简体   繁体   English

Magento-如何使用模块在产品详细信息页面中添加新的自定义模块

[英]Magento- How can i add a new custom block in product details page using module

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. 我正在做一个magento定制站点,我需要添加产品的其他属性,例如类型,版本等。我是magento的新手,如何将新的自定义块添加到产品详细信息页面。 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

class SmartGrowth_CompatibleWith_Block_CompatibleWith extends Mage_Catalog_Block_Product_View 类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();
  } 


}

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 我在_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);

Please help how can i do this , I am new to magento , Any help will be appreciated. 请帮助我该怎么做,我是magento的新手,将不胜感激。

There's no need to add the block in code, it should be done using config XML files. 无需在代码中添加该块,应该使用config XML文件来完成。

Create an XML config for your module (plenty of tutorials on this). 为您的模块创建XML配置(有关此主题的大量教程)。

check catalog.xml (app/design/frontend/base/default/layout/) 检查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: 您可以使用自己的模块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>

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 如果将其命名为Compatible.php,则块的命名也会出错,该类应为SmartGrowth_CompatibleWith_Block_Compatible

You can add custom template in product-shop (css class name for the section beside product image) below the Quick View area without modifying core files. 您可以在快速查看区域下方的product-shop(产品映像旁边部分的css类名)中添加自定义模板,而无需修改核心文件。 in your module's layout file add this code for the required result (do replace "module" "block" with your actual module and block names): 在模块的布局文件中,为所需结果添加以下代码(用实际的模块和块名称替换“模块”“块”):

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

the target for custom block used is "other" which is a child html provided by default in view.phtml(/app/design/frontend/base/default/template/catalog/product/view.phtml) of magento. 自定义块使用的目标是“其他”,这是magento的view.phtml(/app/design/frontend/base/default/template/catalog/product/view.phtml)中默认提供的子html。

Hopes it'll help. 希望能对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM