Jump to content

Need help with some tweaks


Dirty Butter

Recommended Posts

  • Replies 70
  • Created
  • Last Reply

Top Posters In This Topic

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

Ā 

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

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

Link to comment
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;
		}

Ā 

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

Ā 

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

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

Link to comment
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) {

Ā 

Link to comment
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>

Ā 

Ā 

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

Ā 

Edited by Dirty Butter
code addition not needed for 6.0.5
Link to comment
Share on other sites

  • 2 weeks later...

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