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).

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;
| improve this answer | |
  • where i used thid code? – Lovely Setia Jul 4 '18 at 13:42
  • You need to used the code, where you want option text. – Dhiren Vasoya Jul 4 '18 at 13:52
  • I want to get it on rest/V1/products/:sku response. – Lovely Setia 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. – Dhiren Vasoya Jul 5 '18 at 5:18
  • If you have new question, then ask seprately, So other can also help you. – Dhiren Vasoya Jul 5 '18 at 9:59

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.