Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

How to show some attributes in main section of Product View? 
 
Genbit
Member
 
Total Posts:  41
Joined:  2007-08-31
Krasnodar
 

For example, I want add attribute “Producer” after Product Name. How I can do this?

At now, i did that:

I added methods in class Mage_Catalog_Model_Product:

public function getAttribute($attributeId)
    
{
        $attributes 
$this->getAttributes();        
        return (isset(
$attributes[$attributeId])?$attributes[$attributeId]:null);
    
}
    
    
public function getAttributeLabel ($attributeId)
    
{
        $attribute 
$this->getAttribute($attributeId);
        if (
is_null($attribute))
            return 
null;
        
        return 
$attribute->getFrontend()->getLabel();
    
}
    
public function getAttributeValue($attributeId{
        $attribute 
$this->getAttribute($attributeId);
        if (
is_null($attribute))
            return 
null;
        
        return 
$attribute->getFrontend()->getValue($this);        
    
}

and in view.phtml

<h3 class="product-name"><?=$_product->getName()?></h3>
<
h4 class="product-producer"><?=$_product->getAttributeLabel('producer'); ?><?=$_product->getAttributeValue('producer'); ?></h4>

But may be it can be done more easily?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Mark_Kimsal
Sr. Member
 
Total Posts:  186
Joined:  2007-09-12
Michigan, USA
 

If it were me, I would create a function called ... showExtraAttributes() or something, inside that function it would loop through another attribute that contains all the attributes you want printed…

Something like this

$product->showExtra = ‘producer, factory, size, color’;

Then,

function showExtraAttributes() {
  $extra 
explode(','$this->showExtra);

  foreach (
$extra as $val{
    
echo '<h4>'$this->getAttributeLabel($val).'</h4>';
   
}
}

Something like that… that way you can control which attributes are shown in the admin area instead of constantly changing the template file.  Change the value of the attribute “showExtra” to include the names of all the other attributes you want to show.  It’s not “easier”, really, but it’s more flexible, I think.

 
Magento Community Magento Community
Magento Community
Magento Community
 
MJsmart_1
Jr. Member
 
Avatar
Total Posts:  29
Joined:  2008-02-12
PARIS
 

Hi,
I have a solution for this problem…
You can open this class :
Mage_Catalog_Model_Resource_Eav_Attribute
line 132

/**
     * Retrieve don't translated frontend label
     *
     * @return string
     */
    public function getFrontendLabel()
    
{
        
return $this->_getData('frontend_label');
    
}

    
/**//tempend ?>
After that you can write this :
echo ($_product->getAttribute('YourAttribute')->getFrontendLabel());
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top