Question

I have a custom eav attribute on a product that is a of type dropdown. When the product is saved, the attribute is saved as the optionId. How do I get its label to be able to display it properly on the frontend.

Note:

  • I do not want to load the whole set of options for the attribute and loop through the find the matching one. I want to be able to get the label for the saved id value.
  • I have the attribute option id and the attribute code and can use them for query.
Était-ce utile?

La solution

get the productdata by id or sku i am using getbyId

$productData = $this->productRepository->getById($productId);

$attributeValue = $productData->getAttributeText("attribute_code");//pass your attribute code 
Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange
scroll top