views:

39

answers:

2

So we were trying to load a product through a collection with certain criteria, we didn't have the sku or the id so when we did the following

 $prodModel->getCollection()
        ->addAttributeToFilter('visibility', $visibility)
        ->addAttributeToSelect('*')
        ->addCategoryFilter($cat)
        ->addAttributeToFilter('attribute_1', $sattribute_1)
        ->addAttributeToFilter('attribute_2', $attribute_2)
        ->addAttributeToFilter('type_id', 'configurable')
        ->load()
        ->getFirstItem()

When doing this we got the product we wanted but for some reason it didn't have all of the attributes, even though we specified "*" for all attributes. Specifically the one we were not getting was the media gallery attribute. What we ended up doing is saying getFirstItem()->getId() then loaded the product and it worked find.

I just don't understand whey loading the product with the catalog product model would have more attributes.

+2  A: 

After the above code did you try doing this?

$prodModel->loadAllAttributes();
clockworkgeek
No I didn't but I will see about that now.
dan.codes
A: 

I understand you actually asked how to get all of the attributes but I notice you also mention the media gallery attribute specifically. There happens to be a shortcut for getting the product image's final URL.

(string)Mage::helper('catalog/image')->init($product, 'media_gallery');

Casting to a string calls __toString which performs the cleverness. You can also apply resizing, rotation, watermarks, etc. immediately after initialising.

clockworkgeek