Dirty Butter Posted May 16, 2015 Author Share Posted May 16, 2015 I saw that and wondered, as I really thought I had made a copy and then deleted the original sections on the active one. I'll double check. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 16, 2015 Author Share Posted May 16, 2015 I think that's been the problem. I did try to replace that line of code, but I have no idea how I ended up with what I currently have. The SUM part of the code is missing. UGH!!! Will replace and test again, but I suspect it will be ok. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 16, 2015 Author Share Posted May 16, 2015 No - I've made a mess of this. I hate that we can no longerĀ link to specific comments in a thread.Current code:// BSMITHER DISPLAY REVIEWS // Display Reviews $page = (isset($_GET['page']) && !empty($_GET['page'])) ? $_GET['page'] : 1; $per_page = 5; if (($reviews = $GLOBALS['db']->select('CubeCart_reviews', false, array('approved' => 1, 'product_id' => $product['product_id']), 'time DESC', $per_page, $page)) !== false) { if (($paginate = $GLOBALS['db']->select('CubeCart_reviews', 'SUM(`rating`) AS Score, COUNT(`id`) as Count', array('approved' => 1, 'product_id' => $product['product_id']))) !== false) { $GLOBALS['smarty']->assign('PAGINATION', $GLOBALS['db']->pagination(count($paginate), $per_page, $page)); $review_score = 0; $review_count = 0; foreach ($paginate as $rating) { if ($rating['rating'] > 0) {$review_score += $rating['rating']; $review_count++; } } } foreach ($reviews as $review) { if ($review['anon']) { $review['name'] = $GLOBALS['language']->catalogue['review_anon']; } $review['date'] = formatTime($review['time']); $review['date_schema'] = formatTime($review['time'], '%G-%m-%d', true); $review['gravatar'] = md5(strtolower(trim($review['email']))); $review['gravatar_src'] = 'http://www.gravatar.com/avatar/'.$review['gravatar'].'?d=404&r=g'; $headers = get_headers($review['gravatar_src']); $review['gravatar_exists'] = strstr($headers[0], '200') ? true : false; $vars[] = $review; } $GLOBALS['smarty']->assign('REVIEWS', $vars); $GLOBALS['smarty']->assign('REVIEW_COUNT', (int)$review_count); $GLOBALS['smarty']->assign('REVIEW_AVERAGE', ($review_count) ? round($review_score/$review_count, 1) : '0' ); } // END BSMITHER DISPLAY REVIEWS Ā Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 16, 2015 Share Posted May 16, 2015 The SUM part is missing? Yes, that query has been replaced with a different query. But that's up at line 300 and something. We are working at line 1400 and something. There is no SUM part of a statement in this area.There is a $review['rating']: 5.0 on line 1418 Now, $score is 5 and $count is 1 on line 1420 There is a $review['rating']: 5.0 on line 1418 Now, $score is 10 and $count is 2 on line 1420 After rounding, $score is 5.0 on line 1429Note the progression: $score gets added up to 10 for a $count of 2. And after rounding, $score is 10/2 = 5. This is all good.So, somewhere after line 1429, $score is being erroneously adjusted.Please copy your lines (should be) 1413 - 1439. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 16, 2015 Author Share Posted May 16, 2015 Here's my 1413 sectionĀ Ā Ā Ā Ā Ā ## Calculate average review scoreĀ Ā Ā Ā Ā Ā if ($GLOBALS['config']->get('config', 'enable_reviews') && ($reviews = $GLOBALS['db']->select('CubeCart_reviews', array('rating'), array('product_id' => (int)$product['product_id'], 'approved' => '1'))) !== false) {Ā Ā Ā Ā Ā Ā Ā Ā Ā $score = 0;Ā Ā Ā Ā Ā Ā Ā Ā Ā $count = 0;Ā Ā Ā /* BSMITHER REVIEWS CODE */Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā foreach ($reviews as $review) {Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā if ($review['rating'] > 0) if((int)$product['product_id'] = 3150) { trigger_error('There is a $review[\'rating\']: '.$review['rating']);Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā $score += $review['rating'];Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā $count++;if((int) $product['product_id'] = 3150) trigger_error('Now, $score is '.$score.' and $count is '.$count);Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā }Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā }Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā $product['review_score'] = ($count) ? round($score/$count, 1) : false ;Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā if (!$product_view) {Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā $link = currentPage(array('_a', 'cat_id'), null, false).'_a=product&product_id='.$product['product_id'].'#reviews';Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā } else {Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā $link = '#reviews';Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā }Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā $score = ($product['review_score']) ? number_format($product['review_score'],1) : 'null'; if((int)$product['product_id'] = 3150) trigger_error('After rounding, $score is '.$score);/*END BSMITHER REVIEWS CODE */I called it quits last night because I was getting confusedĀ and frustrated then. And I need to take a break from this again. I can feel my blood pressure going up. I am SO sorry that I so often mess up trying to follow your directions. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 16, 2015 Author Share Posted May 16, 2015 Here's the piece of reviews code left after I show the end of your edits, in case I messed something up there: if (!$product_view) { $link = currentPage(array('_a', 'cat_id'), null, false).'_a=product&product_id='.$product['product_id'].'#reviews'; } else { $link = '#reviews'; } $score = number_format(($score/$count), 1); if ($product_view) { $GLOBALS['smarty']->assign('LANG_REVIEW_INFO', sprintf($GLOBALS['language']->catalogue['review_info'], $score, $count, $link)); } else { $product['review_info'] = sprintf($GLOBALS['language']->catalogue['review_info'], $score, $count, $link); } unset($score, $count); } else { $product['review_score'] = false; }Ā Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 16, 2015 Share Posted May 16, 2015 Change this:if ($review['rating'] > 0) if((int)$product['product_id'] = 3150) { trigger_error('There is a $review[\'rating\']: '.$review['rating']);To this:if ($review['rating'] > 0) { if((int)$product['product_id'] = 3150) trigger_error('There is a $review[\'rating\']: '.$review['rating']);Ā Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 16, 2015 Share Posted May 16, 2015 If this is what you have:/*END BSMITHER REVIEWS CODE */ x if (!$product_view) { x $link = currentPage(array('_a', 'cat_id'), null, false).'_a=product&product_id='.$product['product_id'].'#reviews'; x } else { x $link = '#reviews'; x } x $score = number_format(($score/$count), 1); if ($product_view) { $GLOBALS['smarty']->assign('LANG_REVIEW_INFO', sprintf($GLOBALS['language']->catalogue['review_info'], $score, $count, $link)); } else { $product['review_info'] = sprintf($GLOBALS['language']->catalogue['review_info'], $score, $count, $link); } unset($score, $count); } else { $product['review_score'] = false; }Then lines indicated by an 'x' are duplicates, meaning they weren't included in the group of original statements that needed to be replaced. These statements are present above the /* END */ statement -- as they should be.So, the lines indicated by an 'x' -- remove them. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 16, 2015 Author Share Posted May 16, 2015 That was it. I really did try to keep up with all the edits. I can't apologize enough for wasting your time and effort. I've lost the Average Score somewhere along the way right above the list of reviews on the product page, and I haven't re-tested the no star situation yet. Will be back in a bit. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 16, 2015 Author Share Posted May 16, 2015 I can't find an error of mine causing the Average Score to show as zero on all the reviewed items, regardless of stars. Oh My. Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 16, 2015 Share Posted May 16, 2015 Did you do this one? Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 16, 2015 Share Posted May 16, 2015 Then there is this one where a statement is not what I posted here in the 300 area of line numbers.You have: if (($paginate = $GLOBALS['db']->select('CubeCart_reviews', 'SUM(`rating`) AS Score, COUNT(`id`) as Count', array('approved' => 1, 'product_id' => $product['product_id']))) !== false) { It should be: if (($paginate = $GLOBALS['db']->select('CubeCart_reviews', array('rating'), array('product_id' => (int)$product['product_id'], 'approved' => '1'))) !== false) {Ā Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 16, 2015 Author Share Posted May 16, 2015 That line I had SUM in was the problem - I get confused so easily. All seems to be working as I had hoped now. I'll leave the error trigger code in for now, for fear I'll delete the wrong parts. I'll do that on a day when I'm fresh. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 20, 2015 Author Share Posted May 20, 2015 Been studying Zurb.com some more, and I think I stumbled on the way to require the rating. CC v6 already has a plugin called Abide (foundation.abide.js in skins/foundation/js/foundation).http://foundation.zurb.com/docs/components/abide.htmlI added to the bottom list of scripts in main.php<script src="{$STORE_URL}/skins/{$SKIN_FOLDER}/js/foundation/foundation.js"></script> (wasn't sure if this was needed or not)<script src="{$STORE_URL}/skins/{$SKIN_FOLDER}/js/foundation.abide.js"></script>By changing element.product_reviews.php so the form is<form data-abide action="{$VAL_SELF}#reviews_write" id="review_form" method="post">with the required attribute you had already triedĀ <input type="radio" id="rating_{$star.value}" name="rating" value="{$star.value}" class="rating" required {$star.checked}>The Submit button will not work now unless at least one star is clicked.I tried adding an error message, using the sample on the zurb page linked above, but what I tried didn't work. Maybe something needs to be added to foundation.abide.js??? That's all that is missing now for a really useful Rating. <div class="row"> <div class="small-12 columns" id="review_stars"> <label for="rating"><span class="redbold">{$LANG.documents.rating} {$LANG.form.required} </span></label> {foreach from=$RATING_STARS item=star} <input type="radio" id="rating_{$star.value}" name="rating" value="{$star.value}" class="rating" required {$star.checked}> {/foreach} <small class="error">Star rating is required for a Review</small> </div>Ā Ā Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 20, 2015 Share Posted May 20, 2015 "CC v6 already has a plugin called Abide"Not in my copy of CC604. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 20, 2015 Author Share Posted May 20, 2015 Hmmm. I originally downloaded a customized version from zurb, so I wouldn't have to make as many cosmetic changes. Well, at least I have it LOL But it definitely requires the stars. All I need is the error message, and it will be perfect. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 20, 2015 Author Share Posted May 20, 2015 (edited) Just figured out the error message part.I'm now using version 5.5.2 of foundation.css and Abide, with all my cosmetic changes to foundation in place.What was missing was a way to tell Abide that an error message was needed. The error text had already been added, but was not showing. So I looked at 3.cubecart.validate.js and copied the format of existing error message validations.// BSMITHER ADDED REQUIRE STAR VALUE $("#review_form").validate({ rules: { 'review[name]': { required: true }, 'rating': { required: true }, 'review[review]': { required: true }, 'review[title]': { required: true }, 'review': { required: true, email: true } }, messages: { 'review': { required: $('#validate_email').text(), review: $('#validate_email').text() } 'rating':{ required: $('#validate_rating'),number(), } } }); Ā The required rating section does NOT work properly with 6.0.5 - it causes an errant validation error on checkout.confirm.php. 6.0.5 includes a fix for required reviews.Ā Edited June 1, 2015 by Dirty Butter code addition not needed for 6.0.5 Quote Link to comment Share on other sites More sharing options...
Al Brookbanks Posted May 22, 2015 Share Posted May 22, 2015 This is a tricky little one isn't it?! I'm trying to get jquery validate to do its stuff but as you have both found its not playing ball.Ā Quote Link to comment Share on other sites More sharing options...
Al Brookbanks Posted May 22, 2015 Share Posted May 22, 2015 Would it not be best to default the rating to one star? That seems like the obvious and easy fix? Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 22, 2015 Author Share Posted May 22, 2015 The only problem with that is that the same people who would skipĀ a rating on a review would be the ones who left the one as is. Since Ratings are part of the Google algorithm, that would not be helpful IMHO. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted June 1, 2015 Author Share Posted June 1, 2015 Version 6.0.5 does NOT require the Validation code added - it actually causes a major issue with checkout, as it throws an errant validation error message. Will edit appropriate comment. 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.