$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']
-
get attribute options Right ???– Ronak RathodCommented Feb 9, 2021 at 12:58
Add a comment
|
1 Answer
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;
}
}
-
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? 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. 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? Commented Feb 11, 2021 at 9:12