Question

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

    /** @var \Magento\Eav\Api\AttributeOptionManagementInterface $attributeOptions */

    $attributeOptionsManagement = $objectManager->get(\Magento\Eav\Api\AttributeOptionManagementInterface::class);

    /** @var \Magento\Eav\Api\Data\AttributeOptionInterface[] $attributeOptions */

    $attributeOptions = $attributeOptionsManagement->getItems(\Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE, 'feature_products');
    $featuredOptions = [];
    foreach ($attributeOptions as $attributeOption) {
    $featuredOptions[$attributeOption->getValue()] = $block->escapeHtml($attributeOption->getLabel());
    }
echo $featuredOptions['option_id']

No correct solution

OTHER TIPS

Here my dropdown attribute code is - "certification"

So you can write below code to get dropdown attribute options in helper file

<?php
namespace Vendor\Module\Helper;

class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
    protected $_eavConfig;

    public function __construct(
        \Magento\Eav\Model\Config $eavConfig
    ) {
        $this->_eavConfig = $eavConfig;
    }

    public function getDropdownOptions()
    {
        $attribute = $this->_eavConfig->getAttribute('catalog_product', 'certification');
        $options = $attribute->getSource()->getAllOptions();
        $optionsArray = [];

        foreach ($options as $key => $attributeOption) {
            if($attributeOption['value']) {
                $optionsArray[$attributeOption['value']] = $attributeOption['label'];
            }
        }
        return $optionsArray;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top