0

I need to display a custom attribute bellow the product name and I don't know how can I call this attribute.

I am editing the file /app/design/frontend/templatemela/MAG100219_1/template/catalog/product/view.phtml But how can I call this attribute in php? I tried calling a string echo with the name I put in the attribute, but it didn't work.

Code is as below:

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

<div class="codigoinmetro"> 
<h2><?php echo $_helper->productAttribute($_product, $_product->getName(), 'registroinmetro') ?></h2>
</div>
  • Which type of attribute you have text or dropdown? – Utsav Gupta Jan 2 '19 at 13:28
0

Check below code i'm using this code. this code working fine. replace your attribute name with (Brand)

<?php
$brandname = $_product->getAttributeText('brand');
    if (trim($brandname)) {
        echo "" .$this->htmlEscape($brandname);
    }
?>
0

Try the code below:

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

 <div class="codigoinmetro"> 
 <h2><?php echo $_helper->productAttribute($_product, $_product->getRegistroinmetro(), 'registroinmetro') ?></h2>
 </div>
  • what this $_helper point to ? – Sourav Apr 17 '18 at 10:21
  • Its points to product module (Magento core Module For Product) helper. If you open that helper file you will see "productAttribute" function. – Chirag Rajput Apr 17 '18 at 10:23
  • @Sourav , $_helper in my code is the correction of the question's code. – Chirag Rajput Apr 17 '18 at 10:31
  • @EmanuellVieira , had your problem solved yet? – Chirag Rajput Apr 19 '18 at 9:27
0

If you have select type attribute then you can use below code to get attribute value:

$attributeName = $product->getAttributeText('attributename');
If you have input type attribute then you can use below:
$attributeName = $product->getAttributeName ();

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.