Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>By default, when you load a product collection you'll get a bare amount of information about the products. Ex:</p> <pre><code>Array ( [entity_id] =&gt; 9 [entity_type_id] =&gt; 4 [attribute_set_id] =&gt; 4 [type_id] =&gt; simple [sku] =&gt; DLKJFER343 [has_options] =&gt; 0 [required_options] =&gt; 0 [created_at] =&gt; 2012-12-07 16:04:58 [updated_at] =&gt; 2012-12-11 16:21:37 [cat_index_position] =&gt; 0 [stock_item (Varien_Object)] =&gt; Array ( ) ) </code></pre> <p>You need to explicitly tell Magento to load extra information or to filter by a value like this:</p> <pre><code>$_productCollection = Mage::getResourceModel( 'catalog/product_collection' ); // Filter by enabled products $_productCollection-&gt;addAttributeToFilter( 'status', 1 ); // Load all product information $_productCollection-&gt;addAttributeToSelect( '*' ); $_productCollection-&gt;addCategoryFilter( $category ); </code></pre> <p>Now you'll see something like this (using <code>$_product-&gt;debug()</code> to dump out some information):</p> <pre><code>Array ( [entity_id] =&gt; 3 [entity_type_id] =&gt; 4 [attribute_set_id] =&gt; 4 [type_id] =&gt; simple [sku] =&gt; DLKJFER343 [has_options] =&gt; 0 [required_options] =&gt; 0 [created_at] =&gt; 2012-12-05 18:47:39 [updated_at] =&gt; 2012-12-11 16:20:25 [cat_index_position] =&gt; 0 [status] =&gt; 1 [visibility] =&gt; 4 [enable_googlecheckout] =&gt; 1 [tax_class_id] =&gt; 2 [is_recurring] =&gt; 0 [weight] =&gt; 3.0000 [price] =&gt; 534.2500 [name] =&gt; Sample Product [url_key] =&gt; some-product [is_returnable] =&gt; 2 [msrp_enabled] =&gt; 2 [msrp_display_actual_price_type] =&gt; 4 [image] =&gt; /w/r/something.png [small_image] =&gt; /w/r/something_sm.png [thumbnail] =&gt; /w/r/something_th.png [options_container] =&gt; container2 [url_path] =&gt; some-product.html [image_label] =&gt; One image label [small_image_label] =&gt; Another image label [thumbnail_label] =&gt; An image label [description] =&gt; Long winded blah, blah, blah. [short_description] =&gt; Blah, blah, blah. [stock_item (Varien_Object)] =&gt; Array ( ) ) </code></pre> <p>The media gallery information (labels, etc) is a different beast and must be specifically requested through the <code>getMediaGalleryImages()</code> method of the <code>Mage_Catalog_Model_Product</code> object.</p> <p><strong>HOWEVER</strong> this method will return <code>NULL</code> if called while looping through a product collection. Oddly, you cannot access this data without explicitly loading the product model (for reasons I won't go into in this response). So, we need to try something like this:</p> <pre><code>$product = Mage::getModel( 'catalog/product' )-&gt;load( $_product-&gt;getId() ); $images = $product-&gt;getMediaGalleryImages(); </code></pre> <p>There's <a href="http://www.magentocommerce.com/boards/viewthread/29639/" rel="nofollow noreferrer">a performance hit</a> doing this in your collection loop though, so be careful.</p> <hr> <p>EDIT:</p> <p>Mage_Catalog_Block_Product->getLoadedProductCollection()</p> <p>Long, long, <strong>long</strong> story short (this method digs deep)... as far as I can tell <code>getLoadedProductCollection()</code> will only show attributes which have <code>Used In Product Listing</code> set to <code>Yes</code>.</p> <p><img src="https://i.stack.imgur.com/w880U.png" alt="enter image description here"></p> <p>The reason resides in Mage_Catalog_Model_Resource_Config...</p> <pre><code>public function getAttributesUsedInListing() { // ... some code above omitted... -&gt;where('main_table.entity_type_id = ?', (int)$this-&gt;getEntityTypeId()) // THIS RIGHT HERE IS WHY -&gt;where('additional_table.used_in_product_listing = ?', 1); return $adapter-&gt;fetchAll($select); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload