Jump to content

Recommended Posts

  • Replies 70
  • Created
  • Last Reply

Top Posters In This Topic

"You said you needed to fix this anyway, because it created a division by zero for a product that had only one unstarred review."

The edit you made to line 322, undo that. We will try something else.

Link to post
Share on other sites

OK. I'll undo the line 322 edit. I did find this discussion on the jQuery help forum that seems to be about the Require Stars issue. Perhaps the discussion will give you some ideas, perhaps not.

http://forum.jquery.com/topic/jquery-star-rating-plugin-not-working

.... Besides that, do you have a solution to make the stars required? in that way that if people forget to choose a rating they get a warning? At original 'input' buttons are 'required', but for some reason this javascript does not listen to that.....

 

...Unless you are using some plugin to ensure "required" really works, You would need to loop through the inputs checking to see that one input is checked for each name. I would do that check in a submit handler for the form....

 

Link to post
Share on other sites

I have made edits to the Catalogue class file that will not include any zero-starred reviews in the average calculations.

Still to do is to decide and implement:

* Include the zero-star indicator in a listed review, or blank the indicator
* Change/delete the "X average, based on Y reviews" phrase seen near the item price

One could argue that a zero-starred 'review' is actually a "comment", provided we make pplain that not awarding any stars is "allowed", but will not be deemed a review.

Code edits to follow.

Link to post
Share on other sites

Because I've only tested allowing Reviews off and on briefly, I don't have that many without stars. BUT I do NOT want to allow them on a permanent basis unless the average excludes unstarred reviews, or if stars are required. I did make a GitHub request of this, as I'm hoping CC will find a way to require the stars.

As for your still to decide points:

Maybe Reviews could be changed to Comments/Reviews. Then it would make sense to leave the stars off the Comments and just use the Review stars for the math.

Then the phrasing for "X average, based on Y reviews" may be find as is.

Link to post
Share on other sites

In the file catalogue.class.php, original lines 318-342:

				// 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) {
						$review_count = (int)$paginate[0]['Count'];
						$review_score = $paginate[0]['Score'];
						$GLOBALS['smarty']->assign('PAGINATION', $GLOBALS['db']->pagination($review_count, $per_page, $page));
					}
					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', round($review_score/$review_count, 1));
				}

Replace all of that with:

				// 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', array('rating'), array('product_id' => (int)$product['product_id'], 'approved' => '1'))) !== 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' );
				}

Then, original lines 1321-1331:

			foreach ($reviews as $review) {
				$score += $review['rating'];
				$count++;
			}
			$product['review_score'] = round($score/$count, 1);
			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);

Replace with:

			foreach ($reviews as $review) { 
				if ($review['rating'] > 0) {
					$score += $review['rating'];
					$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';

As I said earlier, we may need to experiment with adjusting the language phrases.

The "still to decide" points are not incorporated here.

Link to post
Share on other sites

Ok, then this is catalogue.class.php (original lines 1321-1331).

The only thing I can think of is this group of statements:

if ($review['rating'] > 0) { // rating must be greater than zero
	$score += $review['rating']; // add rating into score tally
	$count++; // add one to count tally
}

Check to make sure that after $score, it is plus-equal operator.

Link to post
Share on other sites

Well, I see it too. And it's a "calculate at run-time" equation, so it can't be because of a cache issue.

This group of statements populates either Smarty's {$LANG_REVIEW_INFO} in View Product, or assigns data to $product['review_info'] in View Category, using sprintf($GLOBALS['language']->catalogue['review_info'], $score, $count, $link) as the phrase template. I think the next logical place to check is the phrase template, although I've not known a phrase template to actually change any values.

Link to post
Share on other sites

I added a one star test review to the Berengeur doll, and just as I suspected it divided the AVERAGE RATING by 3 at the top of the Product Listing and on the Category Listing. It should have used the SCORE TOTAL 11 stars divided by 3. I can comment out the Average line on Product for now, and all the rating stuff on Category, unless you have more ideas to try.

Link to post
Share on other sites

Use this version of the edits made near lines 1321-1331:

            foreach ($reviews as $review) { 
                if ($review['rating'] > 0) { trigger_error('There is a $review[\'rating\']: '.$review['rating']);
                    $score += $review['rating'];
                    $count++; 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'; trigger_error('After rounding, $score is '.$score);

We have added some trigger_error() calls to log the values at key points in the code.

Link to post
Share on other sites

I didn't do anything - customers or you - but this is in the log now:

[16-May-2015 11:22:49 America/Chicago] PHP Notice:  There is a $review['rating']: 5.0 in /home3/butter01/public_html/plushcatalog/classes/catalogue.class.php on line 1418
[16-May-2015 11:22:49 America/Chicago] PHP Notice:  Now, $score is 5 and $count is 1 in /home3/butter01/public_html/plushcatalog/classes/catalogue.class.php on line 1420
[16-May-2015 11:22:49 America/Chicago] PHP Notice:  After rounding, $score is 5.0 in /home3/butter01/public_html/plushcatalog/classes/catalogue.class.php on line 1429
[16-May-2015 11:22:49 America/Chicago] PHP Notice:  There is a $review['rating']: 2.0 in /home3/butter01/public_html/plushcatalog/classes/catalogue.class.php on line 1418
[16-May-2015 11:22:49 America/Chicago] PHP Notice:  Now, $score is 2 and $count is 1 in /home3/butter01/public_html/plushcatalog/classes/catalogue.class.php on line 1420
[16-May-2015 11:22:49 America/Chicago] PHP Notice:  After rounding, $score is 2.0 in /home3/butter01/public_html/plushcatalog/classes/catalogue.class.php on line 1429
[16-May-2015 11:28:08 America/Chicago] PHP Notice:  After rounding, $score is null in /home3/butter01/public_html/plushcatalog/classes/catalogue.class.php on line 1429
[16-May-2015 11:28:08 America/Chicago] PHP Warning:  Division by zero in /home3/butter01/public_html/plushcatalog/classes/catalogue.class.php on line 1438

[16-May-2015 11:38:01 America/Chicago] PHP Warning:  Division by zero in /home3/butter01/public_html/plushcatalog/classes/catalogue.class.php on line 1438
[16-May-2015 11:38:27 America/Chicago] PHP Warning:  Invalid argument supplied for foreach() in /home3/butter01/public_html/plushcatalog/classes/ajax.class.php on line 133

 

Line 1418 is      if ($review['rating'] > 0) { trigger_error('There is a $review[\'rating\']: '.$review['rating']);

Line 1420 is       $count++; trigger_error('Now, $score is '.$score.' and $count is '.$count);

Line 1429 is       $score = ($product['review_score']) ? number_format($product['review_score'],1) : 'null'; trigger_error('After rounding, $score is '.$score);

Line 1438 is        $score = number_format(($score/$count), 1);

 

Link to post
Share on other sites

Maybe your site is being visited by others. I suppose I need to make the triggers happen only on a specific product.

So, for every trigger_error that was added (three of them, insert this directly in front of it:

if((int)$product['product_id'] = 3150)

This will trigger errors only on the Sucky Face item.

Link to post
Share on other sites

I am not liking the error message saying a division by zero in line 1438. That tells me you may not have properly commented out the original statements in that area that I instructed to be replaced.

Link to post
Share on other sites

I just searched for sucky, as that's the only doll we have had with that face.

[16-May-2015 12:12:49 America/Chicago] PHP Notice:  There is a $review['rating']: 5.0 in /home3/butter01/public_html/plushcatalog/classes/catalogue.class.php on line 1418
[16-May-2015 12:12:49 America/Chicago] PHP Notice:  Now, $score is 5 and $count is 1 in /home3/butter01/public_html/plushcatalog/classes/catalogue.class.php on line 1420
[16-May-2015 12:12:49 America/Chicago] PHP Notice:  There is a $review['rating']: 5.0 in /home3/butter01/public_html/plushcatalog/classes/catalogue.class.php on line 1418
[16-May-2015 12:12:49 America/Chicago] PHP Notice:  Now, $score is 10 and $count is 2 in /home3/butter01/public_html/plushcatalog/classes/catalogue.class.php on line 1420
[16-May-2015 12:12:49 America/Chicago] PHP Notice:  After rounding, $score is 5.0 in /home3/butter01/public_html/plushcatalog/classes/catalogue.class.php on line 1429

5 stars are showing on the Category page, but "2.5 average, based on 2 reviews"

Then I opened the actual product page.

[16-May-2015 12:15:34 America/Chicago] PHP Notice:  There is a $review['rating']: 5.0 in /home3/butter01/public_html/plushcatalog/classes/catalogue.class.php on line 1418
[16-May-2015 12:15:34 America/Chicago] PHP Notice:  Now, $score is 5 and $count is 1 in /home3/butter01/public_html/plushcatalog/classes/catalogue.class.php on line 1420
[16-May-2015 12:15:34 America/Chicago] PHP Notice:  There is a $review['rating']: 5.0 in /home3/butter01/public_html/plushcatalog/classes/catalogue.class.php on line 1418
[16-May-2015 12:15:34 America/Chicago] PHP Notice:  Now, $score is 10 and $count is 2 in /home3/butter01/public_html/plushcatalog/classes/catalogue.class.php on line 1420
[16-May-2015 12:15:34 America/Chicago] PHP Notice:  After rounding, $score is 5.0 in /home3/butter01/public_html/plushcatalog/classes/catalogue.class.php on line 1429


same 5 stars with 2.5 average

 

Link to post
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...