Magento product display text & ldquo; Array & rdquo; instead of multiple values

advertisements

On my Magento product page; when a product has multiple values for one custom attribute; instead of displaying the values it displays the text "array". It works fine with one value. Thanks, -Sam


You can do something like:

<?php
    foreach($_product->getMetal() as $name => $value): ?>
<?php echo $name;?> = <?php echo $value;?>
<?php
    endforeach; ?>

Magento takes advantage of PHP's magic getter/setter functionality (http://www.php.net/manual/en/language.oop5.overloading.php#object.get).

You can do a vardump($_product) to see the available attributes (they are stored in the _data array in the product). Then to retrieve one of them, you just remove the underscores and change the first letter of each word to uppercase.

EDIT:

If the above code doesn't output values, you can do this (which will tell you how to get to the value):

<?php
    foreach($_product->getMetal() as $attribute): ?>
<?php var_dump($attribute); ?>
<?php
    endforeach; ?>