Product collections by default load a subset of the products' attributes, unlike $product->load()
which loads all product attributes.
You have to make sure that the msrp
attribute is loaded by the product collection you're using. See Mage/Catalog/etc/config.xml
, the config/frontend/product/collection/attributes
node:
In your module's config.xml
you can add msrp
:
<config>
...
<frontend>
<product>
<collection>
<attributes>
<msrp />
</attributes>
</collection>
</product>
</frontend>
...
<config>
Alternatively, you can tap into the block that loads the product collection and do a $productCollection->addAttributeToSelect('msrp');
. Another option is to also add an observer to the product collection load before event and again add the attribute to the select.
/Edit: If System -> Configuration -> Catalog -> Frontend -> Use Flat Catalog Product is enabled, product collections on the frontend read from the flat tables. That means that the attribute has to be one of the attributes indexed this way otherwise it will be silently ignored (addAttributeToSelect does nothing). An attribute to be indexed in the flat tables has to meet a few conditions that I don't remember exactly right now. I think the attribute has to be Used in product listing
, Use in Layered Navigation
and something else.
Cheers
/Edit: adding information from the comments
getAttributeText()
should be used only for Dropdown and Multiple Select attributes. I'm pretty sure MSRP is a price type attribute. getAttributeText()
eventually calls getOptionText()
which returns false
for regular attributes.
See Mage_Catalog_Model_Product::getAttributeText()
and Mage_Eav_Model_Entity_Attribute_Source_Abstract::getOptionText()
$prod=Mage::getSingleton('catalog/product')->load($_product->getId()); error_log($prod->getMsrp());
this seems incredibly inefficient though to reload the entire product object, what is the better way to do this?