Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Adding rating review stars into product_listing.php


adbart

Recommended Posts

Hello everyone,

 

I'm trying to add the review rating stars underneath the product name of each product when it appears in the list created under each category (defined by product_listing.php).

 

At the moment, my shop generates a product list which shows the following details in a table:

 

(Product Image) Product Name Price (Buy Now Button)

 

What I would like it to do is exactly the same, but add the review rating stars directly underneath the product name (in the same table cell).

 

I have seen another thread on the forums which talks about adding the review stars to product_listing.php but it is both incomplete, and not quite the same as what I am trying to do here. It talks about putting the review stars into product_listing.php as another column, but this is not what I am trying to do.

 

Perhaps someone can give me an idea of how to do this - help would be very gladly appreciated as I have been thrashing about with lines of code for days now!

 

Some instructions in a text file with the additions and alterations to the php would probably even be considered a contribution to osCommerce that we can get listed on the osC website for other people to use.

 

I think this is something that a lot of people would like as it offers an immediate idea to your customers which products are the most popular with your other customers.

 

I look forward to your comments! All the best, Alex.

Link to comment
Share on other sites

So that the review stars look less dominating, I have created a slightly smaller set of stars for this purpose, and they are named smallstars_5.gif, for example.

 

Please someone help me on this contrib!!!!

Link to comment
Share on other sites

So that the review stars look less dominating, I have created a slightly smaller set of stars for this purpose, and they are named smallstars_5.gif, for example.

 

Please someone help me on this contrib!!!!

 

I don't have time to test this extensively but here is what you need to do (just add the red part):

 

case 'PRODUCT_LIST_NAME':

$lc_align = '';

if (isset($HTTP_GET_VARS['manufacturers_id'])) {

$lc_text = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a>';

} else {

$lc_text = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a>?';

}

$review_stars_query = tep_db_query("select round(avg(reviews_rating)) as rating from " . TABLE_REVIEWS . " where products_id = '" . $listing['products_id'] . "'");

$review_stars = tep_db_fetch_array($review_stars_query);

if ($review_stars['rating'] > 0) {

$lc_text .= '<p>' . tep_image(DIR_WS_IMAGES . 'smallstars_' . $review_stars['rating'] . '.gif');

} break;

:-)

Monika

 

addicted to writing code ... can't get enough of databases either, LOL!

 

my toolbox: Textpad - Compare and Merge - phpMyAdmin - WS_FTP - Photoshop - How to search the forum

 

Interactive Media Award July 2007 ~ category E-Commerce

my advice on the forum is for free, PMs where you send me work are considered consultation which I charge for ...

Link to comment
Share on other sites

That works perfectly!

 

Thank you ever so much Monica for that snippet of PHP expertise!

 

Note: I removed Monica's <p> tag and replaced it with <br>  (this fits in with the rest of the formatting).

 

Monica, what would I have to do in order to then have after the stars, 2 links (see below):

 

{STARS} | Reviews | Write Review

 

 

With Reviews linked to product_reviews.php for that product

 

and

 

Write Review linked to write a review for that product???

 

Thank you so much for your help!

Link to comment
Share on other sites

That works perfectly!

 

Thank you ever so much Monica for that snippet of PHP expertise!

 

Note: I removed Monica's <p> tag and replaced it with <br>  (this fits in with the rest of the formatting).

 

Monica, what would I have to do in order to then have after the stars, 2 links (see below):

 

{STARS} | Reviews | Write Review

With Reviews linked to product_reviews.php for that product

 

and

 

Write Review linked to write a review for that product???

 

Thank you so much for your help!

 

here you go:

 

case 'PRODUCT_LIST_NAME':

$lc_align = '';

if (isset($HTTP_GET_VARS['manufacturers_id'])) {

$lc_text = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a>';

} else {

$lc_text = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a> ';

}

$lc_text .= '<p><a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing['products_id']) . '">' . tep_image_button('button_buy_now.gif', IMAGE_BUTTON_BUY_NOW) . '</a> ';

$review_stars_query = tep_db_query("select round(avg(reviews_rating)) as rating from " . TABLE_REVIEWS . " where products_id = '" . $listing['products_id'] . "'");

$review_stars = tep_db_fetch_array($review_stars_query);

if ($review_stars['rating'] > 0) {

$lc_text .= '<br> ' . tep_image(DIR_WS_IMAGES . 'smallstars_' . $review_stars['rating'] . '.gif');

}

 

$lc_text .= ' | ' . '<a href="' . tep_href_link(FILENAME_PRODUCT_REVIEWS, 'products_id=' . $listing['products_id']) . '">' . YOUR_TEXT_REVIEWS . '</a>';

 

$lc_text .= ' | ' . '<a href="' . tep_href_link(FILENAME_PRODUCT_REVIEWS_WRITE, 'products_id=' . $listing['products_id']) . '">' . YOUR_TEXT_WRITE_REVIEW . '</a>';

break;

:-)

Monika

 

addicted to writing code ... can't get enough of databases either, LOL!

 

my toolbox: Textpad - Compare and Merge - phpMyAdmin - WS_FTP - Photoshop - How to search the forum

 

Interactive Media Award July 2007 ~ category E-Commerce

my advice on the forum is for free, PMs where you send me work are considered consultation which I charge for ...

Link to comment
Share on other sites

Also, with the current set-up, products that are not currently rated have nothing come up underneath them.

 

What lines of code do I add to make just some text appear saying "Not Yet Rated"?

 

$review_stars_query = tep_db_query("select round(avg(reviews_rating)) as rating from " . TABLE_REVIEWS . " where products_id = '" . $listing['products_id'] . "'");

$review_stars = tep_db_fetch_array($review_stars_query);

if ($review_stars['rating'] > 0) {

$lc_text .= '<br> ' . tep_image(DIR_WS_IMAGES . 'smallstars_' . $review_stars['rating'] . '.gif');

} else {

$lc_text .= '<br> ' . YOUR_TEXT_NOT_RATED;}

$lc_text .= ' | ' . '<a href="' . tep_href_link(FILENAME_PRODUCT_REVIEWS, 'products_id=' . $listing['products_id']) . '">' . YOUR_TEXT_REVIEWS . '</a>';

 

$lc_text .= ' | ' . '<a href="' . tep_href_link(FILENAME_PRODUCT_REVIEWS_WRITE, 'products_id=' . $listing['products_id']) . '">' . YOUR_TEXT_WRITE_REVIEW . '</a>';

 

} break;

:-)

Monika

 

addicted to writing code ... can't get enough of databases either, LOL!

 

my toolbox: Textpad - Compare and Merge - phpMyAdmin - WS_FTP - Photoshop - How to search the forum

 

Interactive Media Award July 2007 ~ category E-Commerce

my advice on the forum is for free, PMs where you send me work are considered consultation which I charge for ...

Link to comment
Share on other sites

Hi Monika

 

Thanks very much for helping me out on this.

 

The last reply you gave was almost there although it threw up a few errors when I tried to parse it, did a bit of playing around with the positioning of the 'else' clause and this now works:

 

To others planning to use this new contrib, use the below code, it is tested and working:

 

 $review_stars_query = tep_db_query("select round(avg(reviews_rating)) as rating from " . TABLE_REVIEWS . " where products_id = '" . $listing['products_id'] . "'");
$review_stars = tep_db_fetch_array($review_stars_query);
if ($review_stars['rating'] > 0) {
$lc_text .= '<font style="font-size: 2pt"><br><br></font><font style="font-size: 8.5pt" color="#008000"> Rated:</font> ' . tep_image(DIR_WS_IMAGES . 'smallstars_' . $review_stars['rating'] . '.gif');

$lc_text .= ' <br> ' . '<a href="' . tep_href_link(FILENAME_PRODUCT_REVIEWS, 'products_id=' . $listing['products_id']) . '">' . '<font style="font-size: 8.5pt" color="#808080">Read Reviews</font></a>';

$lc_text .= ' <font style="font-size: 8.5pt" color="#808080">|</font> ' . '<a href="' . tep_href_link(FILENAME_PRODUCT_REVIEWS_WRITE, 'products_id=' . $listing['products_id']) . '">' . '<font style="font-size: 8.5pt" color="#808080">Write Review</font></a>';

	   }
else {
$lc_text .= '<br> ' . YOUR_TEXT_NOT_RATED;
}

 

Many thanks to Monika for helping with this!

Link to comment
Share on other sites

Hi Monika

 

Thanks very much for helping me out on this.

 

The last reply you gave was almost there although it threw up a few errors when I tried to parse it, did a bit of playing around with the positioning of the 'else' clause and this now works:

 

To others planning to use this new contrib, use the below code, it is tested and working:

 

 $review_stars_query = tep_db_query("select round(avg(reviews_rating)) as rating from " . TABLE_REVIEWS . " where products_id = '" . $listing['products_id'] . "'");
$review_stars = tep_db_fetch_array($review_stars_query);
if ($review_stars['rating'] > 0) {
$lc_text .= '<font style="font-size: 2pt"><br><br></font><font style="font-size: 8.5pt" color="#008000"> Rated:</font> ' . tep_image(DIR_WS_IMAGES . 'smallstars_' . $review_stars['rating'] . '.gif');

$lc_text .= ' <br> ' . '<a href="' . tep_href_link(FILENAME_PRODUCT_REVIEWS, 'products_id=' . $listing['products_id']) . '">' . '<font style="font-size: 8.5pt" color="#808080">Read Reviews</font></a>';

$lc_text .= ' <font style="font-size: 8.5pt" color="#808080">|</font> ' . '<a href="' . tep_href_link(FILENAME_PRODUCT_REVIEWS_WRITE, 'products_id=' . $listing['products_id']) . '">' . '<font style="font-size: 8.5pt" color="#808080">Write Review</font></a>';

	   }
else {
$lc_text .= '<br> ' . YOUR_TEXT_NOT_RATED;
}

 

Many thanks to Monika for helping with this!

Ah I see my last bracket was de trop. I hadn't tested it. But if you do it your way, the write review willnot be visible if a product has not been rated yet. You should move the last lc_text below the curled bracket fo the else.

:-)

Monika

 

addicted to writing code ... can't get enough of databases either, LOL!

 

my toolbox: Textpad - Compare and Merge - phpMyAdmin - WS_FTP - Photoshop - How to search the forum

 

Interactive Media Award July 2007 ~ category E-Commerce

my advice on the forum is for free, PMs where you send me work are considered consultation which I charge for ...

Link to comment
Share on other sites

Monika - very nice! I *think* this is the theory of what I need to get Artist/Band Name to show in my product listing... would you be so kind to suggest how I can show the parent category of a product (parent category is a sub-category, current mod's only work for main category parent of a product).

 

 

 

I have used http://www.oscommerce.info/kb/osCommerce/G...Tips_and_Tricks/257 which will post the right Artist (parent) in the heading but that I cannot use for product_listing.php (and various other pages down the road)

 

 

 

My shop is a music store so when a cd (product) is viewed, I want the artist (sub-category parent of product) to show. Tried using breadcrumb even but that fails when navigating straight to the product instead of by clicking main cat, then sub cat then product.

 

Here is more detail from another thread where person says Artist table was added to product_info.php (should be product_listing.php?) http://www.oscommerce.com/forums/index.php?s=&...ndpost&p=868505

 

 

 

Any help at all appreciated!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...