Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 34
  1. #21
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Adding Product Rating on Product Listing Page

    Looks really good you did a great job!
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today: v1.5.5]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  2. #22
    Join Date
    Apr 2009
    Location
    Oxford UK
    Posts
    192
    Plugin Contributions
    0

    Default Re: Adding Product Rating on Product Listing Page

    Since this seems to be the only thread about this mod i have a question about it,

    I would like to NOT show the mod if there are no reviews i.e

    http://www.gloopy.co.uk/ps2-games/ps...rmula-1-06-ps2

    it says "Average Rating: 0 0 of 5 Stars!" which could be misleading to customers that this is a bad game or product.

    so with this code

    <?php // 2P modified BOF - Average Product Rating
    // echo '<p class="reviewCount">';
    if ($flag_show_product_info_reviews_count == 1) {
    //echo TEXT_CURRENT_REVIEWS . ' <strong>' . $reviews->fields['count'] . '</strong><br />';
    $stars_image_suffix = str_replace('.', '_', zen_round($reviews_average_rating->fields['average_rating'] * 2, 0) / 2); // for stars_0_5.gif, stars_1.gif, stars_1_5.gif etc.
    $average_rating = zen_round($reviews_average_rating->fields['average_rating'], 2);
    echo TEXT_CURRENT_REVIEWS_RATING . ' <strong>' . $average_rating . '</strong> ' . zen_image(DIR_WS_TEMPLATE_IMAGES . 'stars_' . $stars_image_suffix . '.gif', sprintf(BOX_REVIEWS_TEXT_OF_5_STARS, $average_rating));
    } else {
    echo '';
    }
    echo '</p>';
    // 2P modified EOF - Average Product Rating ?>


    what would i add to tell it not to show if there are no reviews.

    Many Thanks

  3. #23
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: Adding Product Rating on Product Listing Page

    I know this is old, but it's still relevant, so here goes...

    This mod is messy in that it echoes a bit of output to the screen, then does some PHP processing, outputs more, processes more, etc. Thus there is no way to test the result to see if you want to output it at all.

    As a general approach, I would change all of the echo statements into something like $rating_content .= 'whatever'; and at the end of the process check for review quantity and only output if that is greater than 0:
    PHP Code:
    if($reviews->fields['count'] > 0) echo $rating_content
    (Before starting this processing, make sure $rating_content is empty with $rating_content = ''; )

  4. #24

    Default Re: Adding Product Rating on Product Listing Page

    Is it possible to apply this code in Featured products listing? featured_products.php

    Code:
    				// 2P added BOF - Average Product Rating
    			$reviews_query = "select count(*) as count from " . TABLE_REVIEWS . " r, "
    															   . TABLE_REVIEWS_DESCRIPTION . " rd
    							   where r.products_id = '" . (int)$listing->fields['products_id'] . "'
    							   and r.reviews_id = rd.reviews_id
    							   and rd.languages_id = '" . (int)$_SESSION['languages_id'] . "'" .
    							   $review_status;
    
    			$reviews = $db->Execute($reviews_query);
    			$reviews_average_rating_query = "select avg(reviews_rating) as average_rating from " . TABLE_REVIEWS . " r, "
    															   . TABLE_REVIEWS_DESCRIPTION . " rd
    							   where r.products_id = '" . (int)$listing->fields['products_id'] . "'
    							   and r.reviews_id = rd.reviews_id
    							   and rd.languages_id = '" . (int)$_SESSION['languages_id'] . "'" .
    							   $review_status;
    
    			$reviews_average_rating = $db->Execute($reviews_average_rating_query);
    			// 2P added EOF - Average Product Rating

  5. #25
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: Adding Product Rating on Product Listing Page

    That code doesn't include the output part of the code. I notice that it wastes a SQL query if there are no reviews, so I would alter the code you showed, and add the part from a previous post.
    PHP Code:
                    // 2P added BOF - Average Product Rating
                
    $reviews_query "select count(*) as count from " TABLE_REVIEWS " r, "
                                                                   
    TABLE_REVIEWS_DESCRIPTION " rd
                                   where r.products_id = '" 
    . (int)$listing->fields['products_id'] . "'
                                   and r.reviews_id = rd.reviews_id
                                   and rd.languages_id = '" 
    . (int)$_SESSION['languages_id'] . "'" .
                                   
    $review_status;

                
    $reviews $db->Execute($reviews_query);
                if (
    $reviews->fields['count'] > ) {//only continue if needed
                  
    $reviews_average_rating_query "select avg(reviews_rating) as average_rating from " TABLE_REVIEWS " r, "
                                                                   
    TABLE_REVIEWS_DESCRIPTION " rd
                                   where r.products_id = '" 
    . (int)$listing->fields['products_id'] . "'
                                   and r.reviews_id = rd.reviews_id
                                   and rd.languages_id = '" 
    . (int)$_SESSION['languages_id'] . "'" .
                                   
    $review_status;

                  
    $reviews_average_rating $db->Execute($reviews_average_rating_query);
                }

                
    // 2P added EOF - Average Product Rating 
    PHP Code:
    <?php // 2P modified BOF - Average Product Rating
    // echo '<p class="reviewCount">';
    if ($flag_show_product_info_reviews_count == and $reviews->fields['count'] > 0) {
    //echo TEXT_CURRENT_REVIEWS . ' <strong>' . $reviews->fields['count'] . '</strong><br />';
    $stars_image_suffix str_replace('.''_'zen_round($reviews_average_rating->fields['average_rating'] * 20) / 2); // for stars_0_5.gif, stars_1.gif, stars_1_5.gif etc.
    $average_rating zen_round($reviews_average_rating->fields['average_rating'], 2);
    echo 
    TEXT_CURRENT_REVIEWS_RATING ' <strong>' $average_rating '</strong> ' zen_image(DIR_WS_TEMPLATE_IMAGES 'stars_' $stars_image_suffix '.gif'sprintf(BOX_REVIEWS_TEXT_OF_5_STARS$average_rating));
    }
    //echo '</p>';
    // 2P modified EOF - Average Product Rating 
    ?>
    You would put the code wherever you want the output to appear; I can't advise further without looking at the file.
    Last edited by gjh42; 7 Oct 2012 at 03:10 PM. Reason: comment out unused </p>

  6. #26

    Default Re: Adding Product Rating on Product Listing Page

    Thanks gjh42's,

    Unfortunately the code cause some kind of error.
    I get a page with no products at all.

    I have tried to use this, but i keep on getting '0' as rating:

    PHP Code:
              if ($reviews->fields['count'] > ) {
                
    $products_desc .= '<p><strong>' $reviews->fields['count'] . '</strong> Reviews / ';
                
    $stars_image_suffix str_replace('.''_'zen_round($reviews_average_rating->fields['average_rating'] * 20) / 2); // for stars_0_5.gif, stars_1.gif, stars_1_5.gif etc.
                
    $average_rating zen_round($reviews_average_rating->fields['average_rating'], 2);
                
    $products_desc .= '<strong>' $average_rating '</strong> Average Rating </p>' zen_image(DIR_WS_TEMPLATE_IMAGES 'stars_' $stars_image_suffix '.gif'sprintf(BOX_REVIEWS_TEXT_OF_5_STARS$average_rating));
              } 

    this is my featured_products.php
    PHP Code:
    <?php
    /**
     * featured_products module - prepares content for display
     *
     * @package modules
     * @copyright Copyright 2003-2007 Zen Cart Development Team
     * @copyright Portions Copyright 2003 osCommerce
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
     * @version $Id: featured_products.php 6424 2007-05-31 05:59:21Z ajeh $
     */
    if (!defined('IS_ADMIN_FLAG')) {
      die(
    'Illegal Access');
    }
    // initialize vars
    $categories_products_id_list '';
    $list_of_products '';
    $featured_products_query '';
    $display_limit '';

    if ( ((
    $manufacturers_id && $_GET['filter_id'] == 0) || $_GET['music_genre_id'] > || $_GET['record_company_id'] > 0) || (!isset($new_products_category_id) || $new_products_category_id == '0') ) {
      
    $featured_products_query "select distinct p.products_id, p.products_image, pd.products_name, p.master_categories_id
                               from (" 
    TABLE_PRODUCTS " p
                               left join " 
    TABLE_FEATURED " f on p.products_id = f.products_id
                               left join " 
    TABLE_PRODUCTS_DESCRIPTION " pd on p.products_id = pd.products_id )
                               where p.products_id = f.products_id
                               and p.products_id = pd.products_id
                               and p.products_status = 1 and f.status = 1
                               and pd.language_id = '" 
    . (int)$_SESSION['languages_id'] . "'";
                               
    } else {
      
    // get all products and cPaths in this subcat tree
      
    $productsInCategory zen_get_categories_products_list( (($manufacturers_id && $_GET['filter_id'] > 0) ? zen_get_generated_category_path_rev($_GET['filter_id']) : $cPath), falsetrue0$display_limit);

      if (
    is_array($productsInCategory) && sizeof($productsInCategory) > 0) {
        
    // build products-list string to insert into SQL query
        
    foreach($productsInCategory as $key => $value) {
          
    $list_of_products .= $key ', ';
        }
        
    $list_of_products substr($list_of_products0, -2); // remove trailing comma
        
    $featured_products_query "select distinct p.products_id, p.products_image, pd.products_name, p.master_categories_id
                                    from (" 
    TABLE_PRODUCTS " p
                                    left join " 
    TABLE_FEATURED " f on p.products_id = f.products_id
                                    left join " 
    TABLE_PRODUCTS_DESCRIPTION " pd on p.products_id = pd.products_id)
                                    where p.products_id = f.products_id
                                    and p.products_id = pd.products_id
                                    and p.products_status = 1 and f.status = 1
                                    and pd.language_id = '" 
    . (int)$_SESSION['languages_id'] . "'
                                    and p.products_id in (" 
    $list_of_products ")";

      }
    }
                
    if (
    $featured_products_query != ''$featured_products $db->ExecuteRandomMulti($featured_products_queryMAX_DISPLAY_SEARCH_RESULTS_FEATURED);

    $row 0;
    $col 0;
    $list_box_contents = array();
    $title '';

    $num_products_count = ($featured_products_query == '') ? $featured_products->RecordCount();
    // show only when 1 or more
    if ($num_products_count 0) {
      if (
    $num_products_count SHOW_PRODUCT_INFO_COLUMNS_FEATURED_PRODUCTS || SHOW_PRODUCT_INFO_COLUMNS_FEATURED_PRODUCTS == 0) {
        
    $col_width floor(100/$num_products_count);
      } else {
        
    $col_width floor(100/SHOW_PRODUCT_INFO_COLUMNS_FEATURED_PRODUCTS);
      }
      while (!
    $featured_products->EOF) {
       
    $products_price zen_get_products_display_price($featured_products->fields['products_id']);
    $products_desc substr(strip_tags(trim(zen_get_products_description($featured_products->fields['products_id'], $_SESSION['languages_id']))),0,68).'&hellip;';
    $buy_now_link zen_get_buy_now_button($featured_products->fields['products_id'],'<a href="' zen_href_link($_GET['main_page'], zen_get_all_get_params(array('action')) . 'action=buy_now&products_id=' $featured_products->fields['products_id']) . '">' zen_image_button(BUTTON_IMAGE_BUY_NOWBUTTON_BUY_NOW_ALT) .'<br/>'.'</a>&nbsp;<br /');


    if (!isset(
    $productsInCategory[$featured_products->fields['products_id']])) $productsInCategory[$featured_products->fields['products_id']] = zen_get_generated_category_path_rev($featured_products->fields['master_categories_id']);

    $list_box_contents[$row][$col] = array('params' =>'class="centerBoxContentsFeatured centeredContent back"' ' ' 'style="border:1px dotted #EBEBEB;padding-bottom:10px;min-height:310px!important; width:33%;"',
    'text' => (($featured_products->fields['products_image'] == '' and PRODUCTS_IMAGE_NO_IMAGE_STATUS == 0) ? '' '<div id="featured_pro"><a href="' zen_href_link(zen_get_info_page($featured_products->fields['products_id']), 'cPath=' $productsInCategory[$featured_products->fields['products_id']] . '&products_id=' $featured_products->fields['products_id']) . '">'.
    zen_image(DIR_WS_IMAGES .$featured_products->fields['products_image'], $featured_products->fields['products_name'], IMAGE_FEATURED_PRODUCTS_LISTING_WIDTHIMAGE_FEATURED_PRODUCTS_LISTING_HEIGHT) . '</a>') . '<h3 class="itemTitle"><a href="' zen_href_link(zen_get_info_page($featured_products->fields['products_id']), 'cPath=' $productsInCategory[$featured_products->fields['products_id']] . '&products_id=' $featured_products->fields['products_id']) . '">' $featured_products->fields['products_name'] . '</h3></a><div class="listingDescription">' $products_desc '</div><div id="listing_price">'$products_price'</div><br class="clearBoth" /></div><div class="stick">'.$buy_now_link.'</div></div></div>');



        
    $col ++;
        if (
    $col > (SHOW_PRODUCT_INFO_COLUMNS_FEATURED_PRODUCTS 1)) {
          
    $col 0;
          
    $row ++;
        }
        
    $featured_products->MoveNextRandom();
      }

      if (
    $featured_products->RecordCount() > 0) {
        if (isset(
    $new_products_category_id) && $new_products_category_id !=0) {
          
    $category_title zen_get_categories_name((int)$new_products_category_id);
          
    $title '<h2 class="centerBoxHeading typeface-js">' TABLE_HEADING_FEATURED_PRODUCTS . ($category_title != '' ' - ' $category_title '') . '</h2>';
        } else {
          
    $title '<h2 class="centerBoxHeading typeface-js">' TABLE_HEADING_FEATURED_PRODUCTS '</h2>';
        }
        
    $zc_show_featured true;
      }
    }
    ?>

  7. #27
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: Adding Product Rating on Product Listing Page

    I don't see anything in your code that should cause a problem. Where did you try to insert it? It would need to go after $products_desc has been initialized. Just after this line would probably be best:
    PHP Code:
    $products_desc substr(strip_tags(trim(zen_get_products_description($featured_products->fields['products_id'], $_SESSION['languages_id']))),0,68).'&hellip;'

  8. #28

    Default Re: Adding Product Rating on Product Listing Page

    I have insert the my code right after $products_desc initializing like you said.

    I have echo $reviews->fields['count'] and it is always equal to '0' and thats why
    PHP Code:
    if ($reviews->fields['count'] > ) { 
    statement is False

    I think that this code doesn't retrieve the products ID of the featured products:
    PHP Code:
                    // 2P added BOF - Average Product Rating
                
    $reviews_query "select count(*) as count from " TABLE_REVIEWS " r, "
                                                                   
    TABLE_REVIEWS_DESCRIPTION " rd
                                   where r.products_id = '" 
    . (int)$listing->fields['products_id'] . "'
                                   and r.reviews_id = rd.reviews_id
                                   and rd.languages_id = '" 
    . (int)$_SESSION['languages_id'] . "'" .
                                   
    $review_status;

                
    $reviews $db->Execute($reviews_query);
                if (
    $reviews->fields['count'] > ) {//only continue if needed
                  
    $reviews_average_rating_query "select avg(reviews_rating) as average_rating from " TABLE_REVIEWS " r, "
                                                                   
    TABLE_REVIEWS_DESCRIPTION " rd
                                   where r.products_id = '" 
    . (int)$listing->fields['products_id'] . "'
                                   and r.reviews_id = rd.reviews_id
                                   and rd.languages_id = '" 
    . (int)$_SESSION['languages_id'] . "'" .
                                   
    $review_status;

                  
    $reviews_average_rating $db->Execute($reviews_average_rating_query);
                }

                
    // 2P added EOF - Average Product Rating 

  9. #29
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: Adding Product Rating on Product Listing Page

    The featured products file uses $featured_products->fields['products_id'] for this value.

  10. #30
    Join Date
    Sep 2013
    Posts
    25
    Plugin Contributions
    0

    Default Re: Adding Product Rating on Product Listing Page

    Quote Originally Posted by Ajeh View Post
    Just to see how this works, to add it beneath the Product Name, this is the full piece of the CASE statement:
    Code:
            case 'PRODUCT_LIST_NAME':
            $lc_align = '';
            $lc_text = '<h3 class="itemTitle"><a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . (($_GET['manufacturers_id'] > 0 and $_GET['filter_id'] > 0) ?  zen_get_generated_category_path_rev($_GET['filter_id']) : ($_GET['cPath'] > 0 ? zen_get_generated_category_path_rev($_GET['cPath']) : zen_get_generated_category_path_rev($listing->fields['master_categories_id']))) . '&products_id=' . $listing->fields['products_id']) . '">' . $listing->fields['products_name'] . '</a></h3><div class="listingDescription">' . zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION) . '</div>';
    
        // 2P added BOF - Average Product Rating
        $reviews_query = "select count(*) as count from " . TABLE_REVIEWS . " r, "
                                                           . TABLE_REVIEWS_DESCRIPTION . " rd
                           where r.products_id = '" . (int)$listing->fields['products_id'] . "'
                           and r.reviews_id = rd.reviews_id
                           and rd.languages_id = '" . (int)$_SESSION['languages_id'] . "'" .
                           $review_status;
    
        $reviews = $db->Execute($reviews_query);
        $reviews_average_rating_query = "select avg(reviews_rating) as average_rating from " . TABLE_REVIEWS . " r, "
                                                           . TABLE_REVIEWS_DESCRIPTION . " rd
                           where r.products_id = '" . (int)$listing->fields['products_id'] . "'
                           and r.reviews_id = rd.reviews_id
                           and rd.languages_id = '" . (int)$_SESSION['languages_id'] . "'" .
                           $review_status;
    
        $reviews_average_rating = $db->Execute($reviews_average_rating_query);
        // 2P added EOF - Average Product Rating
    
      if ($reviews->fields['count'] > 0 ) {
        $lc_text .= TEXT_CURRENT_REVIEWS . ' <strong>' . $reviews->fields['count'] . '</strong><br />';
        $stars_image_suffix = str_replace('.', '_', zen_round($reviews_average_rating->fields['average_rating'] * 2, 0) / 2); // for stars_0_5.gif, stars_1.gif, stars_1_5.gif etc.
        $average_rating = zen_round($reviews_average_rating->fields['average_rating'], 2);
        $lc_text .= TEXT_CURRENT_REVIEWS_RATING . ' <strong>' . $average_rating . '</strong> ' . zen_image(DIR_WS_TEMPLATE_IMAGES . 'stars_' . $stars_image_suffix . '.gif', sprintf(BOX_REVIEWS_TEXT_OF_5_STARS, $average_rating));
      }
            break;
    I am trying to get it running, but it does not work.
    I pasted this code in my includes/modules/products_listing.php but the Rating is not displayed.
    Do I have to change also some other files or only products_listing.php ?
    Thanks in regards

 

 
Page 3 of 4 FirstFirst 1234 LastLast

Similar Threads

  1. v150 How to add product rating (stars) to a product on main page
    By Dave1st in forum Templates, Stylesheets, Page Layout
    Replies: 4
    Last Post: 12 Jul 2015, 03:04 PM
  2. v139a Adding Product Rating on Featured Listing Page
    By gal_op in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 6 Oct 2012, 06:17 AM
  3. Stars Rating under product listing page
    By ken0306 in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 2 Feb 2011, 01:46 AM
  4. Average Rating in Search Results or Product Listing
    By hungoveragain in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 26 Oct 2009, 10:11 AM
  5. Showing product rating on listing
    By jcastr in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 15 Jun 2009, 05:34 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR