Star Rating on Product Card?

Open to all! Ask other shopowners for help.
heatherbell
Senior Contributor
Posts: 2540
Joined: Mon Oct 07, 2019 4:39 am
Phoenix Version:
Has thanked: 35 times
Been thanked: 243 times

Re: Star Rating on Product Card?

Post by heatherbell »

lecarlb wrote: Thu Feb 29, 2024 8:54 am I tried the following. Lol.

Code: Select all

<?php
       $review_stars_array = [];
      if ($review_average['count'] > 0) {
        $review_stars_array[] = tep_draw_stars((int)$review_average['average']);
     }
      foreach ($review_stars_array as $i => $rating) {
        echo '<div class="pl-3 ' . $i . '">' . $rating . '&nbsp;(' . $review_average['count'] . ')</div>';
      }
?>
So you use $review_average - what's that? Meaning it has to be defined somewhere in your code meaning there should be $review_average = thisThing. Your code is asking the same question and not finding the definition.
The definition is actually further up in the linked code (which you have not included in your code). That definition itself is a result of another definition further up in the linked code (the database query). Look again, try again, rinse, repeat ;)


Join The Code Co-op to get access to your library in the Code Co-op Forum
User avatar
burt
Core Team
Posts: 4551
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 412 times

Re: Star Rating on Product Card?

Post by burt »

lecarlb wrote: Thu Feb 29, 2024 7:17 am In 1.0.7.18, I noticed that product cards in places such as advanced search results are displayed using templates/default/includes/components/product_listing.php.

How to get the star ratings to appear there?
Step 1 is to override this file by placing it into the same location in the override folder, so it is in effect a new file;

templates/override/includes/components/product_listing.php

and then work only on this new file.

Step 2 is to see what data is being returned by the SQL

Add this

Code: Select all

echo '<pre>';
print_r($listing);
echo '</pre>';
UNDER this

Code: Select all

while ($listing = tep_db_fetch_array($listing_query)) {
There might be something regarding reviews or there might not.

If yes; the rest is easy
If no; you can either change the existing parent SQL to get reviews data or add in a child SQL call to get reviews data

Report back.
lecarlb
Contributor
Posts: 316
Joined: Mon Oct 26, 2020 5:26 pm
Phoenix Version:
Has thanked: 48 times
Been thanked: 9 times

Re: Star Rating on Product Card?

Post by lecarlb »

burt wrote: Thu Feb 29, 2024 9:32 am
lecarlb wrote: Thu Feb 29, 2024 7:17 am In 1.0.7.18, I noticed that product cards in places such as advanced search results are displayed using templates/default/includes/components/product_listing.php.

How to get the star ratings to appear there?
Step 1 is to override this file by placing it into the same location in the override folder, so it is in effect a new file;

templates/override/includes/components/product_listing.php

and then work only on this new file.

Step 2 is to see what data is being returned by the SQL

Add this

Code: Select all

echo '<pre>';
print_r($listing);
echo '</pre>';
UNDER this

Code: Select all

while ($listing = tep_db_fetch_array($listing_query)) {
There might be something regarding reviews or there might not.

If yes; the rest is easy
If no; you can either change the existing parent SQL to get reviews data or add in a child SQL call to get reviews data

Report back.
There's nothing regarding reviews.

Thanks
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: Star Rating on Product Card?

Post by ecartz »

Note that if you have a Product object, Product knows how to load the review information. If you update to 1.0.8.21, you would always have a Product object. If you don't update to 1.0.8.21, then you have to do it yourself. The child SQL query would be at https://github.com/CE-PhoenixCart/Phoen ... #L127-L132


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply