How to get custom product attribute(programatically created) drop down values in a phtml in magento 2?
-
09-10-2020 - |
Pergunta
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
Solução
You can use this
$attr = $product->getResource()->getAttribute('series');
if($attr->usesSource()) {
$allOptions = $attr->getSource()->getAllOptions(true, true);
var_dump($allOptions);die;
}
Outras dicas
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);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a magento.stackexchange