0

I have this attribute enter image description here

CODE PHP:

  $attributeCode = 'product_text';

                if ($_product->getData($attributeCode) !== null){
                    echo $_product->getAttributeText($attributeCode);
                }else{
                    echo 'Is NULL';
                }

The problem is I get NULL for each product and I can not display the value of the attribute.

What is wrong?

Thanks in advance![enter image description here]2

1
  • Have you got solution ?
    – Pawan
    Jul 28 '17 at 3:48
0
if ($_product->getData($attributeCode) !== null){

                    echo $_product->getData($attributeCode);
                }else{

                    echo 'Is NULL';
                }

Syntax:

echo $_product->getData('attribute_code');

echo $_product->getAttributeText('attribute_code'); // in case of dropdown
0

First when you set this config Used in product list , you should reindex all and clear the cache

Then you can use $_product->getAttributeText('my_attribute');

0
$attributeCode = 'product_text';
if ($_product->getData($attributeCode) != null)
{
    echo $_product->getProductText();
}
else
{
    echo 'Is NULL';
}

Also set one more field value to yes, follow this screen-shot enter image description here

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.