0
$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']
1
  • get attribute options Right ??? Commented Feb 9, 2021 at 12:58

1 Answer 1

0

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;
    }
}
6
  • Good, but I need my custom dropdown values in helper data.php file Commented Feb 10, 2021 at 7:50
  • Please clarify your question properly. Is this product attribute? Are you trying to get dropdown attribute's option?
    – ZealousWeb
    Commented Feb 10, 2021 at 8:01
  • As per your code in your question seems you are trying to get product attribute(dropdown attribute) options. What your need exactly? And why you have written "echo $featuredOptions['option_id']" ? Please explain it properly so i can give you answer as per your need.
    – ZealousWeb
    Commented Feb 10, 2021 at 9:13
  • I am trying to get dropdown value which is in admin config form in helper file. Commented Feb 11, 2021 at 5:07
  • Can you please share admin screen shot where this dropdown shown?
    – ZealousWeb
    Commented Feb 11, 2021 at 9:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.