4

enter image description hereI found it is hard to show the attributes in Description.phtml,it is hard to me.

i wish to show some attributes as Brand,Color,Name in Description.phtml ,i copied the attributes.phtml and change some code,but i got Blank ...

anyone help ?

Description.phtml is :

 <?php $_description = $this->getProduct()->getDescription(); ?> 
    <?php if ($_description): ?> 
         <div id="adtop"></div> 
         <div id="adbottom"></div> 
         <h2><?php echo $this->__('Details') ?></h2> 
         <div id="detailHtml"> 
             <?php echo $this->helper('catalog/output')->productAttribute($this->getProduct(), $_description, 'description') ?> 
         </div> 
     <?php endif; ?>
3

There are many ways to show the value of attribute on frontend. I am listing out one or two

1) Suppose you say the attribute name is brand and you want to display the value of it. You can use below code

<?php echo $_product->getAttributeText('manufacturer'); ?>

here $_product = $this->getProduct();

2) Suppose you want to get the name of certain field you entered from admin you can use following code

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

here $_helper = $this->helper('catalog/output'); and name is the attribute code.

Hope this helps

  • <?php $_helper = $this->helper('catalog/output'); ?> <?php $_product = $this->getProduct(); ?> <?php foreach ($_additional as $_data): ?> <?php $_attribute = $_product->getResource()->getAttribute($_data['code']); if (!is_null($_product->getData($_attribute->getAttributeCode())) && ((string)$_attribute->getFrontend()->getValue($_product) != '')) { ?> <?php echo $this->htmlEscape($this->__($_data['label'])) ?> <?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?> <?php } ?> <?php endforeach; ?> – sura white Nov 28 '14 at 8:16
  • here is the attributes.phtml,(I wish to show all NOT EMPTY attribues (which in admin i have set them to view at product list or view page) in Description.phtml ,and i found it just blank) – sura white Nov 28 '14 at 8:17
1

Use the same technique to display the custom attribute as Magento uses for displaying description attribute. You may display as many attributes as you want. All of them will be displayed near the description attribute

Layout catalog.xml

<block type="catalog/product_view_description" name="features_product_tab" template="catalog/product/view/custom_attr.phtml" after="-">
    <action method="setTitle" translate="title"><title>Color</title></action>
    <action method="setAttributeCode"><code>color</code></action>
    <action method="setShowLabel"><value>true</value></action>
</block>

<block type="catalog/product_view_description" name="product.description" as="description" template="catalog/product/view/description.phtml">
    <action method="addToParentGroup"><group>detailed_info</group></action>
    <action method="append"><block>features_product_tab</block></action>
</block>

catalog/product/view/custom_attr.phtml

<?php
$attributeCode = $this->getAttributeCode();
$attribute = $this->getProduct()->getResource()->getAttribute($attributeCode);
$attributeValue = $attribute->getFrontend()->getValue($this->getProduct());
/** @var $attribute Mage_Eav_Model_Entity_Attribute_Abstract */
?>
<?php if ($attribute && $attributeValue): ?>
<div class="custom-attribute <?php echo $attributeCode; ?>">
    <?php if ($this->getShowLabel()): ?>
        <label><?php echo $attribute->getFrontend()->getLabel(); ?>: </label>
    <?php endif; ?>
    <span class="value">
        <div class="std">
            <?php echo $this->helper('catalog/output')
                ->productAttribute($this->getProduct(),
                    $attributeValue,
                    $attributeCode) ?></div>
    </span>
</div>
<?php endif; ?>

catalog/product/view/description.phtml

Add to the end of file (or anywhere you need)

<?php echo $this->getChildHtml(); ?>
  • thanks.how aobut all attributes?not Many attributes. – sura white Nov 28 '14 at 12:20
  • Just to make sure: you need to display all product attributes? Is that correct? – MageWorx Nov 28 '14 at 13:16
  • Show the attributes at the Description.phtml,like detail.tmall.com/item.htm?id=21719324031 i have uploaded the image to explain what i want at this topic – sura white Nov 29 '14 at 4:53
  • the attirbutes are Just which i choose DISPLAY AT THE FRONTEND PRODUCT PAGE – sura white Nov 29 '14 at 4:54
  • See my updated answer. I've added changes to catalog/product/view/description.phtml and to catalog.xml – MageWorx Dec 1 '14 at 8:40
1

for me on decription.phtml work only

$attributeValue = $this->getProduct()->getResource()->getAttribute('technical')->getFrontend()->getValue($this->getProduct());
0
<?php echo $attributeValue = 

$this->getProduct()->getResource()->getAttribute('you_attribute_name')->getFrontend()->getValue($this->getProduct()); ?>

Please try this code , if you need to call a attribute in description.phtml file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.