Custom Attribute Tab in Magento Easy Tabs

This is a post to pull together info from a whole bunch of different threads and sources (Magento boards, Stackoverflow and some other random blogs I found).

Template Master Easy Tabs are quite widely used in Magento installations (30K+ downloads, I see from Magento Connect). It’s a good free module that allows you to control and customise the tabbed collateral information section on a Magento product view page. You can active the standard Magento tabs – description, additional, tags, reviews etc. You can also add custom tabs listing a specific attribute, this is handy is you have a text area attribute such as ‘Features’ that allows the client to add in a list of free-form bullet points.

There is also the option to add a custom tab based on a static CMS block. I’ve done exactly that here, the client wanted a specific section that listed some very specific attributes in the Attribute list – and more importantly, they wanted these attributes to be different for different products. As each different product belonged to a specific attribute set I decided to write a custom template which loaded in the product model, found it’s attribute set and then outputted a table containing the specific attributes depending on which attribute set that was.

In the static block;

{{block type="core/template" template="catalog/product/product_technology.phtml"}}

And then in the product_technology.phtml file;

<?php
    $_helper = $this->helper('catalog/output');
    $_prodID = Mage::registry('current_product')->getId();
	$_product = Mage::getModel('catalog/product')->load($_prodID );

	$attributeSetModel = Mage::getModel('eav/entity_attribute_set');
	$attributeSetModel->load($_product->getAttributeSetId());
	$attributeSetName  = $attributeSetModel->getAttributeSetName();

?>

<div class="box-collateral box-additional">

 	
        <table class="data-table" id="product-attribute-specs-table-4">
            <col width="25%" />
            <col />
            <tbody>
			<?php if (0 == strcmp($attributeSetName, 'Clothing')): ?>
				<tr>
					<th class="label">Clothing Shape</th>
					<td class="data"><?php echo $_product->getClothing_shape() ?></td>
				</tr>
				<tr>
					<th class="label">Outer Fabric</th>
					<td class="data"><?php echo $_product->getOuter_fabric() ?></td>
				</tr>	
				<tr>
					<th class="label">Clothing Lining</th>
					<td class="data"><?php echo $_product->getClothing_lining() ?></td>
				</tr>	
			<?php elseif (0 == strcmp($attributeSetName, 'Sleeping Bags')): ?>		
				<tr>
					<th class="label">Outer Fabric</th>
					<td class="data"><?php echo $_product->getOuter_fabric() ?></td>
				</tr>
				<tr>
					<th class="label">Inner Fabric</th>
					<td class="data"><?php echo $_product->getInner_fabric() ?></td>
				</tr>	
				<tr>
					<th class="label">Filling</th>
					<td class="data"><?php echo $_product->getFilling() ?></td>
				</tr>	
			<?php endif; ?>		
            </tbody>
        </table>
		
	<script type="text/javascript">decorateTable('product-attribute-specs-table-4')</script>

</div>



Leave a Comment