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
Vindhuja
1,4051 gold badge21 silver badges44 bronze badges
1 Answer 1
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
Ashish Jagnani
6,3047 gold badges36 silver badges71 bronze badges
-
@V.P, If my answer solve your issue then mark as accepted. So other user take benefits from this.Ashish Jagnani– Ashish Jagnani2016年12月29日 13:36:30 +00:00Commented 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 suggestPurushotam Sharma– Purushotam Sharma2017年08月25日 14:07:00 +00:00Commented Aug 25, 2017 at 14:07
-
I want to display attribute options dropdown in admin form and grid, please help meAshna– Ashna2018年07月23日 08:04:33 +00:00Commented Jul 23, 2018 at 8:04
default