Just thought I’d share something cool I found out in Magento.
The client wanted to show a short tagline to describe a product that was to appear on the home page (within a static block) – but both the descrition & Short Description fields were already taken.
After searching around for ages looking for an easy way of doing this, I decide to create a new Attribute for the product called “tagline”.
I made it a text field and made it have Global scope and visible from the front end.
Next I scratched my head trying to find ways of actually extracting the value of this attribute. There seemed to be no definite answer in how to get an attribute value.
Then I stumbled across a post which suggested that getATTRIBUTENAME() would do the trick – which seems to go against every instinct I have as a developer.
But lo and behold using $product ->getTagline() did actually work and retrieve the new attribute “tagline” I had created.
Magento is marvellous – completely baffling most of the time but marvellous!
Update : 11th jan 2011
Talking to a colleague about this – he mentioned that this was a feature of the Zend Framework on which Magento is built. So maybe not as mind-blowing as I first thought. Still pretty cool though…