{"id":4207,"date":"2017-12-03T22:58:27","date_gmt":"2017-12-04T04:58:27","guid":{"rendered":"https:\/\/justinparrtech.com\/JustinParr-Tech\/?p=4207"},"modified":"2017-12-28T22:43:25","modified_gmt":"2017-12-29T04:43:25","slug":"zen-cart-javascript-css-star-rating-system","status":"publish","type":"post","link":"https:\/\/justinparrtech.com\/JustinParr-Tech\/zen-cart-javascript-css-star-rating-system\/","title":{"rendered":"Zen Cart &#8211; Javascript + CSS Star Rating System"},"content":{"rendered":"<p>The default star rating system in zen cart, for registered users who post a review, is less than spectacular.<\/p>\n<p>Here is how to fix it with CSS + Javascript<\/p>\n<p>Read on&#8230;<\/p>\n<p>&nbsp;<\/p>\n<p><!--more--><\/p>\n<h2>Applies To:<\/h2>\n<p>Zen Cart 1.5.5<\/p>\n<p>&nbsp;<\/p>\n<h2>Step 1:\u00a0 Modify Your Template Style Sheet<\/h2>\n<p>Add the following to <span style=\"text-decoration: underline;\">the end of<\/span> your <strong>stylesheet.css<\/strong>, located in:<br \/>\n<strong>\/YourSite\/includes\/templates\/YourTemplate\/css<\/strong><\/p>\n<pre>\/* \r\n------------------------------- \r\n5 Star Rating CSS\r\n-------------------------------\r\n*\/\r\n\r\n\r\n\/* Base Style *\/\r\n.ratingRow \r\n{\r\n    border-style: none;\r\n    cursor:pointer;\r\n}\r\n\r\n\/* Hide star images and actual input elements *\/\r\n.ratingRow img, .ratingRow input\r\n{\r\n    display:none; \r\n    visible:no;\r\n}\r\n\r\n\/* Label Style *\/\r\n.ratingRow:not(:checked) &gt; label \r\n{\r\n    padding:0;\r\n    font-size:200%;\r\n    line-height:1.2;\r\n    color:#cccccc;\r\n    text-shadow: 1px 1px 0 #CFB53B;\r\n    transition:all 0.5s ease;\r\n}\r\n\r\n\/* Create a 5-point star before each label *\/\r\n.ratingRow &gt; label:before \r\n{\r\n content: '\\2605';\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<h2>Step 2:\u00a0 Modify the Review Template<\/h2>\n<p>Add the highlighted lines to the <span style=\"text-decoration: underline;\">beginning of<\/span> your review template.<\/p>\n<p>Modify <strong>tpl_product_reviews_write_default.php<\/strong> located in:<br \/>\n<strong>YourSite\/includes\/templates\/responsive_classic_mod\/templates<\/strong><\/p>\n<pre>&lt;?php\r\n\/**\r\n * Page Template\r\n *\r\n * @package templateSystem\r\n * @copyright Copyright SomeStuff\r\n * @copyright Portions Copyright SomeStuff\r\n * @license SomeStuff\r\n * @version SomeStuff\r\n *\/\r\n?&gt;\r\n\r\n<span style=\"color: #00ff00;\">&lt;script type=text\/javascript&gt;&lt;!--\r\nfunction zzmouse(zzhov) {\r\n    for (i = 1; i &lt; 6; i++) {\r\n        var zzlbl=document.getElementById(\"zz\"+i);\r\n\r\n        if (i&lt;=zzhov) {\r\n            zzlbl.style.color=\"#FFDF00\";\r\n        } else {\r\n            zzlbl.style.color=\"#cccccc\";\r\n        }\r\n    } \r\n}\r\n\r\nfunction zzmouseout() {\r\n    var zzhov=0;\r\n\r\n    for (i=1; i &lt; 6; i++) {\r\n        var zzele=document.getElementById(\"rating-\"+i);\r\n        if (zzele.checked) zzhov=i;\r\n    }\r\n\r\n    zzmouse(zzhov);\r\n}\r\n--&gt;&lt;\/script&gt;<\/span><\/pre>\n<p>&nbsp;<\/p>\n<h2>Step 3: Modify the Form Option Elements in the Review Template<\/h2>\n<p>Modify <strong>tpl_product_reviews_write_default.php<\/strong> located in:<br \/>\n<strong>YourSite\/includes\/templates\/responsive_classic_mod\/templates<\/strong><\/p>\n<p>Locate the indicated lines, and add the indicated code.<\/p>\n<pre>&lt;div class=\"ratingRow\"&gt;\r\n&lt;?php echo zen_draw_radio_field('rating', '1', '', 'id=\"rating-1\"'); ?&gt;\r\n&lt;?php echo '&lt;label class=\"\" <span style=\"color: #00ff00;\">id=\"zz1\"<\/span> for=\"rating-1\" <span style=\"color: #00ff00;\">onmouseover=\"zzmouse(1)\" onmouseout=\"zzmouseout()\"<\/span>&gt;' . zen_image($template-&gt;get_template_dir(OTHER_IMAGE_REVIEWS_RATING_STARS_ONE, DIR_WS_TEMPLATE, $current_page_base,'images'). '\/' . OTHER_IMAGE_REVIEWS_RATING_STARS_ONE, OTHER_REVIEWS_RATING_STARS_ONE_ALT) . '&lt;\/label&gt; '; ?&gt;\r\n\r\n&lt;?php echo zen_draw_radio_field('rating', '2', '', 'id=\"rating-2\"'); ?&gt;\r\n&lt;?php echo '&lt;label class=\"\" <span style=\"color: #00ff00;\">id=\"zz2\"<\/span> for=\"rating-2\" <span style=\"color: #00ff00;\">onmouseover=\"zzmouse(2)\" onmouseout=\"zzmouseout()\"<\/span>&gt;' . zen_image($template-&gt;get_template_dir(OTHER_IMAGE_REVIEWS_RATING_STARS_TWO, DIR_WS_TEMPLATE, $current_page_base,'images'). '\/' . OTHER_IMAGE_REVIEWS_RATING_STARS_TWO, OTHER_REVIEWS_RATING_STARS_TWO_ALT) . '&lt;\/label&gt;'; ?&gt;\r\n\r\n&lt;?php echo zen_draw_radio_field('rating', '3', '', 'id=\"rating-3\"'); ?&gt;\r\n&lt;?php echo '&lt;label class=\"\" <span style=\"color: #00ff00;\">id=\"zz3\"<\/span> for=\"rating-3\" <span style=\"color: #00ff00;\">onmouseover=\"zzmouse(3)\" onmouseout=\"zzmouseout()\"<\/span>&gt;' . zen_image($template-&gt;get_template_dir(OTHER_IMAGE_REVIEWS_RATING_STARS_THREE, DIR_WS_TEMPLATE, $current_page_base,'images'). '\/' . OTHER_IMAGE_REVIEWS_RATING_STARS_THREE, OTHER_REVIEWS_RATING_STARS_THREE_ALT) . '&lt;\/label&gt;'; ?&gt;\r\n\r\n&lt;?php echo zen_draw_radio_field('rating', '4', '', 'id=\"rating-4\"'); ?&gt;\r\n&lt;?php echo '&lt;label class=\"\" <span style=\"color: #00ff00;\">id=\"zz4\"<\/span> for=\"rating-4\" <span style=\"color: #00ff00;\">onmouseover=\"zzmouse(4)\" onmouseout=\"zzmouseout()\"<\/span>&gt;' . zen_image($template-&gt;get_template_dir(OTHER_IMAGE_REVIEWS_RATING_STARS_FOUR, DIR_WS_TEMPLATE, $current_page_base,'images'). '\/' . OTHER_IMAGE_REVIEWS_RATING_STARS_FOUR, OTHER_REVIEWS_RATING_STARS_FOUR_ALT) . '&lt;\/label&gt;'; ?&gt;\r\n\r\n&lt;?php echo zen_draw_radio_field('rating', '5', '', 'id=\"rating-5\"'); ?&gt;\r\n&lt;?php echo '&lt;label class=\"\" <span style=\"color: #00ff00;\">id=\"zz5\"<\/span> for=\"rating-5\" <span style=\"color: #00ff00;\">onmouseover=\"zzmouse(5)\" onmouseout=\"zzmouseout()\"<\/span>&gt;' . zen_image($template-&gt;get_template_dir(OTHER_IMAGE_REVIEWS_RATING_STARS_FIVE, DIR_WS_TEMPLATE, $current_page_base,'images'). '\/' . OTHER_IMAGE_REVIEWS_RATING_STARS_FIVE, OTHER_REVIEWS_RATING_STARS_FIVE_ALT) . '&lt;\/label&gt;'; ?&gt;\r\n&lt;\/div&gt;<\/pre>\n<p>&nbsp;<\/p>\n<h2>Why?<\/h2>\n<p>The default user experience is a bunch of radio buttons, each with an image of the corresponding &#8220;star&#8221; rating.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4211\" src=\"https:\/\/justinparrtech.com\/JustinParr-Tech\/wp-content\/uploads\/DefaultExperience.png\" alt=\"\" width=\"493\" height=\"416\" srcset=\"https:\/\/justinparrtech.com\/JustinParr-Tech\/wp-content\/uploads\/DefaultExperience.png 493w, https:\/\/justinparrtech.com\/JustinParr-Tech\/wp-content\/uploads\/DefaultExperience-300x253.png 300w\" sizes=\"auto, (max-width: 493px) 100vw, 493px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Most users are conditioned by large online sites to expect a more simplified user experience, where the user is simply presented with 5 empty stars, and they can click the particular star to record their &#8220;star rating&#8221;.\u00a0 In addition, the star functionality includes behavior that allows the user to hover over a particular star, and be provided visual feedback.<\/p>\n<p>Here is the enhanced user experience:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4212\" src=\"https:\/\/justinparrtech.com\/JustinParr-Tech\/wp-content\/uploads\/EnhancedExperience.png\" alt=\"\" width=\"470\" height=\"430\" srcset=\"https:\/\/justinparrtech.com\/JustinParr-Tech\/wp-content\/uploads\/EnhancedExperience.png 470w, https:\/\/justinparrtech.com\/JustinParr-Tech\/wp-content\/uploads\/EnhancedExperience-300x274.png 300w\" sizes=\"auto, (max-width: 470px) 100vw, 470px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Enhanced Functionality:<\/p>\n<ul>\n<li>Hides the label, image, and radio button, and replaces it with a 5-point star symbol<\/li>\n<li>Hovering over a star fills each star to the left in gold, including the hover star<\/li>\n<li>Clicking a star results in each star to the left of the selected star being filled in gold, including the selected star<\/li>\n<li>Internally, this sets the &#8216;rating&#8217; form field<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2>Why isn&#8217;t this posted on Zen-Cart&#8217;s Forum?<\/h2>\n<p>BECAUSE I COULD NOT, FOR THE LIFE OF ME, FIGURE OUT WHERE TO POST IT.<\/p>\n<p>AND, I DON&#8217;T HAVE TIME TO SCREW AROUND TRYING TO FIGURE OUT A BUNCH OF FORUM RULES<\/p>\n<p>I applaud the efforts of the zen-cart folks, and the moderators, but seriously, I signed up, I have a login, but I can&#8217;t post anything?\u00a0 Really?<\/p>\n<p><strong>I googled multiple times for a suitable answer, and in the end, I had to create my own.\u00a0 So here it is.\u00a0 You&#8217;re welcome to use it.<\/strong><\/p>\n<pre><\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The default star rating system in zen cart, for registered users who post a review, is less than spectacular. Here is how to fix it with CSS + Javascript Read on&#8230; &nbsp;<\/p>\n","protected":false},"author":16,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24],"tags":[],"class_list":["post-4207","post","type-post","status-publish","format-standard","hentry","category-zen-cart-stuff"],"_links":{"self":[{"href":"https:\/\/justinparrtech.com\/JustinParr-Tech\/wp-json\/wp\/v2\/posts\/4207","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/justinparrtech.com\/JustinParr-Tech\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/justinparrtech.com\/JustinParr-Tech\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/justinparrtech.com\/JustinParr-Tech\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/justinparrtech.com\/JustinParr-Tech\/wp-json\/wp\/v2\/comments?post=4207"}],"version-history":[{"count":5,"href":"https:\/\/justinparrtech.com\/JustinParr-Tech\/wp-json\/wp\/v2\/posts\/4207\/revisions"}],"predecessor-version":[{"id":4214,"href":"https:\/\/justinparrtech.com\/JustinParr-Tech\/wp-json\/wp\/v2\/posts\/4207\/revisions\/4214"}],"wp:attachment":[{"href":"https:\/\/justinparrtech.com\/JustinParr-Tech\/wp-json\/wp\/v2\/media?parent=4207"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/justinparrtech.com\/JustinParr-Tech\/wp-json\/wp\/v2\/categories?post=4207"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/justinparrtech.com\/JustinParr-Tech\/wp-json\/wp\/v2\/tags?post=4207"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}