News:

Support the VirtueMart project and become a member

Main Menu

Ajax rating system or something similar?

Started by ZippityMan, December 19, 2012, 18:24:39 PM

Previous topic - Next topic

ZippityMan

Right now users have to write comment, select star and click on the button.
But, is it possible to allow only star rating system by simply clicking on the stars (with existing functionality of VM)?

If by current version of VM that's not possible, can you suggest me some plugin for this

Thanks!

bytelord

Hi,

Under Configuration -> Shopfront on the right bottom under Shopper Review/Rating System ... did you try to disable review system and enable only rating system? Just said.

Also please every time you ask something remember to mention you joomla,vm2 and php versions you are using.

Regards
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

ZippityMan

Yes and nothing. Problem is that start rating system is connected with review/commenting system ???
I don't see sense in this, but okay its free product..

I use Joomla 2.5.8, VM 2.0.14, PHP 5.3.10.

bytelord

Yes,

You have right on that. I will check it, there is needed a better solution on that. You can disable rating and have only review and not able to have only rating and not review.

Regards
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

bytelord

#4
Hello again,

A very quick and dirty solution atm for your issue, but the review button will be there, i have to work with the javascript and i dont have time right now.

override the product details template file default_reviews.php

To create a template override for just copy the file joomla_root_folder/components/com_virtuemart/views/productsdetails/tmpl/default_reviews.php under joomla_root_folder/templates/your_joomla_template/html/com_virtuemart/productsdetails/default_reviews.php
If the folders are not exist please create them ... if you already use template overrides edit the overridden file and don't copy that file again.

Now, edit that file and around line 178 you will find:

if ($review_editable) {
?>
<span class="step"><?php echo JText::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 JText::('COM_VIRTUEMART_WRITE_REVIEW'?>" class="inputbox" id="comment" onblur="refresh_counter();" onfocus="refresh_counter();" onkeyup="refresh_counter();" name="comment" rows="5" cols="60"><?php if (!empty($this->review->comment)) {
echo $this->review->comment;
?>
</textarea>
<br/>
<span><?php echo JText::('COM_VIRTUEMART_REVIEW_COUNT'?>
<input type="text" value="0" size="4" class="vm-default" name="counter" maxlength="4" readonly="readonly"/>
</span>
<br/><br/>
<input class="highlight-button" type="submit" onclick="return( check_reviewform());" name="submit_review" title="<?php echo JText::('COM_VIRTUEMART_REVIEW_SUBMIT')  ?>" value="<?php echo JText::('COM_VIRTUEMART_REVIEW_SUBMIT')  ?>"/>
<?php
} else {
echo '<strong>' JText::('COM_VIRTUEMART_DEAR') . $this->user->name ',</strong><br />';
echo JText::('COM_VIRTUEMART_REVIEW_ALREADYDONE');
}



modified to:

$review_editable=FALSE;
if ($review_editable) {
?>
<span class="step"><?php echo JText::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 JText::('COM_VIRTUEMART_WRITE_REVIEW'?>" class="inputbox" id="comment" onblur="refresh_counter();" onfocus="refresh_counter();" onkeyup="refresh_counter();" name="comment" rows="5" cols="60"><?php if (!empty($this->review->comment)) {
echo $this->review->comment;
?>
</textarea>
<br/>
<span><?php echo JText::('COM_VIRTUEMART_REVIEW_COUNT'?>
<input type="text" value="0" size="4" class="vm-default" name="counter" maxlength="4" readonly="readonly"/>
</span>
<br/><br/>
<input class="highlight-button" type="submit" onclick="return( check_reviewform());" name="submit_review" title="<?php echo JText::('COM_VIRTUEMART_REVIEW_SUBMIT')  ?>" value="<?php echo JText::('COM_VIRTUEMART_REVIEW_SUBMIT')  ?>"/>
<?php
} else {
//echo '<strong>' . JText::_ ('COM_VIRTUEMART_DEAR') . $this->user->name . ',</strong><br />';
  
//echo JText::_ ('COM_VIRTUEMART_REVIEW_ALREADYDONE');
?>

                               <input class="highlight-button" type="submit" onclick="return( check_reviewform());" name="submit_review" title="<?php echo JText::('COM_VIRTUEMART_REVIEW_SUBMIT')  ?>" value="<?php echo JText::('COM_VIRTUEMART_REVIEW_SUBMIT')  ?>"/>
<?php
}


Regards
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

ZippityMan

Thanks, but this is not going to work :)

You are setting $review_editable to be false, which makes it to skip first block and load second block of the IF statement which is empty (commented out).

Stars are displayed, but its not possible to click and submit rating, because submit button is not displayed :)

The closest thing which i want to accomplish is http://joomla.vargas.co.cr/en/news/26-joomla-plugins/62-extra-vote-plugin (of course it needs to be reconfigured to accept VM product IDs instead of articles IDs)..

bytelord

#6
Works for me for vm2.0.14 with everything enabled, just skip the review area and you have to press the submit button (shows only the stars and the submit button)

I have place the input button on else ... but as i said this is a quick, dirty and no good solution...

but ...

As i said there is needed to modify the javascript and i don't have the time right now to create a custom solution for you but i have point you to the right spot.

Maybe on the next release (2.2) and after discuss it with the team create an option for that to use only the rating system on review.

Hopefully you understand that i cannot work on this right now, if someone else on the forum have create a custom solution for that will be great to share it with us here.

Regards
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

bytelord

ok,

I work with it and i create a custom solution for you as you need it ... but each time you rate it the page is refreshed and no ajax is been used. You can modify the default_reviews to don't let a user to rate again if you wish. This will work only if you have  enabled everything from the backend ... so... the only modification you will need is:

Comment lines from  178 to 196 before ?>

/* if ($review_editable) {
?>
<span class="step"><?php echo JText::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 JText::('COM_VIRTUEMART_WRITE_REVIEW'?>" class="inputbox" id="comment" onblur="refresh_counter();" onfocus="refresh_counter();" onkeyup="refresh_counter();" name="comment" rows="5" cols="60"><?php if (!empty($this->review->comment)) {
echo $this->review->comment;
?>
</textarea>
<br/>
<span><?php echo JText::('COM_VIRTUEMART_REVIEW_COUNT'?>
<input type="text" value="0" size="4" class="vm-default" name="counter" maxlength="4" readonly="readonly"/>
</span>
<br/><br/>
<input class="highlight-button" type="submit" onclick="return( check_reviewform());" name="submit_review" title="<?php echo JText::('COM_VIRTUEMART_REVIEW_SUBMIT')  ?>" value="<?php echo JText::('COM_VIRTUEMART_REVIEW_SUBMIT')  ?>"/>
<?php
} else {
echo '<strong>' JText::('COM_VIRTUEMART_DEAR') . $this->user->name ',</strong><br />';
echo JText::('COM_VIRTUEMART_REVIEW_ALREADYDONE');
}
*/?>
</div><?php


and add on the javascript the following code around line 175

$('.write-reviews .ratingbox').click( function(e){
$('#reviewform').submit();
});


when you click the star will submit the form.... so that will work for you with the thing that the page is been refreshed because the form is been submitted.

Regards
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

bytelord

#8
Hi again,

I wanna test some thing so a made a better solution for the previous to use ajax for saving and display a message. You can modify the PHP,JS and styling and make it better so here is:

around line 5 add:
//Check if the user has already voted
//author: bytelord
$ratingModel = VmModel::getModel('ratings');
$vote = $ratingModel->getVoteByProduct($this->product->virtuemart_product_id);
if(!empty($vote) && $vote->created_by ==$this->user->id) {
    $isRatedbyUser=TRUE;
} else {
$isRatedbyUser=FALSE;
}


around line 175 add the extra juerry code using ajax:

//Use ajax to save the voting and dislay message
//Author: bytelord

$('.write-reviews .ratingbox').click( function(e){
var alreadyvote='".$isRatedbyUser."';
if (alreadyvote != '1') {
    $.ajax({
type:'POST',
url:'" . JRoute::_ ('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $this->product->virtuemart_product_id . '&virtuemart_category_id=' . $this->product->virtuemart_category_id) . "',
data:$('#reviewform').serialize(),

success: function(data) {
   $('span.step').html('Thanks for your vote!');

},
error: function(data) {
// error handlin, place a message if you like here
      }    
})
} else {
$('span.step').html('".JText::_ ('COM_VIRTUEMART_REVIEW_ALREADYDONE')."');
}


comment the lines from 178 to 196 before ?>

/* if ($review_editable) {
?>
<span class="step"><?php echo JText::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 JText::('COM_VIRTUEMART_WRITE_REVIEW'?>" class="inputbox" id="comment" onblur="refresh_counter();" onfocus="refresh_counter();" onkeyup="refresh_counter();" name="comment" rows="5" cols="60"><?php if (!empty($this->review->comment)) {
echo $this->review->comment;
?>
</textarea>
<br/>
<span><?php echo JText::('COM_VIRTUEMART_REVIEW_COUNT'?>
<input type="text" value="0" size="4" class="vm-default" name="counter" maxlength="4" readonly="readonly"/>
</span>
<br/><br/>
<input class="highlight-button" type="submit" onclick="return( check_reviewform());" name="submit_review" title="<?php echo JText::('COM_VIRTUEMART_REVIEW_SUBMIT')  ?>" value="<?php echo JText::('COM_VIRTUEMART_REVIEW_SUBMIT')  ?>"/>
<?php
} else {
echo '<strong>' JText::('COM_VIRTUEMART_DEAR') . $this->user->name ',</strong><br />';
echo JText::('COM_VIRTUEMART_REVIEW_ALREADYDONE');
}
*/?>
</div><?php


Please modified as you wish ...
Not that this is a dirty solution because needed to modify the core and also create a better layout options for that...

It would be nice and hope find some time to make a better solution for 2.2 with a new option to rate products only and use only ajax for reloading/save content.

Regards
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

jux