Star Rating on Product Card?
-
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?
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.
Has anyone done this? If so please share how to do it.
Thank you.
- burt
- Core Team
- Posts: 4551
- Joined: Tue Oct 29, 2019 9:37 am
- Phoenix Version: v1.1.0.8
- : Buy Me A Beverage
- Has thanked: 252 times
- Been thanked: 412 times
Re: Star Rating on Product Card?
Override the card component and add in a call to Star Rating class.
Should be pretty straightforward. Give it a go?
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?
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?
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.
Beware that this will show Stars twice on Reviews Box Module if that is installed.
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>';
}
?>You do not have the required permissions to view the files attached to this post.
- burt
- Core Team
- Posts: 4551
- Joined: Tue Oct 29, 2019 9:37 am
- Phoenix Version: v1.1.0.8
- : Buy Me A Beverage
- Has thanked: 252 times
- Been thanked: 412 times
Re: Star Rating on Product Card?
This is something that needs to be solved at the Core Level to make changes to "product card" more straightforward.heatherbell wrote: ↑Mon Feb 26, 2024 5:35 pm Beware that this will show Stars twice on Reviews Box Module if that is installed.
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?
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?
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?
Yes, the code posted already shows that the count of reviews is defined so add that to the div.
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?
Code: Select all
<div class="text-center mt-2 ' . $i . '">' . $rating . ' (' . $review_count . ')</div>