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
Asked
Active
Viewed 1,357 times
0
-
You have to iterate through the values and display them individually. Since you didn't give much information, that's all I can offer sorry. – Zachary Schuessler May 09 '12 at 23:41
-
Hi Zachary, I have the following code in my product's view.phtml file: `getAttributeText('metal') ?>` How would I iterate through them to get them all to display? – Sam May 09 '12 at 23:43
2 Answers
0
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; ?>

Joseph at SwiftOtter
- 4,276
- 5
- 37
- 55
-
-
Only Problem is I can't figure out how to separate values with br or bullet points. – Sam May 10 '12 at 20:42
0
I found this on Magento forums and it seems to work: ` getData('attribute_name')): ?>
getResource()->getAttribute('attribute_name')->getFrontend()->getValue($_product)) ?>
`

Balaji Kandasamy
- 4,446
- 10
- 40
- 58

Sam
- 5,150
- 4
- 30
- 51