7

When I try to get data from the material attribute like $_product->getData('material'), it shows the integer value. How can I convert it to the actual front-end value.

10

Instead of getData() you need to use getAttributeText('attribute_code') for dropdown attributes. like

$_product->getAttributeText('material');

For multi-select try this :

$result = $_product->getResource()->getAttribute('material')->getFrontend()->getValue($_product);
  • material has multi select values and it gives the values like 25,19,15 on 'getData()' where as getAttributeText('material') gives blank page on load – user47136 Nov 17 '16 at 7:31
  • @Hemant, Check my updated answer once and let me know. – Ashish Jagnani Nov 17 '16 at 9:03
  • product->getResource() seems to be deprecated – Alex Mar 13 at 11:15
6

To fetch value of attribute Use:

$this->getProduct()->getAttributeText('material');

Or

$this->getProduct()->getResource()->getAttributeRawValue($this->getProduct()->getId(),'material',$this->_storeManager->getStore()->getId());
  • product->getResource() seems to be deprecated – Alex Mar 13 at 11:15
5

You can get product attribute option values by below code

$_product->getAttributeText('material');

You can get multi select option values by

$_attributeValue = $block->getProduct()->getResource()->getAttribute('sizing_guidelines')->getFrontend()->getValue($block->getProduct());
  • Sorry material has multi select values and it gives the values like 25,19,15 – user47136 Nov 17 '16 at 7:31
  • Try my updates answer – Suresh Chikani Nov 17 '16 at 7:32
  • I tried it gives blank page – user47136 Nov 17 '16 at 7:33
  • Have you got any solution for that and tell me which file in try to it. – Suresh Chikani Nov 17 '16 at 7:34
  • i Am trying to get data in phtml template – user47136 Nov 17 '16 at 7:35
0
$_product->getAttributeText('material');

is the right answer --- beware that $_product->getResource() is a deprecated function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy