0

How to get color family values and option Id for product in magento2.

0

Inject an instance of \Magento\Eav\Model\Config to your constructor, before you use that to get an entity's attribute option values.

protected $eavConfig;

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

public function getAttributeOptionValues()
{
    $attribute = $this->eavConfig->getAttribute('catalog_product', '<your_attribute_code_here>');
    $options = $attribute->getSource()->getAllOptions();

    foreach ($options as $optionId => $optionValue) {
        /* Your logic here; */
    }
} 

Replace your_attribute_code_here with the required attribute code ( in your case color family).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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