geoffb Posted December 10, 2013 Share Posted December 10, 2013 Hi, Can you please advise on how to include the rating stars (only) in the homepage latest products blocks for those that have a rating. thanks Geoff Quote Link to comment Share on other sites More sharing options...
bsmither Posted December 10, 2013 Share Posted December 10, 2013 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} </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. Quote Link to comment Share on other sites More sharing options...
geoffb Posted December 10, 2013 Author Share Posted December 10, 2013 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! Quote Link to comment Share on other sites More sharing options...
Al Brookbanks Posted December 17, 2013 Share Posted December 17, 2013 Similar code has been added to GitHub. https://github.com/cubecart/CubeCart/issues/50. The HTML added to the templates is commented out by default aside from Vanilla. We need to break some of this procedural code down to functions for v6. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.