1

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);

!

3

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();
}
3

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());
}
1

I used this.

$attribute_value = $_product->getData($attributeCode);

It's Working!

1

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']; 
}

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.