CreareSEO icon indicating copy to clipboard operation
CreareSEO copied to clipboard

Rich Snippet with Yotpo Review system

Open cesaroito opened this issue 9 years ago • 4 comments

Hello, I use your plugin and works great. I want to know how can I use Rich Snippet with Yotpo. https://goo.gl/hBP7P3 Is that possible? Regards,

cesaroito avatar Sep 24 '15 19:09 cesaroito

As far as I can see both extensions should be compatible. Have you noticed any conflicts?

adampmoss avatar Nov 05 '15 08:11 adampmoss

I had some problems with creare & yotpo, and ran across this to-do as I was trying to figure out what to do.

Looks like the Creare SEO doesn't see the yotpo reviews at all... So, you need to pull in the rich snippet from yotpo and insert them.

Find this file /app/design/frontend/<theme-package>/<theme-template>/template/creareseo/product/schema.phtml

Delete line 30 to the end of the file.

}<?php if ($this->getReviewsCount()) : ?>,
  "review": [
    <?php foreach ($this->_productReviews as $review) : ?>
    {
      "@type": "Review",
      "author": "<?php echo $review->getNickname() ?>",
      "datePublished": "<?php echo date('Y-d-m', strtotime($review->getCreatedAt())) ?>",
      "description": "<?php echo $this->cleanString($review->getDetail()) ?>",
      "name": "<?php echo $review->getTitle() ?>"<?php $_averageRating = $this->getAverageRating($review->getReviewId()) ?><?php if ($_averageRating >= 1) : ?>,
      "reviewRating": {
        "@type": "Rating",
        "bestRating": "5",
        "ratingValue": "<?php echo $_averageRating ?>",<?php $_totalAverageRating += $_averageRating ?>
        "worstRating": "1"
      }
      <?php endif ?>
    }<?php echo ($_i != $this->getReviewsCount() ? ',' : '') ?>
        <?php $_i++ ?>
    <?php endforeach ?>
  ],
  "aggregateRating": {
    "@type": "AggregateRating",
    <?php $ratingValue = round($_totalAverageRating/$this->getReviewsCount(), 1) ?>
        <?php if ($ratingValue > 0) : ?>
    "ratingValue": "<?php echo $ratingValue ?>",
    <?php else: ?>
    "ratingValue": "1",
    <?php endif ?>
    "reviewCount": "<?php echo $this->getReviewsCount() ?>"
  }
  <?php endif ?>
}
</script>

and replace them with the following:

}<?php $array = $this->helper('yotpo/richSnippets')->getRichSnippet($this); ?>
  <?php if ($array["reviews_count"] > 0): ?>,
  "aggregateRating": {
    "@type": "AggregateRating",
    "ratingValue": "<?php echo $array["average_score"]; ?>",
    "reviewCount": "<?php echo $array["reviews_count"]; ?>"
  }
  <?php endif; ?>
}
</script>

This way only inserts the aggregate rating section if there's reviews in yotpo. Otherwise, it drops it.

Yotpo won't export all the individual reviews to go into the ld+json, so we need to drop the review block. All you want in your final version of this file is the aggregate rating info.

sam327 avatar Feb 15 '16 20:02 sam327

Yep, I can second that. Optimally, you would check if the Yotpo extension is installed and active and if so, use the code provided by @sam327.

sprankhub avatar Mar 07 '16 15:03 sprankhub

This is worth noting - you can only use rich snippets if you're on Yotpo's Pro plan or higher - it won't work on the starter plan.

The check to see if a module is installed and active is something like this: Mage::getConfig()->getModuleConfig('modulename')->is('active', 'true') which you can use to write an if-check and wrap my code in...

However, if you're going in to edit this file to add the yotpo code, you really should know whether or not yotpo is installed. But my code seems to fail gracefully. I broke yotpo during development and nothing was majorly broken, I just got blank spaces. YMMV, of course.

sam327 avatar Mar 11 '16 01:03 sam327