Magento 2 – New Product Attributes Not Displaying on Frontend

attributesfrontendmagento2productproduct-attribute

I have created a counfigurable product with. New Attribute Set & it's attributes. I have set the value in Admin also.

On vendor\magento\module-catalog\view\frontend\templates\product\list.phtml

I'm customizing listing. I'm trying to get my newly added attribute using

foreach ($_productCollection as $_product):
    echo $_helper->productAttribute($_product, $_product->getYear(), 'year');

    $attribute = $_product->getResource()->getAttribute('year');
    if ($attribute) {
        echo $labelValue = $attribute->getFrontend()->getValue($_product);
    }
endforeach;

But it's still not displaying set value. I'm able to see value in Admin Product Page. But not in the frontend.

I have cleared cache as well.

Best Answer

0 down vote Replace below code :

$attribute = $_product->getResource()->getAttribute('year');

to my Code

$_attributeValue =$_product->getResource()->getAttribute('year')->getFrontend()->getValue($_product);

remove your Code use my code only one you have to use this will work

After Editing the code run the below command:

php bin/magento cache:flush` & `php bin/magento cache:clean
Related Topic