Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I found a way to get my desired result.</p> <p>Apparently my attribute wasn't loaded in my collection so I re-wrote my code and got things done my own way.</p> <p>My task was to create an attribute "Feature in Category?" so products with a "Yes" would appear prior to the category listing. The field Contrast Ratio was being used as an example.</p> <p>I'm willing to share this, so here's my code...</p> <p>Thanks all for your help you led me into the right direction :))</p> <pre><code>&lt;?php Mage::getSingleton('catalog/layer')-&gt;setData("product_collection",NULL); $this-&gt;_productCollection = null; $_productCollection=$this-&gt;getLoadedProductCollection(); $currentCategory = Mage::registry('current_category'); $_products = Mage::getModel('catalog/product') -&gt;getCollection() -&gt;addAttributeToSelect(array('name','short_description','product_url','small_image')) -&gt;addAttributeToFilter('seen_first', array('like' =&gt; '%1%')) -&gt;addCategoryFilter($currentCategory) -&gt;load(); $_collectionSize = sizeof($_products); ?&gt; &lt;?php if(!sizeof($_products)): ?&gt; &lt;!--&lt;div class="padder"&gt; &lt;div class="note-msg"&gt; &lt;?php echo $this-&gt;__('There are no products matching the selection.') ?&gt; &lt;/div&gt; &lt;/div&gt;--&gt; &lt;?php else: ?&gt; &lt;?php // Grid Mode ?&gt; &lt;div class="listing-type-grid catalog-listing padder"&gt; &lt;!-- the class name will change to .listing-type-cell if viewing in list mode --&gt; &lt;?php $_items = $_productCollection-&gt;getItems(); shuffle($_items); ?&gt; &lt;div class="price_omg_random_products_container"&gt; &lt;table class="price_omg_random_products" cellspacing="0" class="generic-product-grid" id="product-list-table"&gt; &lt;?php $i=0; foreach ($_products as $_product): ?&gt; &lt;?php if ($i++%4==0): ?&gt; &lt;tr&gt; &lt;?php endif ?&gt; &lt;td&gt; &lt;p class="product-image"&gt; &lt;a href="&lt;?php echo $_product-&gt;getProductUrl() ?&gt;" title="&lt;?php echo $this-&gt;htmlEscape($_product-&gt;getName()) ?&gt;"&gt; &lt;img src="&lt;?php echo $this-&gt;helper('catalog/image')-&gt;init($_product, 'small_image')-&gt;resize(110, 110); ?&gt;" alt="&lt;?php echo $this-&gt;htmlEscape($_product-&gt;getName()) ?&gt;"/&gt; &lt;/a&gt; &lt;/p&gt; &lt;h5&gt;&lt;a href="&lt;?php echo $_product-&gt;getProductUrl() ?&gt;" title="&lt;?php echo $this-&gt;htmlEscape($_product-&gt;getName()) ?&gt;"&gt;&lt;?php echo '&lt;span class="price_omg_random_products_title"&gt;'.$this-&gt;htmlEscape($_product-&gt;getName()).'&lt;/span&gt;' ?&gt;&lt;/a&gt;&lt;/h5&gt; &lt;?php if($_product-&gt;getRatingSummary()): ?&gt; &lt;!--?php echo $this-&gt;getReviewsSummaryHtml($_product, 'short') ?--&gt; &lt;?php echo $this-&gt;getReviewsSummaryHtml($_product) ?&gt; &lt;?php endif; ?&gt; &lt;?php ?&gt; &lt;div class="clear"&gt;&lt;/div&gt; &lt;ul class="add-to"&gt; &lt;?php echo nl2br($_product-&gt;getShortDescription()); if($_additional = $_product-&gt;getAdditionalData()): ?&gt; &lt;h2&gt;&lt;?php echo $this-&gt;__('Additional Information') ?&gt;&lt;/h2&gt; &lt;table class="data-table" id="product-attribute-specs-table"&gt; &lt;col width="25%" /&gt; &lt;col /&gt; &lt;tbody&gt; &lt;?php foreach ($_additional as $_data): ?&gt; &lt;tr&gt; &lt;th class="label"&gt;&lt;?php echo $this-&gt;htmlEscape($this-&gt;__($_data['label'])) ?&gt;&lt;/th&gt; &lt;td class="data"&gt;&lt;?php echo $_helper-&gt;productAttribute($_product, $_data['value'], $_data['code']) ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php endforeach; ?&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;script type="text/javascript"&gt;decorateTable('product-attribute-specs-table')&lt;/script&gt; &lt;?php endif;?&gt; &lt;? if($_product-&gt;isSaleable()): ?&gt; &lt;li class="add-to-cart-textlink"&gt; &lt;p&gt; &lt;?php echo '&lt;span class="price_omg_random_products_price" &gt;&amp;euro;'.number_format($_product-&gt;getPrice(), 2, '.', '').'&lt;/span&gt;'; ?&gt; &lt;!--&lt;button type="button" title="&lt;?php echo $this-&gt;__('Info') ?&gt;" class="button" onclick="setLocation('&lt;?php echo $_product-&gt;getProductUrl() ?&gt;')"&gt;&lt;span&gt;&lt;span class="button_info"&gt;&lt;?php echo $this-&gt;__('Info') ?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;--&gt; &lt;button type="button" title="&lt;?php echo $this-&gt;__('Add to Cart') ?&gt;" class="button" onclick="setLocation('&lt;?php echo $this-&gt;getAddToCartUrl($_product) ?&gt;')"&gt;&lt;span&gt;&lt;span&gt;&lt;?php echo $this-&gt;__('Add to Cart') ?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/button&gt; &lt;/p&gt; &lt;!--&lt;a href="#" onclick="setLocation('&lt;?php echo $this-&gt;getAddToCartUrl($_product) ?&gt;')"&gt;&lt;span&gt;Add to Cart&lt;/span&gt;&lt;/a&gt;--&gt; &lt;/li&gt; &lt;?php else: ?&gt; &lt;li&gt;&lt;?php echo $this-&gt;__('Out of stock') ?&gt;&lt;/li&gt; &lt;?php endif; ?&gt; &lt;?php if ($i==4) break; // show 4 products max ?&gt; &lt;?php endforeach ?&gt; &lt;?php for($i;$i%4!=0;$i++): ?&gt; &lt;td class="empty-product"&gt;&amp;nbsp;&lt;/td&gt; &lt;?php endfor ?&gt; &lt;?php if ($i%4==0): ?&gt; &lt;/tr&gt; &lt;?php endif ?&gt; &lt;/table&gt; &lt;/div&gt; &lt;script type="text/javascript"&gt;decorateTable('product-list-table')&lt;/script&gt; &lt;/div&gt; &lt;?php endif; ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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