0

I am getting attribute values of an attribute color as 5567, 5568, 5569 etc in block of my custom module.

I want to get the attribute color instead of values as red, blue.

I am getting values as below -

$productCollection = $this->getProductCollection();
    foreach ($productCollection as $product) { 

        $colrValue = $product->getColor();

}

Please help.

2 Answers 2

0

Use getAttributeText() function.

 $productCollection = $this->getProductCollection();
        foreach ($productCollection as $product) { 
            $colrValue = $product->getAttributeText("color");
    }
0

You can try this code.

$productCollection = $this->getProductCollection();
foreach ($productCollection as $product) { 
    $product->getResource()->getAttribute('color')->getFrontend()->getValue($product);
}

Hope this will help you!

1
  • Have you tried this ? @chanchal Nov 6, 2019 at 11:06

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.