Dirty Butter Posted May 11, 2015 Share Posted May 11, 2015 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.) Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 11, 2015 Share Posted May 11, 2015 I assume you are wanting this for Foundation? Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 11, 2015 Share Posted May 11, 2015 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. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 11, 2015 Author Share Posted May 11, 2015 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. Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 11, 2015 Share Posted May 11, 2015 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> Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 12, 2015 Author Share Posted May 12, 2015 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. Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 12, 2015 Share Posted May 12, 2015 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 }, Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 12, 2015 Author Share Posted May 12, 2015 Not working yetjquery.rating.min.js is present2.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? Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 13, 2015 Share Posted May 13, 2015 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}> Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 13, 2015 Share Posted May 13, 2015 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> Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 13, 2015 Share Posted May 13, 2015 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. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 13, 2015 Author Share Posted May 13, 2015 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? Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 13, 2015 Author Share Posted May 13, 2015 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> Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 13, 2015 Share Posted May 13, 2015 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. Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 13, 2015 Share Posted May 13, 2015 Let me find the code that computes the "score" of the rating, and I'll get back to this. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 13, 2015 Author Share Posted May 13, 2015 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. Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 13, 2015 Share Posted May 13, 2015 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. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 13, 2015 Author Share Posted May 13, 2015 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. Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 13, 2015 Share Posted May 13, 2015 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) { Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 13, 2015 Author Share Posted May 13, 2015 That works for items with at least one starred review. But if the ONLY review does not have stars, it still shows zero rating. Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 13, 2015 Share Posted May 13, 2015 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? Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 13, 2015 Author Share Posted May 13, 2015 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. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 13, 2015 Author Share Posted May 13, 2015 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 Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 13, 2015 Share Posted May 13, 2015 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}. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 13, 2015 Author Share Posted May 13, 2015 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. 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.