Star Rating on Product Card?

Open to all! Ask other shopowners for help.
lecarlb
Contributor
Posts: 316
Joined: Mon Oct 26, 2020 5:26 pm
Phoenix Version:
Has thanked: 48 times
Been thanked: 9 times

Star Rating on Product Card?

Post by lecarlb »

I was wondering if there's an addon that support this feature. I would like to show the rating stars on the product cards.

Has anyone done this? If so please share how to do it.

Thank you.


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 »

Override the card component and add in a call to Star Rating class.
Should be pretty straightforward. Give it a go?
14Steve14
Senior Contributor
Posts: 923
Joined: Fri Oct 25, 2019 7:01 pm
Phoenix Version: v1.0.9.1
Has thanked: 17 times
Been thanked: 103 times

Re: Star Rating on Product Card?

Post by 14Steve14 »

burt wrote: Mon Feb 26, 2024 9:41 am Override the card component and add in a call to Star Rating class.
Should be pretty straightforward. Give it a go?
I thought about this also, and had no end of problems. I got the model number to show, but the star ratings just created a blank page. I may have to try again when I see the errors again. My problem was that I didnt really know how much of the code copied from one of the other areas where the rating show was required.
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 »

After making a copy of /templates/default/includes/components/product_card.php
Save it in:
templates/override/includes/components/product_card.php
Edit to add the following code into the card where you want, after the price looks OK.

Code: Select all

    <?php
    $review_ratings = [];
      $review_count = count($product->get('reviews'));
      if ($review_count > 0) {
        $review_ratings[] = new star_rating((float)(int)$product->get('review_rating'));
      }
      foreach ($review_ratings as $i => $rating) {
        echo '<div class="text-center mt-2 ' . $i . '">' . $rating . '</div>';
      }
    ?>
Beware that this will show Stars twice on Reviews Box Module if that is installed.
Screenshot 2024-02-26 173254.png
You do not have the required permissions to view the files attached to this post.
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 »

heatherbell wrote: Mon Feb 26, 2024 5:35 pm Beware that this will show Stars twice on Reviews Box Module if that is installed.
This is something that needs to be solved at the Core Level to make changes to "product card" more straightforward.

I have the perfect solution which I'll commit in the 1.0.9.x series.
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 »

Thanks @heatherbell @burt

Is there a way to show the review count or number of reviews?

I've attached an example. Changing the color of the stars is not important but may be considered.

Also, how will the above code work on a 1.0.7.18 shop?
You do not have the required permissions to view the files attached to this post.
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: Tue Feb 27, 2024 4:03 am Is there a way to show the review count or number of reviews?
Yes, the code posted already shows that the count of reviews is defined so add that to the div.
Screenshot 2024-02-27 070328.png
You do not have the required permissions to view the files attached to this post.
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 »

so add that to the div.
Not sure what that means.

Thank you for the quick response.
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: Tue Feb 27, 2024 7:23 am Not sure what that means.

Code: Select all

<div class="text-center mt-2 ' . $i . '">' . $rating . '&nbsp;(' . $review_count . ')</div>
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 »

That works thank you.

Would the code be different in a 1.0.7.18 shop? I can confirm that code works in a 1.0.8.4 shop.


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