I have a product attribute called remote_image_link. When I retrieve a product using this code:
$mageProduct = Mage::getModel('catalog/product')
->getCollection()
->addFieldToFilter('sku',"1234")->getFirstItem();
And then try and get the value of the attribute RemoteImageLink,
$mageProduct->getRemoteImageLink()
Nothing is returned. But when I add this code:
$mageProduct = Mage::getModel('catalog/product')->load($mageProduct->getId());
Then it works and I can get a value for the remote_image attribute.
How come I have to call load, aren't I loading using the addFieldToFileter
Best Answer
First of all use
addAttributeToFilter
instead ofaddFieldToFilter
. It's cleaner that way.And retrieve your product like this:
When getting a collection not all attributes are added to the collection. You need to add manually the attributes you need.
If for some reason that doesn't work, set the attribute
remote_image_link
to beUsed in product listing
.