![]()
Adding custom attributes to your product view is very easy. Adding them to the product listing (category pages) is much more difficult. You’ll need to create a custom module for that. In this post though, I’ll only be showing you how to add attributes to the product view page.
If it is a text field (textbox or textarea), this is all you have to do:
1 | <?php echo $_product->getAttributeName() ?> |
There is one thing different here though. If your Attribute Code is “shirt_size”, then you would use getShirtSize(). Remove the underscores and capitalize the first letter of each word. It is picky that way. if you use getshirtsize(), it won’t work.
If you are using a dropdown or a multiple select, you have to call it a little differently:
1 | <?php echo $_product->getAttributeText('shirt_size') ?> |
This method requires the actual Attribute Code. If you are displaying the value from a dropdown, you’ll get exactly what you need with this call. If you are wanting to display the values from a multiple select, it will return an array.
What file is this in?
Astronomad,
/app/design/frontend/default/default/template/catalog/product/view.phtml
I need to show select box of my new attributes(color/size). that i did by using above method.
Now i need to show the attribute in shopping cart and also it must be shown in order details page how can i do that?
Thanks so much for this great info. I used this to show an attribute on view.phtml that is a link. I see the link and my attribute but it is text rather than an active hyperlink. Any ideas ? Thanks for the wonderful resource Josh !
Thanks.. I was wondering why my getAttributeText wasn’t working for the text field.
and how for price fields?
Fantastic, thank you soooo much! How do people find out this stuff?
Thank you for this little snippet. It was exactly what I was looking for. Is there a list of common functions for Magento like can be found in the WordPress codex? I find the Magento wiki to be… lacking.
thank you soo much, this is exactly what I was looking for.
using magento 1.3.2.4, how to get custom attributes in the /app/design/frontend/default/default/template/catalog/product/list.phtml intead of view.phtml.
i want to show custom attributes in the product listing when people are searching for it.
i tried using $_product->getNextShipmentDate() but it returns null in list.phtml. it returns the expected value in view.phtml.
i got it.. i had to enable ‘Used in product listing’ in the attribute settings.
after enabling this, $_product->getNextShipmentDate() is not returning null anymore and showing the same value as in view.pthml.
now i need to figure out how they format the date for display.
great for product pages… however getAttributeText(”) for custom category attributes.. not so good.
The attribute I just created is a drop down for categories, now getNAMEOFATTRIBUTE() returns a 1,2 or 3 (the total number of drop down options I have) but never the value of the selected attribute option. getAttributeText(”) as you stated is for drop downs returns nothing.
Completely opposite for product pages though.
Thanks “ted”.
Information provided by you helped me a lot.
Thanks again…
“ted”?
Thank you so much for your valuable contribution
i created an attribute which is price attribute and i named it “retailprice”. I can see it in the additional information tab. How can i show it in the product list?
How to get the product cost attribute value on reports .
i need this product cost feild to be displayed on sales report and best sellers report.
report–>sales–> sales report
report–>Advanced–> bestsellers
plz help its urgent.
Any idea why this wont work on catelog->category->view.pthml when trying to call out category attributes? As I stated above, getAttributeText(‘my_attribute’) for category drop downs or multi-select wont work on category level..
Very frustrating.
OH got it!
Note to self (and others):
$categoryFull = Mage::getModel(“catalog/category”)->load($this->getCurrentCategory()->getId());
$attributes = $categoryFull->getAttributes();
echo $attributes['your_custom_attribute']->getFrontend()->getValue($categoryFull);
This will get values of custom attributes for categories!
isnt this posible in the xml files? I dont like changing the templates…
It’s great! Thank you!