Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here the code you were looking for, sorry for the delay :)</p> <p>It come from this discussion: <a href="http://www.magentocommerce.com/boards/viewthread/17414/" rel="nofollow">http://www.magentocommerce.com/boards/viewthread/17414/</a></p> <p>I just added some extra check on the number of id a and pagination</p> <pre><code>function addMediaGalleryAttributeToCollection(Mage_Catalog_Model_Resource_Product_Collection $_productCollection) { if (Mage::getStoreConfig('color_selector_plus/colorselectorplusgeneral/showonlist', Mage::app()-&gt;getStore())) { $_mediaGalleryAttributeId = Mage::getSingleton('eav/config')-&gt;getAttribute('catalog_product', 'media_gallery')-&gt;getAttributeId(); $_read = Mage::getSingleton('core/resource')-&gt;getConnection('catalog_read'); $pageCur = $_productCollection-&gt;getCurPage(); $pageSize = $_productCollection-&gt;getPageSize(); $offset = $pageSize * ($pageCur - 1); $ids = $_productCollection-&gt;getAllIds($pageSize, $offset); // added check on products number: if 0 ids the following query breaks if (count($ids) &gt; 0) { $sql = ' SELECT main.entity_id, `main`.`value_id`, `main`.`value` AS `file`, `value`.`disabled`, /*`value`.`label`, `value`.`position`, */ /*`default_value`.`label` AS `label_default`, */ /*`default_value`.`position` AS `position_default`, */ `default_value`.`disabled` AS `disabled_default` FROM `catalog_product_entity_media_gallery` AS `main` LEFT JOIN `catalog_product_entity_media_gallery_value` AS `value` ON main.value_id=value.value_id AND value.store_id=' . Mage::app()-&gt;getStore()-&gt;getId() . ' LEFT JOIN `catalog_product_entity_media_gallery_value` AS `default_value` ON main.value_id=default_value.value_id AND default_value.store_id=0 WHERE ( main.attribute_id = ' . $_read-&gt;quote($_mediaGalleryAttributeId) . ') AND (main.entity_id IN (' . $_read-&gt;quote($_productCollection-&gt;getAllIds()) . ')) /*ORDER BY IF(value.position IS NULL, default_value.position, value.position) ASC */ '; $_mediaGalleryData = $_read-&gt;fetchAll($sql); $_mediaGalleryByProductId = array(); foreach ($_mediaGalleryData as $_galleryImage) { $k = $_galleryImage['entity_id']; unset($_galleryImage['entity_id']); if (!isset($_mediaGalleryByProductId[$k])) { $_mediaGalleryByProductId[$k] = array(); } $_mediaGalleryByProductId[$k][] = $_galleryImage; } unset($_mediaGalleryData); foreach ($_productCollection as &amp;$_product) { $_productId = $_product-&gt;getData('entity_id'); if (isset($_mediaGalleryByProductId[$_productId])) { $_product-&gt;setData('media_gallery', array('images' =&gt; $_mediaGalleryByProductId[$_productId])); } } unset($_mediaGalleryByProductId); } } return $_productCollection; } </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