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

霸气de小男生 提交于 2019-12-20 03:54:15

问题


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.


回答1:


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




回答2:


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

Hopes it'll help.



来源:https://stackoverflow.com/questions/14575391/magento-how-can-i-add-a-new-custom-block-in-product-details-page-using-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!