I have the following situation: For our online-bookshop I have created an attribute called author. Now, I would like to be able to have a link on any product-page. E.g. on the product-page of a book by J.N. Darby I want to have the author’s name converted to a link to the advanced search result page, for author J.N. Darby.
The problem is that I need the ID for the option to achieve that. I know, how to get the option value via getAttributeText(’author’), but how do I get the corresponding ID?
I’ll have a look at it later (I just had a very exhausting day trying to fly through the snow in europe). For the moment: Thank you very much for answering!
Hi subesh,
that got me exactly where I wanted!
I have another problem however that maybe you can help me.
I need to load a customer address attribute but based on the admin value I set to it in the backend.
when I run your code, I get the array with all its values and labels but can’t find the value set in the admin. Do you know what I mean with that?
thanks a lot!
Well, I got something going although I doubt this is the best way to go… here it is:
apparently the admin values are stored in another store (which would happen to be the admin one)
What I managed to do is change the store to load the data and then switch back.
// SET TO ADMIN STORE Mage::app()->getStore()->setId(0); $add = Mage::getModel('customer/address')->load($order->getShippingAddress()->getId()); $attribute = $add->getResource()->getAttribute("district"); $district = $attribute->getSource()->getOptionText($order->getShippingAddress()->getData('district')); // SET BACK TO DEFAULT STORE // NOTE THAT YOUR STORE MAY DIFFER FROM MINE IF YOU ARE USING MORE THAN ONE Mage::app()->getStore()->setId(1);
Hope this helps someone, and please if you come up with a better way, let me know!
If you’re getting strange characters it sometimes means that Magento doesn’t recognize variables.
I’m guessing the reason in this case is a “$product” variable.
So change subesh’s first line a bit
from