I've been trying to pull one single customer review onto the product page.
I've no code to show as honestly i'm not sure where to start and can't find any mention of it online.
Anyone have any ideas?
I wrote a tutorial earlier on bringing all the review elements onto the product page, so you could follow this tutorial: http://www.e-commercewebdesign.co.uk/blog/magento-tutorials/product-reviews-on-product-view-page.php
All you'd have to do is rename the list block and bring it out in the same way. Then simply modify the loop which brings out the reviews in any way you see fit. E.g. limit to a certain number or only echo out review from a certain user.
EDIT:
To get the latest review is quite simple because the reviews are in date order anyway.
Go to review > product > list.phtml
Replace the code in that file with this:
<?php $_items = $this->getReviewsCollection()->getItems();?>
<div class="box-collateral box-reviews" id="customer-reviews">
<?php if (count($_items)):?>
<h2><?php echo $this->__('Customer Reviews') ?></h2>
<?php echo $this->getChildHtml('toolbar') ?>
<dl>
<?php $r_count = 0; ?>
<?php foreach ($_items as $_review):?>
<?php if ($r_count == 0) { ?>
<dt>
<?php echo $this->htmlEscape($_review->getTitle()) ?> <?php echo $this->__('Review by <span>%s</span>', $this->htmlEscape($_review->getNickname())) ?>
</dt>
<dd>
<?php $_votes = $_review->getRatingVotes(); ?>
<?php if (count($_votes)): ?>
<table class="ratings-table">
<col width="1" />
<col />
<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; ?>
<?php echo nl2br($this->htmlEscape($_review->getDetail())) ?>
<small class="date"><?php echo $this->__('(Posted on %s)', $this->formatDate($_review->getCreatedAt()), 'long') ?></small>
</dd>
<?php } ?>
<?php $r_count++; ?>
<?php endforeach; ?>
</dl>
<?php echo $this->getChildHtml('toolbar') ?>
<?php endif;?>
<?php echo $this->getChildHtml('review_form') ?>
</div>
I've simple put an interator into the loop $r_count and put a check inside the foreach which prevent it from progressing on the next loop iteration.
Related
Hey guys ok so i'm wokring on a clients Weekly Newsletter i'm working with Joomla 2.5.19 and using the enterprise version of acymailling to send it out. I'm kicking my heading in at the moment because of outlook, i'm using a module from Jreviews that publishes the latest reviews submitted to the site in the newsletter, it all works fine except in outlook.
the out put of the script is meant to be a 2x2table with the 4 latest reviews in it. the only prob is outlook seems to hates me using Div for a table and stacks the 2x2 table into a verticle kaotic mess.
the code i'm trying to edit is:
'>
<?php /* root element for the items */ ?>
<div class="jrModuleItems <?php echo $orientation . ' jrThumbnail'.ucfirst($tn_position); ?>">
<?php /* new page starts here */
$pages = array_chunk($reviews,$limit);
$j=0;
foreach($pages AS $page):
?>
<div class="jr-results jrResults jrModuleContainer jrReviewsModule">
<?php $i=0;
while(!empty($page)):
$i++; $j++; $review = array_shift($page); ?>
<?php
// Process link title
$listing_title = ($listing_title_chars && mb_strlen($review['Listing']['title'])>$listing_title_chars) ? $Text->truncate($review['Listing']['title'],$listing_title_chars) : $review['Listing']['title'];
$review_title = ($review_title_chars && mb_strlen($review['Review']['title'])>$review_title_chars) ? $Text->truncate($review['Review']['title'],$review_title_chars) : $review['Review']['title'];
$link_title = str_replace('{listing_title}',$listing_title,$link_title_format);
$link_title = str_replace('{review_title}',$review_title,$link_title);
// Create the thumbnail
$tn_show and $mainMediaThumb = $Media->thumb(Sanitize::getVar($review,'MainMedia'),array('listing'=>$review,'size'=>$tn_size,'mode'=>$tn_mode,'css_size'=>true));
?>
<?php $lastItem = ($i == $columns) ? ' jrLastItem' : ''; ?>
<div class="jrModuleItem<?php echo $lastItem; ?>" style="width: <?php echo $item_width; ?>%; padding-right: <?php echo $item_padding; ?>%;">
<?php if($show_numbers):?><div class="jrModuleItemNumber"><?php echo $j;?>.</div><?php endif;?>
<?php if($tn_show && $mainMediaThumb && $tn_position != 'bottom'):?>
<!-- Listing Thumbnail -->
<div class="jrModuleItemThumbnail">
<?php echo $Html->sefLink($mainMediaThumb,$review['Listing']['url']);?>
<?php // Uncomment line below to show reviewer avatar. You can comment or remove the thumbnail code above
// echo $Community->avatar($review);
?>
</div>
<?php endif;?>
<div class="jrModuleItemContent">
<!-- Listing Title -->
<div class="jrModuleItemTitle">
<?php echo $Html->sefLink($link_title,$review['Listing']['url']);?>
<?php if(Sanitize::getString($review['Listing'],'tag')):?>
<span class="jrComponentLabel jrStatusLabel jrBlue">
<?php echo Sanitize::getString($review['Listing'],'tag');?>
</span>
<?php endif;?>
</div>
<!-- Rating -->
<?php if ( $review['Criteria']['state'] == 1 ):?>
<div class="jrOverallRatings">
<?php if($review['Review']['editor'] == 1):?>
<?php
$rating_stars = $Rating->drawStars($review['Rating']['average_rating'], $this->Config->rating_scale, 'editor');
$rating_value = $Rating->round($review['Rating']['average_rating'],$this->Config->rating_scale);
?>
<div class="jrOverallEditor" title="<?php __t("Editor rating"); ?>">
<div class="jrRatingStars"><?php echo $rating_stars ?></div>
<span class="jrRatingValue"><?php echo $rating_value?></span>
</div>
<?php else:?>
<?php
$rating_stars = $Rating->drawStars($review['Rating']['average_rating'], $this->Config->rating_scale, 'user');
$rating_value = $Rating->round($review['Rating']['average_rating'],$this->Config->rating_scale);
?>
<div class="jrOverallUser" title="<?php __t("User rating"); ?>">
<div class="jrRatingStars"><?php echo $rating_stars ?></div>
<span class="jrRatingValue"><?php echo $rating_value?></span>
</div>
<?php endif;?>
</div>
<?php endif;?>
<!-- Reviewer name -->
<div class="jrModuleItemReviewer">
<span class="reviewer"><?php __t("Reviewed by");?> <?php echo $Community->screenName($review);?></span>
</div>
<?php if($fields): ?>
<!-- Custom Fields -->
<div class="jrModuleFields">
<?php
foreach ($fields as $field):
$field = trim($field);
$field_value = $CustomFields->field($field,$review);
?>
<?php if($field_value != ''):?>
<div class="jrModuleFieldDiv <?php echo lcfirst(Inflector::camelize($field)); ?>">
<span class="jrModuleFieldTitle"><?php echo $CustomFields->label($field, $review); ?>: </span>
<span class="jrModuleFieldValue"><?php echo $field_value; ?></span>
</div>
<?php endif;?>
<?php endforeach; ?>
</div>
<?php endif;?>
<?php if($show_comments && trim($review['Review']['comments'])!=''):?>
<!-- Review Comments -->
<div class="jrModuleItemInfo">
<?php
// Uncomment line below to show review title
// echo '<strong>' . $review['Review']['title'] . '</strong><br />';
?>
<span class="comments">"<?php echo $Text->truncateWords($review['Review']['comments'],$comments_words,'...');?>"</span>
</div>
<?php endif;?>
</div>
<?php if($tn_show && $mainMediaThumb && $tn_position == 'bottom'):?>
<!-- Listing Thumbnail -->
<div class="jrModuleItemThumbnail">
<?php echo $Html->sefLink($mainMediaThumb,$review['Listing']['url']);?>
<?php // Uncomment line below to show reviewer avatar. You can comment or remove the thumbnail code above
// echo $Community->avatar($review);
?>
</div>
<?php endif;?>
</div>
<?php /*end of row , start new row*/
if(!empty($page) && ($i == $columns || $total == $j)):?>
<div class="jrDivider"></div>
<?php $i=0; endif;?>
<?php endwhile;?>
</div>
<?php endforeach; /* new page ends here */?>
</div><?php /* end items root element */?>
Does any one have the slightest idea how i could turn this into a for loop that outputs a table?
The quickest path from A to B is to edit the attached code to render a table versus stacked divs.
* EDIT *
The answer to your comment isn't so simple as replace all of 'A' with 'B.' A div is a "self-contained" HTML element while a table is a grouping with syntax rules.
An HTML table is constructed like so:
<table>
<thead>
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Row 1 - Column 1</td>
<td>Row 1 - Column 2</td>
</tr>
<tr>
<td>Row 2 - Column 1</td>
<td>Row 2 - Column 2</td>
</tr>
</tbody>
</table>
The foreach loop in your code should create a row through each iteration. Which means you need to render your table, thead and tbody tags outside of this looping code. Inside the loop, you render a new row each iteration, which requires an opening/closing tag for the row and an opening/closing for each column.
Hope this helps.
I'm a newbie in web development, and i want to modify an existing project.I want to display rows including a null value,a default value of zero or the empty one.This is the code in action..
public function executeDetails(sfWebRequest $r) {
if($this->getUser()->hasAttribute('extend_term_ch')) {
$this->getUser()->getAttributeHolder()->remove('extend_term_ch');
}
$this->loan = Doctrine_Core::getTable('Loans')->findOneById($r->getParameter('id'));
$this->debits = Doctrine_Core::getTable('CreditLogs')->getByLoanId($r->getParameter('id'));
}
and in templates
<?php $totalAmount = 0 ?>
<?php foreach($loan->Collections as $i=>$c): ?>
<?php $totalAmount += $c->amount ?>
<tr class="<?php echo ($i%2==0)?'even':'odd' ?>">
<td>
<?php echo $c->mode_of_payment ?>
<?php if($c->mode_of_payment == 'Cheque'): ?>
<?php $cReferencedObj = $c->Cheques ?>
<div class="small_detail info">
<span class="bold">(<?php echo $cReferencedObj->bank ?>, <?php echo $cReferencedObj->branch ?>) <?php echo $cReferencedObj->reference_number ?></span>
</div><br />
<?php endif; ?>
<?php $replaced = $c->getReplacedCheque() ?>
<?php if(!empty($replaced)): ?>
<div class="small_detail info">
Payment for <span class="bold">(<?php echo $replaced->bank ?>, <?php echo $replaced->branch ?>) <?php echo $replaced->reference_number ?></span>
</div><br />
<?php endif; ?>
</td>
<td><?php echo $c->batch_no ?></td>
<td>
PHP <?php echo number_format($c->amount, 2) ?>
<?php if($c->mode_of_payment == 'Cheque' && !empty($c->Cheques->replaced_with)): ?>
<?php $replaced = $c->Cheques->Replaced ?>
<div class="small_detail info">
Replaced with <span class="bold">(<?php echo $replaced->bank ?>, <?php echo $replaced->branch ?>) <?php echo $replaced->reference_number ?></span>
</div>
<?php endif; ?>
</td>
<td><?php echo date('F d, Y', strtotime($c->date_created)) ?></td>
<td><?php echo $c->created_by ?></td>
<td><?php echo $c->date_created ?></td>
<td>
<?php if(in_array($c->mode_of_payment, array('Cheque', 'ATM', 'Direct Bank Transfer'))): ?>
<span class="info">
View Details
</span>
<?php else: ?>
<div class="small_detail info">
Collector: <span class="bold"><?php echo $c->Collectors->lastname.', '.$c->Collectors->firstname ?></span>
</div>
<?php endif; ?>
<?php if(in_array($loan->mode_of_payment, array('Cash', 'ATM')) && $sf_user->hasCredential('COLLECTIONS_ROLLBACK')): ?>
<div class="small_detail bullet_go">
Rollback Collection
</div>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
<tr>
<td colspan="6">Total Paid</td>
<td>PHP <?php echo number_format($totalAmount, 2) ?></td>
</tr>
This will only display rows with data..how about displaying the empty row?For example a person has to pay his debts in 40 days from April 1, 2014 up to March 10,2014, then for some reason, he did not pay April 4, 6, 8 and so on.I want to display those dates 4, and 6 and 8 and display some errors for every date he failed to pay it like "No payment for this date".
I am using onestepcheckout in Magento. I have added in some extra flat rates and I am using two of them. I want to be able to only show one of the flat rates depending on the subtotal of the cart.
I have got the subtotal into a variable but the code has a foreach through each shipping method available so I need a way to say if $total is over 500 only show the second shipping method, if the total is under 500 only show the first shipping method.
<?php $total = Mage::getSingleton('checkout/session')->getQuote()->getSubtotal(); ?>
<?php foreach ($_shippingRateGroups as $code => $_rates): ?>
<dd><?php echo $this->getCarrierName($code) ?></dd>
<?php foreach ($_rates as $_rate): ?>
<dt style="margin-bottom: 5px;">
<?php if ($_rate->getErrorMessage()): ?>
<ul class="messages"><li class="error-msg"><ul><li><?php echo $_rate->getErrorMessage() ?></li></ul></li></ul>
<?php else: ?>
<input name="shipping_method" type="radio" class="validate-one-required-by-name" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> />
<label for="s_method_<?php echo $_rate->getCode() ?>"><!--<b><?php echo $this->getCarrierName($code) ?>:</b>--> <?php echo $_rate->getMethodTitle() ?>
<strong>
<?php $_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax()); ?>
<?php $_incl = $this->getShippingPrice($_rate->getPrice(), true); ?>
<?php echo $_excl; ?>
<?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
(<?php echo $this->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
<?php endif; ?>
</strong>
</label>
<?php endif ?>
</dt>
<?php endforeach; ?>
<?php endforeach; ?>
Just do ...
//first method here by default
if($total>500){
//second method here
}
Something tells me you already know how to do this though
I can't decipher, what the first and second method are in your code, otherwise I would've posted a more complete code
So i have figured out how to display product reviews on a product page. Now I need to understand how to limit the number of review that display and add a "read more reviews" link to the product reviews default page.
Any ideas? Or Can anyone point me in the right direction? I have tried a number of different scripts with no luck.
UPDATE: I tried making the changes below but its still not working - any ideas on what i'm doing wrong?
Yeah thats what I thought, but its still not working, any ideas what i'm doing wrong??
<?php $_items = $this->getReviewsCollection()->setPageSize('5')->getItems();?>
<div class="box-collateral box-reviews" id="customer-reviews">
<?php if (count($_items)):?>
<div class="box-title">
<h2><?php echo $this->__('Customer<br><span id="smallH2">Reviews</span>') ?></h2>
</div>
<?php echo $this->getChildHtml('toolbar') ?>
<dl class="box-content" id="product-reviews-list">
<?php foreach ($_items as $_review):?>
<dt>
<?php
$reviewURL = $this->getReviewUrl($_review->getId());
$reviewURL = str_replace("catalog","review",$reviewURL);
?>
<?php echo $this->htmlEscape($_review->getTitle()) ?> <?php echo $this->__('Review by <span>%s</span>', $this->htmlEscape($_review->getNickname())) ?>
</dt>
<dd>
<table class="data-table review-summary-table">
<col />
<col />
<tbody>
<?php foreach ($_review->getRatingVotes() as $_vote): ?>
<tr>
<th class="label"><?php echo $this->escapeHtml($_vote->getRatingCode()) ?></th>
<td class="value">
<div class="rating-box">
<div class="rating" style="width:<?php echo $_vote->getPercent() ?>%;">
</div>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<p><?php echo nl2br($this->htmlEscape($_review->getDetail())) ?></p>
<p class="date"><?php echo $this->__('(Posted on %s)', $this->formatDate($_review->getCreatedAt()), 'long') ?></p>
</dd>
<?php endforeach; ?>
</dl>
<script type="text/javascript">decorateGeneric($$('#product-reviews-list dd'), ['last']);</script>
<?php endif;?>
<?php echo $this->getChildHtml('review_form') ?>
</div>
This is the solution I ended up going with:
<?php
$i = 1;
foreach ($_items as $_review):
if ($i < 6): ?>
Thanks for all that tried to help...
I had to do this and found a more robust way. In your theme's review.xml file find this line which creates the pager:
<block type="page/html_pager" name="product_review_list.toolbar" />
and replace it with the following (except with whichever number you like):
<block type="page/html_pager" name="product_review_list.toolbar">
<action method="setLimit"><limit>6</limit></action>
</block>
app\code\core\Mage\Review\Block\Product\View\List.php
protected function _beforeToHtml()
{
$this->getReviewsCollection()->setPageSize(5)
->load()
->addRateVotes();
return parent::_beforeToHtml();
}
It's worked for me. Of course, you should rewrite the block
I hope you are using collections for fetching reviews. So you can make
$collection->setPageSize('number of reviews on page');
I have here a quite complicated loop what I would like to modify while is not really working as I expected. The problem is: my if statements else condition is generating trash and I don't really know where the problem comes
<div id="container">
<?php include 'header.php';
foreach ($vars as $item):
if (is_array($item['productItems'])):?>
<div class="product_box">
<h4>
<?php echo $item['title']?>
</h4>
<?php foreach($item['productItems'] as $products):?>
<?php foreach($products as $key=>$product):?>
<div class="product">
<div class="image_holder">
<a href="<?php echo $product['image']['medium'];?>" class="preview">
<img src="<?php echo $product['image']['small'];?>"
alt="gallery thumbnail" title="" />
</a>
<?php foreach($product['trackingLinks'] as $key=>$trackinglink): ?>
<a href="<?php echo $trackinglink[0]['ppc']?>"> <span><?php echo $product['name'];?>
</span>
</a>
</div>
<h5>
<?php echo 'Preise: '. $product['price'].' '.$product['currency'];?>
</h5>
<span><?php echo 'Versand Kosten: '.$product['shippingCosts'].' EUR';?>
</span>
<p>
<?php echo (substr($product['descriptionLong'], 0,150 )).'...mehr';?>
</p>
<a class="shopping_button"
href="<?php echo $trackinglink[0]['ppc']?>">zum Shop</a>
</div>
<?php endforeach ?>
<?php endforeach ?>
<?php endforeach ?>
<div class="ajax_bar">
<select id="ajax_call" size="1" name="Weitere Produkte">
<option value='50'>Weitere Produkte</option>
<option value='100'>weitere 100</option>
<option value='150'>weitere 150</option>
</select>
</div>
</div>
<?php else: ?>
<div class="text_box">
<h2>
<?php echo $item['title'];?>
</h2>
<p>
<?php echo $item['text'];?>
</p>
</div>
<?php endif; ?>
<?php endforeach; ?>
<?php include 'footer.php';?>
</div>
I'm going to make a wild guess here and say that this is because you don't escape your output using htmlspecialchars or htmlentities.
If you're not sure what's inside the for-loop, use this nifty construct to debug on page:
echo '<pre>', htmlspecialchars(print_r($vars, true)), '</pre>';
It also helps to look at the page source instead; this usually gives vital clues as to why your page layout is so messed up.
Update
Okay got it! It's because of this:
<?php else: ?>
<div class="text_box">
<h2>
<?php echo $item['title'];?>
</h2>
<p>
<?php echo $item['text'];?>
</p>
The $item is a string here, and $item['title'] is understood by PHP as $item[0] which is the first character of $item :)