1

I have created "Text Field" Attribute and configured "Yes" in "Used in Product Listing". while I am trying to retrieving value of this text field using below code it is giving me blank output.

<?= /* @escapeNotVerified */ $_product->getTestAttribute() ?>

enter image description here

Still not able to get value of this attribute in my product/list.phtml file. Thanks in advance.

4
  • For the list page you can use $_product object, whats you code, please add here.
    – Lasantha
    Commented May 4, 2018 at 6:12
  • I have already written the code in question. For testing purpose my attribute name is "TestAttribute" . So, I have used below code in my .phtml <?= /* @escapeNotVerified */ $_product->getTestAttribute() ?> Commented May 4, 2018 at 6:42
  • Try getData() , getAttributeText() functions. "<?= " is it support short tags
    – Lasantha
    Commented May 4, 2018 at 6:56
  • Yes, it is supporting "<?=" short tags. I am using this for other attributes. in $_product->getData() output I am not able to find my "TestAttribute" . I think, this is the reason I am not able to get value of it. Ideally it should be there in product attribute. Commented May 4, 2018 at 7:06

2 Answers 2

2
$_getMyAttr = $_product->getResource()->getAttribute('my_attribute');

// Get Value

$attrTestValue = $_getMyAttr->getFrontend()->getValue($_product);

// Get Label

$attrTestLabel = $_getMyAttr->getStoreLabel();
0

Please check values are there in admin product section. if the values are present, it will display on frontend.

1
  • Yes, I have checked value is there in admin product section. Commented May 4, 2018 at 6:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.