2

In Magento 1.x I could show the Admin value of an Attribute like this:

_product->getAdminAttributeText('bleach')

But it doesn't work in Magento 2. How can I show the Admin value of a dropdown list in Magento 2?

3 Answers 3

1

Easy way to do this (maybe not the cleanest):

$product->getResource()->getAttribute('attribute_code')->setStoreId(0)->getFrontend()->getValue($product);
0

Create object and load the product using id.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$_product = $objectManager->get('Magento\Catalog\Mode\Product')->load($product_id);

Get the value using option id.

$optionId = 10;
$attr = $_product->getResource()->getAttribute('color');
if ($attr->usesSource()) {
   $optionText = $attr->getSource()->getOptionText($optionId);
    }
2
  • Thank you, how do I get the ID number and how do I output the value? Commented Sep 27, 2016 at 6:56
  • option ID can be fetched using inspect element Commented Sep 28, 2016 at 11:23
0

To get the admin value of an attribute, try this :

$attribute = $product->getResource()->getAttribute('YOUR_ATTRIBUTE_NAME');
$adminValue = $attribute
              ->setStoreId(0) // Admin store ID
              ->getSource()->getOptionText($product->getData('YOUR_ATTRIBUTE_NAME'));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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