News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

How to merge all reviews (from childs and display it on parent product page)

Started by bart198x, April 06, 2015, 11:40:38 AM

Previous topic - Next topic

ZoBabe

Studio 42,
  Is there somewhere I can find instructions on setting the reviews and ratings to come from the parent, and apply new ones only to parent as well? While I've followed the instructions above to merge reviews, it's far from ideal. And I can't get the ratings to work at all.
  This has been driving me crazy for months, and several of my clients are asking to be moved to other platforms over it...  :(

Joomla: 3.4.5
Virtuemart: 3.0.10
 

Studio 42

Quote from: ZoBabe on October 29, 2015, 03:30:30 AM
Studio 42,
  Is there somewhere I can find instructions on setting the reviews and ratings to come from the parent, and apply new ones only to parent as well? While I've followed the instructions above to merge reviews, it's far from ideal. And I can't get the ratings to work at all.
Sorry i only help, i have no time to do a full working solution.

bortolani

Hi, I solved the problem by assigning all reviews to the parent product.

In practice if the product is a 'father' I assign the review to it. In case of  a child product I assign the review to its parent.
Same when showing reviews.

The result is that the parent and all its children share the same reviews.
I don't see any drawback in this solution.

To do that I created an override for components\com_virtuemart\views\productdetails\tmpl\default_reviews.php
Here is the code for the new default_reviews.php:


<?php
/**
 *
 * Show the product details page
 *
 * @package    VirtueMart
 * @subpackage
 * @author Max Milbers, Valerie Isaksen
 * @link http://www.virtuemart.net
 * @copyright Copyright (c) 2004 - 2010 VirtueMart Team. All rights reserved.
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
 * VirtueMart is free software. This version may have been modified pursuant
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses.
 * @version $Id: default_reviews.php 8508 2014-10-22 18:57:14Z Milbo $
 */

// Check to ensure this file is included in Joomla!
defined ('_JEXEC') or die ('Restricted access');

// Customer Reviews
$review_editable true;
if (
$this->allowRating || $this->allowReview || $this->showRating || $this->showReview) {

$maxrating VmConfig::get'vm_maximum_rating_scale');
$ratingsShow VmConfig::get'vm_num_ratings_show'); // TODO add  vm_num_ratings_show in vmConfig
$stars = array();
$showall vRequest::getBool'showall'FALSE );
$ratingWidth $maxrating*24;
for( $num 0$num<=$maxrating$num++ ) {
$stars[] = '
<span title="'
.(vmText::_"COM_VIRTUEMART_RATING_TITLE" ).$num.'/'.$maxrating).'" class="vmicon ratingbox" style="display:inline-block;width:'24*$maxrating.'px;">
<span class="stars-orange" style="width:'
.(24*$num).'px">
</span>
</span>'
;
}

echo '<div class="customer-reviews">';

$ratingModel VmModel::getModel('ratings');
$productModel VmModel::getModel('product');

$publishedparent FALSE;
$parentid $this->product->product_parent_id;
if ($parentid) {
$parentproduct $productModel->getProductSingle($parentid);
$publishedparent $parentproduct->published;
}

if ($publishedparent$addreview_id $parentid;
else $addreview_id $this->product->virtuemart_product_id;

$allreviews $ratingModel->getReviewsByProduct($addreview_id);


if ($allreviews) {
foreach( $allreviews as $review ) {
/* Check if user already commented */
// if ($review->virtuemart_userid == $this->user->id ) {
if ($review->created_by == $this->user->id && !$review->review_editable) {
$review_editable false;
}
}
}
}

if (
$this->allowRating or $this->allowReview) {

if ($review_editable) {
?>


<form method="post"
  action="<?php echo JRoute::_'index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id='.$this->product->virtuemart_product_id.'&virtuemart_category_id='.$this->product->virtuemart_category_idFALSE ); ?>"
  name="reviewForm" id="reviewform">

<?php if($this->allowRating and $review_editable) { ?>

<h4><?php echo vmText::_'COM_VIRTUEMART_WRITE_REVIEW' );
if(count$this->rating_reviews ) == 0) {
?>
<span><?php echo vmText::_'COM_VIRTUEMART_WRITE_FIRST_REVIEW' ?></span><?php
?>

</h4>
<span class="step"><?php echo vmText::_'COM_VIRTUEMART_RATING_FIRST_RATE' ?></span>
<div class="rating">
<label for="vote"><?php echo $stars[$maxrating]; ?></label>
<input type="hidden" id="vote" value="<?php echo $maxrating ?>" name="vote">
</div>

<?php

$reviewJavascript "
jQuery(function($) {
var steps = "
.$maxrating.";
var parentPos= $('.rating .ratingbox').position();
var boxWidth = $('.rating .ratingbox').width();// nbr of total pixels
var starSize = (boxWidth/steps);
var ratingboxPos= $('.rating .ratingbox').offset();

jQuery('.rating .ratingbox').mousemove( function(e){
var span = jQuery(this).children();
var dif = e.pageX-ratingboxPos.left; // nbr of pixels
difRatio = Math.floor(dif/boxWidth* steps )+1; //step
span.width(difRatio*starSize);
$('#vote').val(difRatio);
//console.log('note = ',parentPos, boxWidth, ratingboxPos);
});
});
"
;
vmJsApi::addJScript'rating_stars'$reviewJavascript );

}

// Writing A Review
if ($this->allowReview and $review_editable) {
?>

<div class="write-reviews">

<?php // Show Review Length While Your Are Writing
$reviewJavascript "
function check_reviewform() {

var form = document.getElementById('reviewform');
var ausgewaehlt = false;

if (form.comment.value.length < "
.VmConfig::get'reviews_minimum_comment_length'100 ).") {
alert('"
.addslashesvmText::sprintf'COM_VIRTUEMART_REVIEW_ERR_COMMENT1_JS'VmConfig::get'reviews_minimum_comment_length'100 ) ) )."');
return false;
}
else if (form.comment.value.length > "
.VmConfig::get'reviews_maximum_comment_length'2000 ).") {
alert('"
.addslashesvmText::sprintf'COM_VIRTUEMART_REVIEW_ERR_COMMENT2_JS'VmConfig::get'reviews_maximum_comment_length'2000 ) ) )."');
return false;
}
else {
return true;
}
}

function refresh_counter() {
var form = document.getElementById('reviewform');
form.counter.value= form.comment.value.length;
}
"
;
vmJsApi::addJScript'check_reviewform'$reviewJavascript ); ?>

<span
class="step"><?php echo vmText::sprintf'COM_VIRTUEMART_REVIEW_COMMENT'VmConfig::get'reviews_minimum_comment_length'100 ), VmConfig::get'reviews_maximum_comment_length'2000 ) ); ?></span>
<br/>
<textarea class="virtuemart" title="<?php echo vmText::_'COM_VIRTUEMART_WRITE_REVIEW' ?>"
  class="inputbox" id="comment" onblur="refresh_counter();" onfocus="refresh_counter();"
  onkeyup="refresh_counter();" name="comment" rows="10"
  cols="60"><?php if(!empty($this->review->comment)) {
echo $this->review->comment;
?>
</textarea>
<br/>
<span><?php echo vmText::_'COM_VIRTUEMART_REVIEW_COUNT' ?>
<input type="text" value="0" size="4" name="counter" maxlength="4" readonly="readonly" style="display: inherit"/>
</span>
<?php
}

if($review_editable and $this->allowReview) {
?>

<br/><br/>
<input class="highlight-button" type="submit" onclick="return( check_reviewform());"
   name="submit_review" title="<?php echo vmText::_'COM_VIRTUEMART_REVIEW_SUBMIT' ?>"
   value="<?php echo vmText::_'COM_VIRTUEMART_REVIEW_SUBMIT' ?>"/>
<?php } else if($review_editable and $this->allowRating) { ?>
<input class="highlight-button" type="submit" name="submit_review"
   title="<?php echo vmText::_'COM_VIRTUEMART_REVIEW_SUBMIT' ?>"
   value="<?php echo vmText::_'COM_VIRTUEMART_REVIEW_SUBMIT' ?>"/>
<?php
}

?>
    </div>

<input type="hidden" name="virtuemart_product_id"
   value="<?php echo $addreview_id?>"/>
<input type="hidden" name="option" value="com_virtuemart"/>
<input type="hidden" name="virtuemart_category_id"
   value="<?php echo vRequest::getInt'virtuemart_category_id' ); ?>"/>
<input type="hidden" name="virtuemart_rating_review_id" value="0"/>
<input type="hidden" name="task" value="review"/>
</form>
<?php
} else if(!
$review_editable) {
echo '<strong>'.vmText::_'COM_VIRTUEMART_DEAR' ).$this->user->name.',</strong><br />';
echo vmText::_'COM_VIRTUEMART_REVIEW_ALREADYDONE' );
}
}


if (
$this->showReview) {

?>

<h4><?php echo vmText::('COM_VIRTUEMART_REVIEWS'?></h4>

<div class="list-reviews">
<?php
$i 0;
//$review_editable = TRUE;
$reviews_published 0;
if ($allreviews) {
foreach ($allreviews as $review) {
if ($i == 0) {
$color 'normal';
} else {
$color 'highlight';
}


?>


<?php // Loop through all reviews
if (!empty($allreviews) && $review->published) {
$reviews_published++;
?>

<div class="<?php echo $color ?>">
<span class="date"><?php echo JHtml::date ($review->created_onvmText::('DATE_FORMAT_LC')); ?></span>
<span class="vote"><?php echo $stars[(int)$review->review_rating?></span>
<blockquote><?php echo $review->comment?></blockquote>
<span class="bold"><?php echo $review->customer ?></span>
</div>
<?php
}
$i++;
if ($i == $ratingsShow && !$showall) {
/* Show all reviews ? */
if ($reviews_published >= $ratingsShow) {
$attribute = array('class'=> 'details''title'=> vmText::('COM_VIRTUEMART_MORE_REVIEWS'));
echo JHtml::link ($this->more_reviewsvmText::('COM_VIRTUEMART_MORE_REVIEWS'), $attribute);
}
break;
}
}

} else {
// "There are no reviews for this product"
?>

<span class="step"><?php echo vmText::('COM_VIRTUEMART_NO_REVIEWS'?></span>
<?php
}  ?>

<div class="clear"></div>
</div>
<?php
}

if (
$this->allowRating || $this->allowReview || $this->showRating || $this->showReview) {
echo '</div> ';
}
?>



Hope this helps,
Bruno

Studio 42

Should work, but then all review are in parent. SO using parent as a model, and child is not same product give trouble with this. Because you see review in other child product that are perhaps not the same.
Eg using generic "phone" as a model and child are Samsung s4,Samsung s5,Iphone 6 ...

lindapowers

Quote from: Studio 42 on February 17, 2016, 17:25:06 PM
Should work, but then all review are in parent. SO using parent as a model, and child is not same product give trouble with this. Because you see review in other child product that are perhaps not the same.
Eg using generic "phone" as a model and child are Samsung s4,Samsung s5,Iphone 6 ...

Exactly our case

bortolani

Hi,
one possible workaround is to check if the parent product is published.
In general, if you use a parent as a pattern for other products then you don't publish it.
If you publish it then you probably have variants that shoud share the same reviews.

In fact this solution should work for almost all scenarios.

In my case, for example I  have a 'grandparent' product that I use as a pattern and it is not published.
Its children are products that are published and that themselves have children for different size/color combinations.
Reviews are assigned to the 2nd level products, and all grandchildren share the same reviews as well as their first ancestor.

The code I posted above produces this behaviour.
You may check it here: www.puffosport.it/puffo2 (under development)

Bruno

xenofon360

Hi all,

i adjusted the code of bart198x for reviews and works fine!!

I have a problem though, the code that bart198x provided for ratings that makes the same work (show ratings everywhere in the product)
don't work cause i don't have a rating.php file in my template, i have only the original one into basic virtuemart folder. So ... , is there any solution for that ?

Thank you in advance,

Xenofon Kaloudis