Frage

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.
War es hilfreich?

Lösung

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 
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit magento.stackexchange
scroll top