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);
!
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();
}
U Can used this and Get Custome And Defult attributes Option Data, For Example
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$atrributesRepository = $objectManager->create('\Magento\Catalog\Model\Product\Attribute\Repository');
$selectOptions = $atrributesRepository->get('AttributeCode')->getOptions();
foreach ($selectOptions as $selectOption) {
print_r($selectOption->getData());
}
You can use this code to get attributes value :
$eavConfig = $this->objectManager->get('\Magento\Eav\Model\Config');
$attribute = $eavConfig->getAttribute('catalog_product', 'color');
$alloptions = $attribute->getSource()->getAllOptions();
foreach($alloptions as $option) {
$label = $option['label'];
$AllOptionsArr[$label][] = $option['value'];
}
$product = $this->_productRepository->create()->load($productId);
$attributeValue = $product->getData('yourattribute_code');