Jump to content

Archived

This topic is now archived and is closed to further replies.

Dirty Butter

Need help with some tweaks

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
Share on other sites

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 1429

Note 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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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;
		}

 

Share this post


Link to post
Share on other sites

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']);

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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) {

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.html

I 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>

 

 

Share this post


Link to post
Share on other sites

"CC v6 already has a plugin called Abide"

Not in my copy of CC604.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

 

Share this post


Link to post
Share on other sites

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. 

Share this post


Link to post
Share on other sites

Would it not be best to default the rating to one star? That seems like the obvious and easy fix?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

×
×
  • Create New...