Question

I am trying to load multiple values of Color attribute in product list phtml file with this code:

<?php echo __('Color: ') . $_product->getAttributeText('color'); ?>

But I get array error:

Notice: Array to string conversion

Any help please? This is magento 2.4 version

Était-ce utile?

La solution

Try the following way:


$color = $_product->getAttributeText('color');
        if ($color) {
            if (is_array($color)) {
                echo implode(',', $color);
            } else {
                echo $color;
            }
        }
Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange
scroll top