2

I have created a custom attribute "color" and it has the values Red, Green, Blue. When I call /V1/products/:sku it shows the product details and also shows the custom_attributes{"attribute_code":"color","value":"74"}. I want the value of the attribute is "Red" instead of 74 (It's ID).

1
0

You need to try this code.

$_product = $productObject; //get product object

$optionId = 74;   
$attr = $_product->getResource()->getAttribute('color');
if ($attr->usesSource()) {
   $optionText = $attr->getSource()->getOptionText($optionId);
}
echo $optionText;
6
  • where i used thid code? Jul 4 '18 at 13:42
  • You need to used the code, where you want option text. Jul 4 '18 at 13:52
  • I want to get it on rest/V1/products/:sku response. Jul 5 '18 at 5:08
  • you need to set the code according to your requirement. May be you need to overide somethings or make custom code. Jul 5 '18 at 5:18
  • 1
    This answer is not helpful. The question is about the REST-API (see the flags). Aug 6 '18 at 6:52

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.