Question

Created a custom product attribute by programmatically. Now, I need to get the drop down option values in a phtml page.

$seriesname  =   $child->getAttributeText('series');

$values =   $product->getResource()->getAttribute('series')->getFrontend()->getValue($product);

$_attributeValue = $block->getProduct()->getResource()->getAttribute('series')->getFrontend()->getValue($block->getProduct());

Used the above three methods, but I didn't get all the values. I only get 'Select Option'. It has three option values, option1, option2, option3

Was it helpful?

Solution

You can use this

$attr = $product->getResource()->getAttribute('series');
if($attr->usesSource()) {
    $allOptions = $attr->getSource()->getAllOptions(true, true);
    var_dump($allOptions);die;
}

OTHER TIPS

You can get it by below code

$_attributeValue = $block->getProduct()->getResource()->getAttribute('series')->getFrontend()->getValue($block->getProduct());
$values =   $product->getResource()->getAttribute('series')->getFrontend()->getValue($product);
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top