01273 264503 info@mootpoint.org

OpenCart is fairly well optimised for search engine friendliness, and has support for SEO-friendly URLs out of the box. User reviews are not only a great way to provide feedback to customers about a product, but also a good way to keep product content fresh and attractive to search engines. However, OpenCart product reviews are displayed in the Reviews tab using AJAX. Search engine crawlers will not process the JavaScript used to pull the review content, and thus cannot read the reviews. I wrote this vqMod script which writes the review content into the HTML so it can be crawled.

<modification>

   <id>Make User Reviews Indexable</id>
   <version>1.0.0</version>
   <vqmver>2.1</vqmver>
   <author>countzer0</author>

   <file name="catalog/controller/product/product.php">
        <operation>
            <search position="before"><![CDATA[$this->data['tags'] = array();]]></search>
            <add><![CDATA[         $this->data['reviews'] = array();
         
         $review_total = $this->model_catalog_review->getTotalReviewsByProductId($this->request->get['product_id']);
            
         $results = $this->model_catalog_review->getReviewsByProductId($this->request->get['product_id'], 0, 20);
            
         foreach ($results as $result) {
            $this->data['reviews'][] = array(
               'author'     => $result['author'],
               'text'       => strip_tags($result['text']),
               'rating'     => (int)$result['rating'],
               'reviews'    => sprintf($this->language->get('text_reviews'), (int)$review_total),
               'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added']))
            );
         }   
]]></add>
        </operation>
   </file>
   <file name="catalog/view/theme/default/template/product/product.tpl">
        <operation>
            <search position="replace"><![CDATA[<div id="review"></div>]]></search>
            <add><![CDATA[    <div id="review">
      <?php if ($reviews) { ?>
         <?php foreach ($reviews as $review) { ?>
         <div class="content"><b><?php echo $review['author']; ?></b> | <img src="catalog/view/theme/default/image/stars-<?php echo $review['rating'] . '.png'; ?>" alt="<?php echo $review['reviews']; ?>" /><br />
           <?php echo $review['date_added']; ?><br />
           <br />
           <?php echo $review['text']; ?></div>
         <?php } ?>
      <?php } else { ?>
         <div class="content"><?php echo $text_no_reviews; ?></div>
      <?php } ?>
    </div>
]]></add>
        </operation>
   </file>
   
</modification>

Note: the script pulls out all the reviews for the product, it doesn’t paginate them, so watch out if you have thousands of reviews! Also, the AJAX is left untouched. This script works with OpenCart 1.5.3.