1

I have created a field in system->config to save an attribute code which is already created.(For eg:color)

Based on that value, I need to get all the option values of that attribute.(ie ,In my admin form drop down, I need to display its option values as red,blue,green).

How it is possible ? Please help.

Mrunmay Deswandikar
1,2995 gold badges24 silver badges43 bronze badges
asked Dec 29, 2016 at 12:05

1 Answer 1

4

Add to the constructor in your class an instance of \Magento\Eav\Model\Config like this:

protected $eavConfig;
public function __construct(
 ...
 \Magento\Eav\Model\Config $eavConfig,
 \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
 ...
){
 ...
 $this->eavConfig = $eavConfig;
 $this->scopeConfig = $scopeConfig;
 ...
}

then you can use that in your class

$attribute_code_here = $this->scopeConfig->getValue('dev/debug/template_hints', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
$attribute = $this->eavConfig->getAttribute('catalog_product', $attribute_code_here);
$options = $attribute->getSource()->getAllOptions();
answered Dec 29, 2016 at 12:43
3
  • @V.P, If my answer solve your issue then mark as accepted. So other user take benefits from this. Commented Dec 29, 2016 at 13:36
  • I also want to show product attribute label in custom grid instead of attribute value. Currently it showing attribute option value. please suggest Commented Aug 25, 2017 at 14:07
  • I want to display attribute options dropdown in admin form and grid, please help me Commented Jul 23, 2018 at 8:04

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.