Magento 2 – Get Attribute Value Using Attribute Code

magento2product-attribute

I have Attribute Code. Am trying to fetch value but this code is not fetching attributes values that are in the decimal table!

$_product->getResource()->getAttribute($attributeCode)->getFrontend()->getValue($_product);

!

Best Answer

We can get attributeValue using following code

if it is a custom attribute

$products = $this->_productRepository->get($sku);
if(is_object($products->getCustomAttribute($attributeCode))){
    return $products->getCustomAttribute($attributeCode)->getValue();
}
Related Topic