문제

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.
도움이 되었습니까?

해결책

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 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top