0

I want to show brand name in product details page above product name.So I want to write code in title.phtml.I wrote like this

      $objectManager = \Magento\Framework\App\ObjectManager::getInstance();

      $productBlock = $objectManager->create('\Magento\Catalog\Block\Product\View\AbstractView');
      $product = $productBlock->getProduct();

      $product->getAttributeText('manufacturer');

but nothing shows. How do I achieve this?

0

Use following code it may be helps use

  $objectManager = \Magento\Framework\App\ObjectManager::getInstance();

  $productBlock = $objectManager->create('\Magento\Catalog\Block\Product\View\AbstractView');
  $product = $productBlock->getProduct();

  $product->getResource()->getAttribute($code)->getFrontend()->getValue($product); 
1
1

Magento doesn't load all the product attributes. So you have to check if you marked this attribute to show on the product detail view:

Go in the administration to the menu Stores > Attributes Product Select the attribute you want to show Go to Storefront Properties and make sure "Visible on Catalog Pages on Storefront" is "Yes"

When you change that value you should reindex so Magento adds the value to the flat table.

After that (maybe clean the cache) you should be able to get the value for the attribute on a product page.

$_attributeValue =$_product->getResource()->getAttribute('brand')->getFrontend()->getValue($_product);

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.