1

I am working on aMagento 1.9website.

I want to add an attribute of the brand on theproduct page under the product name.

I have highlighted in the following image.


enter image description here

can anyone please guide how can I do the same.

0

Open ..\..\catalog\product\view.phtml

And Find line,

<span class="h1"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></span>

Put the code below span

<?php
    $productId = $_product->getId();
    $product= Mage::getModel('catalog/product')->load($productId);
    $manufaturer= $product->getAttributeText('manufacturer');
    echo $manufaturer;
?>
  • It worked and am able to add attribute on page but the size of that text is too small can you please guide how can i increase its size and if possible change its color too ? – RANU EMPRISE Jun 25 '18 at 23:12
  • You Can Put this code after this -> <div class="product-name"></div> your code – Jugal Kishor Jun 26 '18 at 8:53
0

For example, Your attribute code is "Brand", You need to use this code in following location:

/app/design/frontend/[your package]/[your theme]/template/catalog/product/view.phtml:

<?php
   $Brand = $this->htmlEscape($_product->getData('Brand'));    
   echo $Brand;    
?>

Or

echo $this->htmlEscape($_product->getData('Brand')); 
0

If you want to add with saperate file then you can call custom phtml file before after sku,

<referenceContainer name="product.info.stock.sku">            
    <block class="Magento\Catalog\Block\Product\View" name="product_view_style" template="Magento_Catalog::product/view/custom.phtml" before="-"/>
</referenceContainer>

and create custom.phtml here ,

YOUR_THEME/Magento_Catalog/templates/product/view/custom.phtml

<?php $_product = $this->getProduct();
 $optionId = $_product->getData('color');

  /*Swacth Text value*/
  $attr = $_product->getResource()->getAttribute('color');
  if ($attr->usesSource()) {
     $optionText = $attr->getSource()->getOptionText($optionId);
  }
  echo  $optionText;
 ?>

Hope it's help you !

0

To edit some extra information you should not modify default Magento file. For this, you can override Magento default file in your theme.

To display brand attribute value after product name follows below steps:

1.Copy view.phtml file from

magento/app/design/frontend/base/default/template/catalog/product

and place in

magento/app/design/frontend/[your_package]/[your_theme]/template/catalog/product/

in this file, you can see

<div class="product-name">
    <h1><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h1>
</div>
  1. Write below code after completion of "product-name" div, for example, your attribute code is "brand" and attribute type is "text" then

    <div class="brand-name">
        <?php echo $this->->escapeHtml($_product->getData('brand')); ?>
    </div>
    

if the attribute type is dropdown then use

<div class="brand-name">
    <?php echo $_product->getAttributeText("brand"); ?>
</div>

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.