• Home
  • Magento
  • Contact
KEEP IN TOUCH

Hide Attributes from frontend which values are not given from backend in Magento

Facebook Twitter Google + Share Reddit Digg Stumble Delicious More

To work with Magento we need to create many attribute for show information about product. But all attribute are no need for all product. For this reason we need to skip some attribute value from backend for some product. If you skip any attribute value from backend, by default Magento shows that attribute in frontend with ‘No‘ value. This create a problem to define product specification properly.

Recently i solved this problem. If you want to hide those attributes from frontend which values are skip from backend, you can follow me-

To do this you have to go:

/app/design/frontend/your-instance-name/your-theme-name/template/catalog/product/view/attributes.phtml

If you not found attributes.phtml file there then you can find that in following location:

/app/design/frontend/base/default/template/catalog/product/view/attributes.phtml

Now open the attributes.phtml and replace all code with following code:

  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Academic Free License (AFL 3.0)
  8. * that is bundled with this package in the file LICENSE_AFL.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/afl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magentocommerce.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category    design
  22. * @package     base_default
  23. * @copyright   Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
  24. * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
  25. */
  26.  
  27. /**
  28. * Product additional attributes template
  29. *
  30. * @see Mage_Catalog_Block_Product_View_Attributes
  31. */
  32. ?>
  33. <?php
  34.    $_helper = $this->helper('catalog/output');
  35.     $_product = $this->getProduct()
  36. ?>
  37. <?php if($_additional = $this->getAdditionalData()): ?>
  38.     <h2><?php echo $this->__('Additional Information') ?></h2>
  39.     <table class="data-table" id="product-attribute-specs-table">
  40.         <col width="25%" />
  41.         <col />
  42.         <tbody>
  43.         <!--<?php foreach ($_additional as $_data): ?>
  44.            <tr>
  45.                <th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
  46.                <td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
  47.            </tr>
  48.        <?php endforeach; ?>-->
  49.             <?php foreach ($_additional as $_data): ?>
  50.             <?php $_attribute = $_product->getResource()->getAttribute($_data['code']);
  51. if (!is_null($_product->getData($_attribute->getAttributeCode())) && ((string)$_attribute->getFrontend()->getValue($_product) != '')) { ?>
  52.            <tr>
  53.                <th class="label">
  54.                    <?php echo $this->htmlEscape($this->__($_data['label'])) ?>
  55.                </th>
  56.                <td class="data">
  57.                    <?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?>
  58.                </td>
  59.            </tr>
  60.            <?php } ?>
  61.            <?php endforeach; ?>
  62.  
  63.         </tbody>
  64.     </table>
  65.     <script type="text/javascript">decorateTable('product-attribute-specs-table')</script>
  66. <?php endif;?>
<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */

/**
 * Product additional attributes template
 *
 * @see Mage_Catalog_Block_Product_View_Attributes
 */
?>
<?php
    $_helper = $this->helper('catalog/output');
    $_product = $this->getProduct()
?>
<?php if($_additional = $this->getAdditionalData()): ?>
    <h2><?php echo $this->__('Additional Information') ?></h2>
    <table class="data-table" id="product-attribute-specs-table">
        <col width="25%" />
        <col />
        <tbody>
        <!--<?php foreach ($_additional as $_data): ?>
            <tr>
                <th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
                <td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
            </tr>
        <?php endforeach; ?>-->
            <?php foreach ($_additional as $_data): ?>
            <?php $_attribute = $_product->getResource()->getAttribute($_data['code']);
if (!is_null($_product->getData($_attribute->getAttributeCode())) && ((string)$_attribute->getFrontend()->getValue($_product) != '')) { ?>
            <tr>
                <th class="label">
                    <?php echo $this->htmlEscape($this->__($_data['label'])) ?>
                </th>
                <td class="data">
                    <?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?>
                </td>
            </tr>
            <?php } ?>
            <?php endforeach; ?>

        </tbody>
    </table>
    <script type="text/javascript">decorateTable('product-attribute-specs-table')</script>
<?php endif;?>

Then save the attributes.phtml file and upload that in your server. Now delete cache and refresh the product page.

Related Topics

  • How to get custom attributes value in Magento Frontend
  • How to remove auto added break (<br />) tag from product description of magento
  • How to include "Add to Compare" link on Related Products in Magento
  • Create Accordion Menu for Magento Layered Navigation
  • Change default sort order direction (ASC to DESC) for product listing in Magento
Posted in Magento- Tagged Maento Attribute
6 CommentsWritten by Admin

6 Comments

  1. Kanted
    June 21, 2012 at 2:08 PM | Permalink

    Perfectly worked on 1.7.0.0 version. Thank you

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *


seven + 6 =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code lang=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" extra="">

E-mail Subscription

Enter your email address:

Recent Posts

BPL Fixture 2013 | Download Bangladesh Premier League Time-Table

BPL Fixture 2013 | Download Bangladesh Premier League Time-Table

Bangladesh Premier League BPL 2013 All Teams and Players List

Bangladesh Premier League BPL 2013 All Teams and Players List

National University Result | Get Bangladesh NU Result

National University Result | Get Bangladesh NU Result

JSC (Junior School Certificate) And JDC Exam Result Bangladesh

JSC (Junior School Certificate) And JDC Exam Result Bangladesh

Primary Somapony Result | PSC (Primary School Certificate) BD

Primary Somapony Result | PSC (Primary School Certificate) BD

Download pdf 33rd BCS written exam routine and Seat Plan 2012

Download pdf 33rd BCS written exam routine and Seat Plan 2012

Degree 1st Year Final Routine of National University (NU) BD

Degree 1st Year Final Routine of National University (NU) BD

JSC (Junior School Certificate) Exam Routine 2012 Download PDF

JSC (Junior School Certificate) Exam Routine 2012 Download PDF

National University (NU) Honours Final (4th) Year Routine Download

National University (NU) Honours Final (4th) Year Routine Download

NU (National University) Honours 1st Year Routine PDF Download

NU (National University) Honours 1st Year Routine PDF Download

How to get oDesk money directly on Bank account from Bangladesh

How to get oDesk money directly on Bank account from Bangladesh

Dhaka University (DU) Admission Test Routine for 2012-2013

Dhaka University (DU) Admission Test Routine for 2012-2013

Recent Comments

  • chayan on National University Result | Get Bangladesh NU Result
  • Stan on Creating and Showing a static block in Magento Frontend
  • Stan on Creating and Showing a static block in Magento Frontend
  • Dani on How to get custom attributes value in Magento Frontend
  • Kiran on How to show products on Magento Homepage from specific Category
  • Bryan on How to Remove Callout section from left / right side of Magento
  • Sawon on Installing Magento on Localhost using WAMP Server
  • Keyur Shah on Installing Magento on Localhost using WAMP Server

Categories

  • Bangladesh Xpress
  • Magento
  • Sports
  • Tips and Tricks

EvoLve theme by Theme4Press  •  Powered by WordPress XpressBangla

Copyright © 2012 XpressBangla. All rights reserved.
You might also likeclose
  • Monday, 19/12/2011 2:48 PM
    Change default sort order direction (ASC to DESC) for product listing in Magento