Friday, 15 June 2012

How to get Dropdown Attribute value

In Magento it is possible to access a product’s attributes with a simple getter method. Let’s get the attribute test:

<?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?> 

There is one thing different here though. If your Attribute Code is “shirt_size”, then you would use getShirtSize(). Remove the underscores and capitalize the first letter of each word. It is picky that way. if you use getshirtsize(), it won’t work.
If you are using a dropdown or a multiple select, you have to call it a little differently:

<?php echo $_product->getAttributeText('shirt_size') ?>
 
 
<?php $_product->getResource()->getAttribute('contrast_ratio')
    ->getFrontend()->getValue($_product); ?>

Note : contrast_ratio is your dropdown attribute code


1 comment:

  1. Great blog. All posts have something to learn. Your work is very good and i appreciate you and hoping for some more informative posts.keep writing
    magento development company in bangalore 

    ReplyDelete

Note: only a member of this blog may post a comment.