Add Custom Product Tab In Magento and get Attribute Content

Posted: April 11, 2015 in Magento

Add Custom Product Tab In Magento and get Attribute Content

Magento First

Navigate to Catalog > Attributes > Manage Attributes and click on Add New Attribute. Enter an attribute code “warranty” and be sure to specify Text Area for the textarea option. Fill in the remaining details to your preference.

The Code

In your theme’s design path, open the catalog.xml file. We’re going to add a custom tab, in my case a Warranty text, to appear immediately after the Additional Information tab. Second, locate the code for the Additional Information tab, which looks like this:

app/design/frontend/[theme]/default/layout/catalog.xml

<block type="catalog/product_view_attributes" name="product.attributes" as="additional" template="catalog/product/view/attributes.phtml">
     <action method="addToParentGroup"><group>detailed_info</group></action>
     <action method="setTitle" translate="value"><value>Additional Information</value></action>
</block>

Add your Code
app/design/frontend/[theme]/default/layout/catalog.xml

<block type="catalog/product_view_attributes" name="product.warranty" as="warranty" template="catalog/product/view/warranty.phtml">
      <action method="addToParentGroup"><group>detailed_info</group></action>
      <action method="setTitle" translate="value"><value>Warranty</value></action>
</block>

Now we need to create the custom view at catalog/product/view/warranty.phtml to perform the logic. You might want to get more creative with your names!

app/design/frontend/[theme]/default/template/catalog/product/view/warranty.phtml

<?php
$_product = $this->getProduct();
$attribute = $_product->getResource()->getAttribute('warranty');
if ( is_object($attribute) ) {
  $identifier = $_product->getData("warranty");
  echo $identifier;
}
?>

Please see below Demo :

Capture

Advertisements
Comments
  1. You are a very capable individual!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s