How to get custom product attribute(programatically created) drop down values in a phtml in magento 2?
-
09-10-2020 - |
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
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