Display rating above Reviews - php

We are using following code for displaying review & ratings section. I want to display stars above "Title": This is really very good product
<?php $_items = $this->getReviewsCollection()->getItems();?>
<div class="box-collateral box-reviews" id="customer-reviews">
<?php if (count($_items)):?>
<div class="review-heading">
<h2>
<?php echo $this->__('') ?>
<span class="reviewtab">
<?php
// echo count($_items);
?>
Ratings & Reviews
</span>
</h2>
<?php echo $this->getChildHtml('toolbar') ?>
</div>
<dl>
<?php foreach ($_items as $_review):?>
<dt>
<a href="<?php echo $this->getReviewUrl($_review->getId()) ?>">
<?php echo $this->escapeHtml($_review->getTitle()) ?>
</a>
</dt>
<dd>
<?php $_votes = $_review->getRatingVotes(); ?>
<?php echo nl2br($this->escapeHtml($_review->getDetail())) ?>
<?php if (count($_votes)): ?>
<table class="ratings-table">
<colgroup>
<col class="review-label" />
<col class="review-value" />
</colgroup>
<tbody>
<?php foreach ($_votes as $_vote): ?>
<tr>
<th><?php echo $this->escapeHtml($_vote->getRatingCode()) ?></th>
<td>
<div class="rating-box">
<div class="rating" style="width:<?php echo $_vote->getPercent() ?>%;"></div>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
<span class="review-meta">
<?php echo $this->__('Review by %s', $this->escapeHtml($_review->getNickname())) ?>
/
<?php echo $this->__('(Posted on %s)', $this->formatDate($_review->getCreatedAt()), 'long') ?>
</span>
</dd>
<?php endforeach; ?>
</dl>
<?php // echo $this->getChildHtml('toolbar') ?>
<?php elseif($this->getParentBlock()): ?>
<?php echo $this->getParentBlock()->getReviewsSummaryHtml($this->getProduct(), 'short', true)?>
<?php endif;?>
<?php echo $this->getChildHtml('review_form') ?>
</div>
When I tried with css, it didn't work for me.
I tried swapping code, but it didn't work for me either. Am I doing a mistake by swapping?
Please help me to find solution.
Thanks in advance

This should help, you might need to make minor css changes i think.
<?php $_items = $this->getReviewsCollection()->getItems();?>
<div class="box-collateral box-reviews" id="customer-reviews">
<?php if (count($_items)):?>
<div class="review-heading">
<h2>
<?php echo $this->__('') ?>
<span class="reviewtab">
<?php
// echo count($_items);
?>
Ratings & Reviews
</span>
</h2>
<?php echo $this->getChildHtml('toolbar') ?>
</div>
<dl>
<?php foreach ($_items as $_review):?>
<dt>
<?php $_votes = $_review->getRatingVotes(); ?>
<?php if (count($_votes)): ?>
<table class="ratings-table">
<colgroup>
<col class="review-label" />
<col class="review-value" />
</colgroup>
<tbody>
<?php foreach ($_votes as $_vote): ?>
<tr>
<th><?php echo $this->escapeHtml($_vote->getRatingCode()) ?></th>
<td>
<div class="rating-box">
<div class="rating" style="width:<?php echo $_vote->getPercent() ?>%;"></div>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
<a href="<?php echo $this->getReviewUrl($_review->getId()) ?>">
<?php echo $this->escapeHtml($_review->getTitle()) ?>
</a>
</dt>
<dd>
<?php echo nl2br($this->escapeHtml($_review->getDetail())) ?>
<span class="review-meta">
<?php echo $this->__('Review by %s', $this->escapeHtml($_review->getNickname())) ?>
/
<?php echo $this->__('(Posted on %s)', $this->formatDate($_review->getCreatedAt()), 'long') ?>
</span>
</dd>
<?php endforeach; ?>
</dl>
<?php // echo $this->getChildHtml('toolbar') ?>
<?php elseif($this->getParentBlock()): ?>
<?php echo $this->getParentBlock()->getReviewsSummaryHtml($this->getProduct(), 'short', true)?>
<?php endif;?>
<?php echo $this->getChildHtml('review_form') ?>

Related

FatalErrorException: syntax error, unexpected end of file

Dear stackoverflow member PHP developers. Despite all the coding in a project, I am getting the following error persistently. It gives a syntax error on line 102, the last line. I get the error "syntax error, unexpected end of file". I've been trying for 3 days but I couldn't find the error. Thank you very much if you help.
<?php foreach($entrysquizquest as $key => $entry): ?>
<section class="entry quizquestion selectableQuest" id="section_<?php echo e($entry->order); ?>" data-entry="<?php echo e($entry->id); ?>">
<?php if($entry->title): ?>
<h2 class="sub-title" >
<?php echo e($entry->title); ?>
</h2>
<?php endif; ?>
<div class="media">
<div class="sharemedia">
<?php echo $__env->make('._particles.others.entrysharebuttons', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
</div>
<a id="" class="gif-icon-a"><img class="img-responsive" style="display: block;width:100%" alt="<?php echo e($entry->title); ?>" src="<?php echo e(makepreview($entry->image, null, 'entries')); ?>"></a>
<small><?php echo $entry->source; ?></small>
</div>
<p>
<?php echo $entry->body; ?>
</p>
<div class="clear"></div>
<div class="answer" style="margin-left:-15px;">
<?php $sitep = $post->entry()->where('type', 'answer')->where('source', $entry->id)->get(); ?>
<ol class="option-selection <?php if($entry->video == '1'): ?>thdefault <?php else: ?> <?php echo e($entry->video == "2" ? 'thlarge' : 'thlist'); ?><?php endif; ?>">
<?php foreach($sitep as $keya => $answers): ?>
<?php $keya=$keya+1;?>
<li>
<a class="" href="javascript:" data-answer="<?php echo e($answers->id); ?>" data-result="<?php echo e($answers->video); ?>" >
<div class="answer-cover">
<?php if($entry->video!='3'): ?>
<img class="responsive-img" alt="<?php echo e($answers->title); ?>" src="<?php echo e(makepreview($answers->image, null, 'answers')); ?>">
<?php endif; ?>
<h4 class="option-sel" >
<i class="fa fa-square-o answer-check"></i>
<span class="option-text">
<?php echo $answers->title > "" ? $answers->title : '<br>'; ?>
</span>
</h4>
</div>
</a>
<div class="clear"></div>
</li>
<?php if(($keya%3)==0 and $entry->video=='1' or ($keya%2)==0 and $entry->video=='2' ): ?>
</ol><div class="clear"></div> <ol class="option-selection <?php if($entry->video == '1'): ?>thdefault <?php else: ?> <?php echo e($entry->video == "2" ? 'thlarge' : 'thlist'); ?><?php endif; ?>">
<?php endif; ?>
<?php endforeach; ?>
</ol>
</div>
<div class="clear"></div>
</section>
<section class="entry results" id="quiz_result" data-popup="<?php echo e(getcong('BuzzyQuizzesPopup')); ?>">
<div class="quiz_result_area">
<h2 class="post-title"><?php echo e($post->title); ?></h2>
<ol>
<?php foreach($entrysquizresults as $keyp => $entry): ?>
<li class="quiz_result" data-order="<?php echo e($keyp); ?>" data-result="<?php echo e($entry->id); ?>" data-link="<?php echo e(Request::url()); ?>" data-name="<?php echo e(trans('buzzyquiz.yougot', ['title'=> $entry->title])); ?>" data-iname="<?php echo e(trans('buzzyquiz.igot', ['title'=> $entry->title, 'posttitle'=> $post->title])); ?>" data-itname="<?php echo e(trans('buzzyquiz.igotfortweet', ['title'=> $entry->title])); ?>" data-description="<?php echo e(strip_tags($entry->body)); ?>" data-picture="<?php echo e($entry->image > "" ? makepreview($entry->image, null, 'entries') : makepreview($post->thumb, 'b', 'posts')); ?>">
<h2 class="quiz_headline">
<?php echo e(trans('buzzyquiz.yougot', ['title'=> $entry->title])); ?>
</h2>
<div class="clear"></div>
<div class="quiz_text" <?php echo e($entry->image == '' ? 'style=width:100%' :''); ?><?php echo $entry->body; ?></div>
<div class="quiz_img <?php echo e($entry->image == '' ? 'hide' :''); ?>" >
<img class="responsive_img" style=" float: right;" src="data:image/gif;base64,R0lGODlhAQABAPAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==">
</div>
</li>
<?php endforeach; ?>
</ol>
</div>
<div class="clear"></div>
<div class="quiz_result_share">
<h2 class="bold share_title"><?php echo e(trans('buzzyquiz.shareresult')); ?></h2>
<div class="external-sign-in">
<?php echo e(trans('index.sharefacebook')); ?>
<?php echo e(trans('index.sharetweet')); ?>
<?php echo e(trans('index.sharepinterest')); ?>
<?php echo e(trans('index.sharegoogle')); ?>
</div>
<div class="clear"></div>
</div>
</section>
in line 57 add
<?php endforeach; ?>
you forget end foreach
Check for syntax error on a debugger. For instance, you have two > :
<?php echo ($entry->image == '' ? 'style=width:100%' :''); ?>><?php echo

how to change add to cart button to view button in list of products section

I am building an ecommerce website named bookslab.in. I want to change add to cart button to view details button when users see list of products. Whenever i click on all products, then list of products will come with add to cart button i want to change that button to view details button & when users click on this button then they should go on details page of products.
I sending the view.phtml code:
<?php
?>
<?php $_helper = $this->helper('catalog/output'); ?>
<?php $_product = $this->getProduct(); ?>
<script type="text/javascript">
var optionsPrice = new Product.OptionsPrice(<?php echo $this->getJsonConfig() ?>);
</script>
<div id="messages_product_view"><?php echo $this->getMessagesBlock()->toHtml() ?></div>
<div class="product-view">
<div class="product-essential">
<form action="<?php echo $this->getSubmitUrl($_product, array('_secure' => $this->_isSecure())) ?>" method="post" id="product_addtocart_form"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<?php echo $this->getBlockHtml('formkey') ?>
<div class="no-display">
<input type="hidden" name="product" value="<?php echo $_product->getId() ?>" />
<input type="hidden" name="related_product" id="related-products-field" value="" />
</div>
<div class="product-img-box">
<div class="product-name">
<h1><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h1>
</div>
<?php echo $this->getChildHtml('media') ?>
</div>
<div class="product-shop">
<div class="product-name">
<span class="h1"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></span>
</div>
<div class="price-info">
<?php echo $this->getPriceHtml($_product); ?>
<?php echo $this->getChildHtml('bundle_prices') ?>
<?php echo $this->getTierPriceHtml() ?>
</div>
<div class="extra-info">
<?php echo $this->getReviewsSummaryHtml($_product, 'default', false)?>
<?php echo $this->getChildHtml('product_type_availability'); ?>
</div>
<?php echo $this->getChildHtml('alert_urls') ?>
<?php if ($_product->getShortDescription()):?>
<div class="short-description">
<div class="std"><?php echo $_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description') ?></div>
</div>
<?php endif;?>
<?php echo $this->getChildHtml('other');?>
<?php if ($_product->isSaleable() && $this->hasOptions()):?>
<?php echo $this->getChildChildHtml('container1', '', true, true) ?>
<?php endif;?>
</div>
<div class="add-to-cart-wrapper">
<?php echo $this->getChildHtml('product_type_data') ?>
<?php echo $this->getChildHtml('extrahint') ?>
<?php if (!$this->hasOptions()):?>
<div class="add-to-box">
<?php if($_product->isSaleable()): ?>
<?php echo $this->getChildHtml('addtocart') ?>
<?php if( $this->helper('wishlist')->isAllow() || $_compareUrl=$this->helper('catalog/product_compare')->getAddUrl($_product)): ?>
<span class="or"><?php echo $this->__('OR') ?></span>
<?php endif; ?>
<?php endif; ?>
<?php echo $this->getChildHtml('addto') ?>
<?php echo $this->getChildHtml('sharing') ?>
</div>
<?php echo $this->getChildHtml('extra_buttons') ?>
<?php elseif (!$_product->isSaleable()): ?>
<div class="add-to-box">
<?php echo $this->getChildHtml('addto') ?>
<?php echo $this->getChildHtml('sharing') ?>
</div>
<?php endif; ?>
</div>
<?php echo $this->getChildHtml('related_products') ?>
<div class="clearer"></div>
<?php if ($_product->isSaleable() && $this->hasOptions()):?>
<?php echo $this->getChildChildHtml('container2', '', true, true) ?>
<?php endif;?>
</form>
<script type="text/javascript">
//<![CDATA[
var productAddToCartForm = new VarienForm('product_addtocart_form');
productAddToCartForm.submit = function(button, url) {
if (this.validator.validate()) {
var form = this.form;
var oldUrl = form.action;
if (url) {
form.action = url;
}
var e = null;
try {
this.form.submit();
} catch (e) {
}
this.form.action = oldUrl;
if (e) {
throw e;
}
if (button && button != 'undefined') {
button.disabled = true;
}
}
}.bind(productAddToCartForm);
productAddToCartForm.submitLight = function(button, url){
if(this.validator) {
var nv = Validation.methods;
delete Validation.methods['required-entry'];
delete Validation.methods['validate-one-required'];
delete Validation.methods['validate-one-required-by-name'];
// Remove custom datetime validators
for (var methodName in Validation.methods) {
if (methodName.match(/^validate-datetime-.*/i)) {
delete Validation.methods[methodName];
}
}
if (this.validator.validate()) {
if (url) {
this.form.action = url;
}
this.form.submit();
}
Object.extend(Validation.methods, nv);
}
}.bind(productAddToCartForm);
//]]>
</script>
</div>
<div class="product-collateral toggle-content tabs">
<?php if ($detailedInfoGroup = $this->getChildGroup('detailed_info', 'getChildHtml')):?>
<dl id="collateral-tabs" class="collateral-tabs">
<?php foreach ($detailedInfoGroup as $alias => $html):?>
<dt class="tab"><span><?php echo $this->escapeHtml($this->getChildData($alias, 'title')) ?></span></dt>
<dd class="tab-container">
<div class="tab-content"><?php echo $html ?></div>
</dd>
<?php endforeach;?>
</dl>
<?php endif; ?>
</div>
<?php echo $this->getChildHtml('upsell_products') ?>
<?php echo $this->getChildHtml('product_additional_data') ?>
</div>
Ok You posted the view.phtml file. That's detail page of the product. So you're in the product DETAILS page. You want to look the file that is in the same folder
list.phtml
<?php
<?php
/**
* Product list template
*
* #see Mage_Catalog_Block_Product_List
*/
?>
<?php
$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
?>
<?php if(!$_productCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<div class="category-products">
<?php echo $this->getToolbarHtml();?>
<?php // List mode ?>
<?php if($this->getMode()!='grid'): ?>
<?php $_iterator = 0; ?>
<ol class="products-list" id="products-list">
<?php foreach ($_productCollection as $_product): ?>
<li class="item<?php if( ++$_iterator == sizeof($_productCollection) ): ?> last<?php endif; ?>">
<?php // Product Image ?>
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
<?php // Product description ?>
<div class="product-shop">
<div class="f-fix">
<?php $_productNameStripped = $this->stripTags($_product->getName(), null, true); ?>
<h2 class="product-name"><?php echo $_helper->productAttribute($_product, $_product->getName() , 'name'); ?></h2>
<?php if($_product->getRatingSummary()): ?>
<?php echo $this->getReviewsSummaryHtml($_product) ?>
<?php endif; ?>
<?php echo $this->getPriceHtml($_product, true) ?>
<?php if($_product->isSaleable()): ?>
<p><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></p>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
<div class="desc std">
<?php echo $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?>
<?php echo $this->__('Learn More') ?>
</div>
<ul class="add-to-links">
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<li><?php echo $this->__('Add to Wishlist') ?></li>
<?php endif; ?>
<?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
<li><span class="separator">|</span> <?php echo $this->__('Add to Compare') ?></li>
<?php endif; ?>
</ul>
</div>
</div>
</li>
<?php endforeach; ?>
</ol>
<script type="text/javascript">decorateList('products-list', 'none-recursive')</script>
<?php else: ?>
<?php // Grid Mode ?>
<?php $_collectionSize = $_productCollection->count() ?>
<?php $_columnCount = $this->getColumnCount(); ?>
<?php $i=0; foreach ($_productCollection as $_product): ?>
<?php if ($i++%$_columnCount==0): ?>
<ul class="products-grid">
<?php endif ?>
<li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
<h2 class="product-name"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h2>
<?php if($_product->getRatingSummary()): ?>
<?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
<?php endif; ?>
<?php echo $this->getPriceHtml($_product, true) ?>
<div class="actions">
<?php if($_product->isSaleable()): ?>
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
<ul class="add-to-links">
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<li><?php echo $this->__('Add to Wishlist') ?></li>
<?php endif; ?>
<?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
<li><span class="separator">|</span> <?php echo $this->__('Add to Compare') ?></li>
<?php endif; ?>
</ul>
</div>
</li>
<?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
</ul>
<?php endif ?>
<?php endforeach ?>
<script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
<?php endif; ?>
<div class="toolbar-bottom">
<?php echo $this->getToolbarHtml() ?>
</div>
Then look for this element
<ul class="products-grid" >
And within this element find
<div class="actions">
Inside of this div, look for this button
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
now change it to
<button type="button" title="<?php echo $this->__('View Details') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getProductUrl($_product) ?>')"><span><span><?php echo $this->__('View Details') ?></span></span></button>

How to filter related.phtml by in-stock products only in magento

How would one go about filtering magento's related products block to show only in stock products?
<?php foreach($this->getItems() as $_item): ?>
<li class="item">
<?php if(!$_item->isComposite() && $_item->isSaleable()): ?>
<?php if (!$_item->getRequiredOptions()): ?>
<input type="checkbox" class="checkbox related-checkbox" id="related-checkbox<?php echo $_item->getId() ?>" name="related_products[]" value="<?php echo $_item->getId() ?>" />
<?php endif; ?>
<?php endif; ?>
<div class="product">
<img src="<?php echo $this->helper('catalog/image')->init($_item, 'thumbnail')->resize(50) ?>" width="50" height="50" alt="<?php echo $this->htmlEscape($_item->getName()) ?>" />
<div class="product-details">
<p class="product-name"><?php echo $this->htmlEscape($_item->getName()) ?></p>
<?php echo $this->getPriceHtml($_item, true, '-related') ?>
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<?php echo $this->__('Add to Wishlist') ?>
<?php endif; ?>
</div>
</div>
</li>
<?php endforeach ?>
I've uploaded my current iteration of magentos realted.phtml to github:
https://gist.github.com/anonymous/6126772
Wrap the <li> in <?php if ($_item->isSaleable()): ?> . . . <?php endif; ?>.

get product code in featured products module opencart

I want to get product code (module) into featured products module opencart
see this example of what I want
http://demo.pure-sol.com/fahmy/test.jpg
I did some code but there something wrong with the result
\catalog\controller\module\featured.php
$this->data['text_model'] = $this->language->get('text_model'); // line 10
$this->data['model'] = $product_info['model']; // line 54
catalog\language\english\module\featured.php
$_['text_model'] = 'Model';
catalog\view\theme\fashionfever\template\module\featured.tpl
<div class="feature">
<h2> <?php echo $heading_title; ?></h2>
<div class="box-content">
<div class="box-product">
<?php foreach ($products as $product) { ?>
<div>
<?php if ($product['thumb']) { ?>
<div class="image"><img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" /></div>
<?php } ?>
<div class="name"><?php echo $product['name']; ?></div>
<?php if ($product['price']) { ?>
<div class="price">
<?php if (!$product['special']) { ?>
<?php echo $product['price']; ?>
<?php } else { ?>
<span class="price-old"><?php echo $product['price']; ?></span> <span class="price-new"><?php echo $product['special']; ?></span>
<?php } ?>
</div>
<?php } ?>
<?php if ($product['rating']) { ?>
<div class="rating"><img src="catalog/view/theme/default/image/stars-<?php echo $product['rating']; ?>.png" alt="<?php echo $product['reviews']; ?>" /></div>
<?php } ?>
<div class="cart"><input type="button" value="<?php echo $button_cart; ?>" onclick="addToCart('<?php echo $product['product_id']; ?>');" class="button" /></div>
</div>
<!-- additional code -->
<p><?php echo $text_model; ?>: <?php echo $model; ?></p>
<?php } ?>
</div>
</div>
</div>
remove the line
$this->data['model'] = $product_info['model']; // line 54
and in $this->data['products'][] = array(
add this line
'model' => $product_info['model'],
add this
<p><?php echo $text_model; ?>: <?php echo $product['model']; ?></p>
just after
<div class="cart"><input type="button" value="<?php echo $button_cart; ?>" onclick="addToCart('<?php echo $product['product_id']; ?>');" class="button" /></div>

How to list 4 random products from a categoy in Magento

The question is pretty simple, the code below shows the items in one category. Those categories have 4 products.
However my plan is to put in those categories 20 products, and make the following code to choose randomly 4 products of those categories.
I suppose the only line I need to change is this:
$_productCollection=$this->getLoadedProductCollection();
<?php
/**
* Product list template
*
* #see Mage_Catalog_Block_Product_List
*/
?>
<?php
$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
?>
<?php if(!$_productCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<div class="category-products">
<?php // List mode ?>
<?php $_iterator = 0; ?>
<script type="text/javascript">decorateList('products-list', 'none-recursive')</script>
<?php // Grid Mode ?>
<?php $_collectionSize = $_productCollection->count() ?>
<?php $_columnCount = $this->getColumnCount(); $_columnCount=4; ?>
<?php $i=0; foreach ($_productCollection as $_product): ?>
<?php if ($i++%$_columnCount==0): ?>
<ul class="products-grid">
<?php endif ?>
<li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(170); ?>" width="170" height="170" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
<h2 class="product-name"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h2>
<?php if($_product->getRatingSummary()): ?>
<?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
<?php endif; ?>
<div class="actions">
<div style="clear:both;"></div>
<div>
<?php $Deal = $_product->getResource()->getAttribute('deal')->getFrontend()->getValue($_product);?>
<?php $onSale = $_product->getResource()->getAttribute('on_sale')->getFrontend()->getValue($_product);?>
<?php $hotItem = $_product->getResource()->getAttribute('hot_item')->getFrontend()->getValue($_product);?>
<?php $freeShip = $_product->getResource()->getAttribute('free_shipping')->getFrontend()->getValue($_product);?>
<?php if($Deal == 'Yes'){ ?>
<img width="91px" height="21px" alt="Deal" title="Deal" src="<?php echo $this->getSkinUrl('images/icon-deal.gif') ?>" oncontextmenu="return false" >
<?php } ?>
<?php if($onSale == 'Yes'){ ?>
<img width="91px" height="21px" alt="On Sale" title="On Sale" src="<?php echo $this->getSkinUrl('images/icon-sale.gif') ?>" oncontextmenu="return false" >
<?php } ?>
<?php if($hotItem == 'Yes'){ ?>
<img width="91px" height="21px" alt="Hot Item" title="Hot Item" src="<?php echo $this->getSkinUrl('images/icon-hot.gif') ?>" oncontextmenu="return false" >
<?php } ?>
<?php if($freeShip == 'Yes'){ ?>
<img alt="Free Shipping" width="91px" height="21px" title="Free Shipping" src="<?php echo $this->getSkinUrl('images/icon-freeship.gif') ?>" oncontextmenu="return false" >
<?php }?>
</div>
</div>
<?php echo $this->getPriceHtml($_product, true) ?>
<div class="actions">
<?php if($_product->isSaleable()): ?>
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
<?php /*?><ul class="add-to-links">
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<li><?php echo $this->__('Add to Wishlist') ?></li>
<?php endif; ?>
<?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
<li><span class="separator">|</span> <?php echo $this->__('Add to Compare') ?></li>
<?php endif; ?>
</ul><?php */?>
</div>
</li>
<?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
</ul>
<?php endif ?>
<?php endforeach ?>
<script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
</div>
<?php endif; ?>
Try this:
<?php
// $_productCollection = $this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
$_category = Mage::getModel('catalog/category')->load($this->getCategoryId());
$_productCollection = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('*')
->addCategoryFilter($_category)
->setVisibility(array(2,3,4));
$_productCollection->getSelect()->order(new Zend_Db_Expr('RAND()'));
$_productCollection->setPage(1, 4);
?>

Categories