Magento 2.4: I have a custom product attribute called shop_status
. It has two possible options:
- ACTIVE
- INACTIVE
I would like to get the option ID from the text label, eg:
$id = $attribute->getOptionValue('ACTIVE');
Is there any function to do this?
I know I can get a list of the options and loop through to find like so:
$attribute = $this->attributeRepository->get(
'catalog_product',
'shop_status'
);
$options = $attribute->getOptions();
foreach ($options as $option) {
// If label == ACTIVE
}
Is there a better way to do this?