Jump to content

Rating Stars on homepage


geoffb

Recommended Posts

Even though the rating is available in the View Product page, and there is a "gather-all-data" method that should be used for all purposes, CubeCart uses a separate method to get the Latest Products. We need to enhance that method.

 

In the file /classes/cubecart.class.php, find near line 120, this:

                    $products[] = $product;
                }

                $GLOBALS['smarty']->assign('LATEST_PRODUCTS', $products);

On a line just above that, add:

/* MOD MOD MOD */ if (($product_review = $GLOBALS['db']->select('CubeCart_reviews', 'SUM(`rating`) AS Score, COUNT(`id`) as Count', array('approved' => 1, 'product_id' => $product['product_id']))) !== false) { if($product_review[0]['Score'] !== "") $product['review_score'] = round($product_review[0]['Score']/$product_review[0]['Count'], 1); }

I kept it to one line so as to not disturb the line numbering too badly.

 

This gives us a 'review_score', if one is available, added to the data that makes up each product in Latest Products.

 

Next, in the skin, you now have:

{if isset($product.review_score) && $CONFIG.enable_reviews}<span style="">Rating: {$product.review_score}&nbsp;</span>{/if}

So, we show the Rating: ## if the variable exists and if the admin has enabled evidence of reviews to be visible. You need to decide how you want to show this: a number (max is 5), a series of stars, wi-fi reception bars, etc.

 

You can copy the {for}{/for} block from content.product.php if you want to use that style of display.

Link to comment
Share on other sites

Hi bsmither,

 

OK thats all coded up. For anyone else looking to do the same, once I added the below to file classes/cubecart.class.php in line 118 (double check your number against the code above where it needs to sit between)

/* MOD START */ if (($product_review = $GLOBALS['db']->select('CubeCart_reviews', 'SUM(`rating`) AS Score, COUNT(`id`) as Count', array('approved' => 1, 'product_id' => $product['product_id']))) !== false) { if($product_review[0]['Score'] !== "") $product['review_score'] = round($product_review[0]['Score']/$product_review[0]['Count'], 1); }/*MOD END*/

I then needed to make a call to the review stars in file content.homepage.php, here it is, note that if you copy this code from the content.product.php file you need to remove the capitalisation from $PRODUCT, see the below

{if isset($product.review_score) && $CONFIG.enable_reviews}
      <p class="rating">
      {for $i = 1; $i <= 5; $i++}
          {if $product.review_score >= $i}
          <img src="{$STORE_URL}/skins/{$SKIN_FOLDER}/images/common/star.png" alt="" />
          {elseif $product.review_score > ($i - 1) && $product.review_score < $i}
          <img src="{$STORE_URL}/skins/{$SKIN_FOLDER}/images/common/star_half.png" alt="" />
          {else}
          <img src="{$STORE_URL}/skins/{$SKIN_FOLDER}/images/common/star_off.png" alt="" />
          {/if}
        {/for}
        </p>
        {/if}

the above will test to see if the product has a rating and if so show it in star format.

 

Hope this helps future users but beware, any modifications to the core code such as the classes folder will be overwritten when you do any upgrades so for me I'm noting on file any changes so I can include them again after an update, although I'm sure doing it the plugin way would be better, just dont know how to yet!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...