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 use Department email addresses, so I can route admin mail into different Outlook folders, based on the purpose for the message. How can I make choosing a Department required in content.contact.php?

Also, either Require stars on a Review (preferred), or have CC calculate the overall star rating on only reviews WITH at least one star. (I've already modified element.product_reviews.php so only logged in Users can leave reviews.)

Share this post


Link to post
Share on other sites

It seems to me that adding to the existing javascript in 3.cubecart.validate.js near lines 72-94 should suffice. Then add {$LANG.form.required} to the <select> tag in content.contact.php.

 

Share this post


Link to post
Share on other sites

I thought whatever you suggested might work on other skins, so I didn't specify. But if it takes 3.cubecart.validate.js - yes, Foundation.

Share this post


Link to post
Share on other sites

You might think that. In Foundation's js/vendor/, there is jquery.validate.js, which is not in the /js/plugins/ folder that CC5 skins use.

Any validation for non-Foundation skins would need enhancing the existing CC5 skin method, or the method(s) employed by third-party skins.

Try this (as I haven't tried it myself yet):

Find:
    $("#contact_form").validate({
        rules: {
            'contact[subject]': {
                required: true
            },

Add After:
            'contact[dept]': {
                required: true
            },

What I do not know is how the Validator plugin "validates" a drop-down selector. Does it deem a value="" (which is the "--Please select--" option) as being invalid? We'll see.

Then, in the template:

Find:
            <label for="contact_dept">{$LANG.common.department}</label>

Change to:
            <label for="contact_dept">{$LANG.common.department} {$LANG.form.required}</label>

 

Share this post


Link to post
Share on other sites

The Validator handled the Select properly. Thank you!

As for requiring star rating, I added this to 3.validator.js after name in $("#review_form").validate({:

            'review[rating]': {
            required: true
            },

I also tried [star.value], and [star.checked] but nothing caused the validator to throw the error message.

Share this post


Link to post
Share on other sites

In the file 2.cubecart.js, near line 69, there is a function that (supposedly) already pins a 'required' attribute to radio inputs having class="rating".

So check that the template's /js/vendor/jquery.rating.min.js is present.

There are so many "star rating" plugins available, I can't determine which one CubeCart is actually using.

I'm thinking that, maybe, the rating() function provided by the plugin changes the array of radio selectors to something else entirely.

Plus, the form element name seems to be just "rating" and not "review[rating]" as you are trying to use. So, aside from what I just said above, try just

'rating': {required:true },

Share this post


Link to post
Share on other sites

Not working yet

jquery.rating.min.js is present

2.cubecart.js has the function you referred to.

element.product_reviews.php now has
 

 <label for="rating">{$LANG.documents.rating}  {$LANG.form.required}</label>
                  {foreach from=$RATING_STARS item=star}
                  <input type="radio" id="rating_{$star.value}" name="rating" value="{$star.value}" class="rating" {$star.checked}>
                  {/foreach}

3.cubecart.validate.js now has

  $("#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()
            }
        }
    });

Maybe this is a bug?

Share this post


Link to post
Share on other sites

Let's try this.

Remove the following, what you recently added) from 3.cubecart.validate.js:

'rating': {
	required: true
},

In element.product_reviews.php:

Change:
<input type="radio" id="rating_{$star.value}" name="rating" value="{$star.value}" class="rating" {$star.checked}>

To:
<input type="radio" id="rating_{$star.value}" name="rating" value="{$star.value}" class="rating required" {$star.checked}>

 

Share this post


Link to post
Share on other sites

The plugin being used may be this one: https://www.fyneworks.com/jquery/star-rating/

If so, the required: true parameter in 2.cubecart.js means that the plugin will not add a "clear" option. That is, the only option is to pick 1 to 5 stars, but this is not where the validation is done to make sure something was picked.

So, the edit to element.product_reviews.php will be ineffective at validating a choice has been made.

Back to square one!

You could try making the radio group required this way:

Change:
<input type="radio" id="rating_{$star.value}" name="rating" value="{$star.value}" class="rating" {$star.checked}>

To:
<input type="radio" id="rating_{$star.value}" name="rating" value="{$star.value}" class="rating" required {$star.checked}>

And also, a few lines up:

Change:
<label for="rating">{$LANG.documents.rating}</label>

To:
<label for="rating">{$LANG.documents.rating} {$LANG.form.required}</label>

 

Share this post


Link to post
Share on other sites

Nope That didn't work, either. The rating plugin changes all the:

<input id="rating_1" class="rating star-rating-applied" type="radio" required="" value="1" name="rating" style="display: none;" aria-required="true">

Into:

<div id="rating_1" class="star-rating rater-0 rating star-rating-applied star-rating-live" aria-label="" role="text">
  <a title="1">1</a>
</div>

Note the display:none on the original <input> tag. Generally, you can't enforce a required status on a hidden form element.

Share this post


Link to post
Share on other sites

Well, if that's not going to work, how about the original less desirable alternative - make the overall rating use only reviews that actually DID give it a star rating?

Share this post


Link to post
Share on other sites

Just noticed the review file uses zero as the worst rating possible. It really should be ONE, don't you think? That would solve this issue. Nope, changing worst to one did not fix it.

What about taking off the hide class?

{if $IS_USER}
   <div id="review_write" class="hide">
      <h3>{$LANG.catalogue.write_review}</h3>

Share this post


Link to post
Share on other sites

Personally, I sort of agree, but I also think otherwise.

Personally, I am inclined to want a red to green scale with actual values from a negative starting point -- depending. And another rating scale for the overall shopping experience.

It depends on the product. It depends on what the customer is wanting to express/rate. (Having once worked for a psychology PhD who specializes in written test design, one cannot simply plop an ambiguous 1-5 rating scale in front of someone and expect a coherent analysis.)

Therefore, I would actually forego the built-in 1-5 rating thing and plan/implement a coherent survey package at Survey Monkey -- that is, if I really wanted to understand my customer's thoughts about my store and products offered.

The built-in rating is a trade-off of customer convenience against a richer understanding of my customer base and their perception of my business.

Share this post


Link to post
Share on other sites

Let me find the code that computes the "score" of the rating, and I'll get back to this.

Share this post


Link to post
Share on other sites

I have not allowed Reviews much, as customers use it for all sorts of purposes - just what you're saying about customer psychology. For instance, the one I'm using as a test was asking for help finding an out of stock toy, as she loved it so much - with no stars marked of course.

Share this post


Link to post
Share on other sites

We can adjust the query to return only reviews that have a rating greater than zero. That might miss some interesting reviews.

Or, return all (approved) reviews, but adjust the count later to be only those reviews with a score greater than zero. That might cause some consternation by those who inherently grok the math.

 

Share this post


Link to post
Share on other sites

Since Google uses Overall Rating in its algorithm, the best answer would require stars. Since that doesn't seem to be possible, the second best, IMHO, would be to calculate the Overall Rating for 1 to 5 stars, ignoring the zero stars. It should be possible to reword Overall Rating in Languages to indicate it's based on reviews with ratings.

Share this post


Link to post
Share on other sites

Try in /classes/catalogue.class.php near line 322:

From:
if (($paginate = $GLOBALS['db']->select('CubeCart_reviews', 'SUM(`rating`) AS Score, COUNT(`id`) as Count', array('approved' => 1, 'product_id' => $product['product_id']))) !== false) {

To:
if (($paginate = $GLOBALS['db']->select('CubeCart_reviews', 'SUM(`rating`) AS Score, COUNT(`id`) as Count', array('rating' => '>0', 'approved' => 1, 'product_id' => $product['product_id']))) !== false) {

 

Share this post


Link to post
Share on other sites

That works for items with at least one starred review. But if the ONLY review does not have stars, it still shows zero rating.

Share this post


Link to post
Share on other sites

In fact, if there are no reviews with at least a score of 1, then the count will be zero and the formula for average is score/count, or X/0, which will crash PHP.

So, I need to adjust that.

"If the ONLY review does not have stars, it still shows zero rating."

What do you want to do about it?

Share this post


Link to post
Share on other sites

Can it say None Rated, instead of showing the zero? I left the (Required) wording by the stars on the Review form, hoping it would increase the number who use the stars, even though there is no error message if they don't, and the review completes.

Share this post


Link to post
Share on other sites

This looks better to me:

 <p class="pagination_top"><span class="pagination">{if isset($PAGINATION)}{$PAGINATION}{/if}</span>{$LANG.catalogue.average_rating}: <strong>{if {$REVIEW_AVERAGE}==0} None Rated {else}{$REVIEW_AVERAGE}</strong>{/if} </p>
    

And I changed Language>Catalogue>Average Rating for Reviews with Stars

Share this post


Link to post
Share on other sites

And there still might be something just above the product price. This is a complete phrase - not something that can be tested for.

In content.product.php near lines 88-101. Begins with <p itemprop>. So, you might want to wrap that in a test to suppress {if $PRODUCT.review_score == 0}.

 

Share this post


Link to post
Share on other sites

The no star reviews don't cause a problem on the category page, but the unstarred reviews behave as they did originally. They show up in the Count. You said you needed to fix this anyway, because it created a division by zero for a product that had only one unstarred review.

	// ORIGINAL REPLACED WITH BSMITHER TO NOT INCLUDE NO STARS REVIEW IN CALCULATION if (($paginate = $GLOBALS['db']->select('CubeCart_reviews', 'SUM(`rating`) AS Score, COUNT(`id`) as Count', array('approved' => 1, 'product_id' => $product['product_id']))) !== false) {
	if (($paginate = $GLOBALS['db']->select('CubeCart_reviews', 'SUM(`rating`) AS Score, COUNT(`id`) as Count', array('rating' => '>1', 'approved' => 1, 'product_id' => $product['product_id']))) !== false) {					

This is getting so complicated!! It really would be so much better if there were some way to require stars! Perhaps there is another Foundation review plugin available that would have already solved this issue? I'm going to do a little searching on Zurb.

Share this post


Link to post
Share on other sites

×
×
  • Create New...