Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tessguefen/9120f8963b086e703a78 to your computer and use it in GitHub Desktop.
Save tessguefen/9120f8963b086e703a78 to your computer and use it in GitHub Desktop.
Miva Merchant - Save PowerReviews to a Custom Field (Thanks Steven!)
// Save PowerReviews rating amount and count to custom product field
$(window).load(function(){
var debug = false,
rating,
count,
productId = $('#product-id').text(),
timesChecked = 0,
storedRating = $('[itemprop="ratingValue"]').text(),
storedCount = $('[itemprop="reviewCount"]').text();
function checkForRating(){
rating = $('.pr-snippet-rating-decimal').text();
count = $('.pr-snippet-link span').text();
if(rating !== ''){
validateRating();
} else if (timesChecked < 100) {
if (debug) console.log('checked'+$('.pr-snippet-rating-decimal').text()+'-'+$('.pr-snippet-link span').text());
timesChecked += 1;
setTimeout(function(){checkForRating()},250);
}
}
checkForRating();
function validateRating(){
if(rating !== '0.0'){
if(storedRating !== rating || storedCount !== count){
saveRating();
}
}
}
function saveRating(){
// ajax call to page that will save the rating and count
$.ajax({
url: '/mm5/merchant.mvc',
type: 'POST',
cache: false,
data: {
Screen: 'PROD',
powerReviewsRating: rating,
powerReviewsCount: count,
updateProductId: productId
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment