Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,84 @@
var productCommentAbuseReportErrorMessage = '{l|escape:'javascript' s='Sorry, your abuse report cannot be sent.' d='Modules.Productcomments.Shop'}';
</script>

{assign var='hasSummary' value=($nb_comments > 0 && isset($summary))}

{capture name='post_review_button'}
{if $nb_comments > 0 && $post_allowed}
<div id="product-comments-list-btn-group">
<button class="w-100 w-sm-auto btn btn-outline-primary post-product-comment" id="product-comments-list-review-button" type="button" data-bs-toggle="modal" data-bs-target="#post-product-comment-modal" data-ps-ref="product-post-review-button">
{l s='Write your review' d='Modules.Productcomments.Shop'}
</button>
</div>
{/if}
{/capture}

{capture name='comments_title'}{l s='Comments' d='Modules.Productcomments.Shop'}{if !$hasSummary} ({$nb_comments}){/if}{/capture}

<div id="product-comments-list-header">
<h2 class="section-title">
{l s='Comments' d='Modules.Productcomments.Shop'} ({$nb_comments})
</h2>
{include file='module:productcomments/views/templates/hook/average-grade-stars.tpl' grade=$average_grade showGradeAverage=true showNbComments=false}
{include file='components/section-title.tpl' title=$smarty.capture.comments_title}

{if $hasSummary}
{$smarty.capture.post_review_button nofilter}
{else}
{include file='module:productcomments/views/templates/hook/average-grade-stars.tpl' grade=$average_grade showGradeAverage=true showNbComments=false}
{/if}
</div>

{if $nb_comments > 0 && $post_allowed}
<div id="product-comments-list-btn-group">
<button class="w-100 w-sm-auto btn btn-outline-primary post-product-comment" id="product-comments-list-review-button" type="button" data-bs-toggle="modal" data-bs-target="#post-product-comment-modal" data-ps-ref="product-post-review-button">
{l s='Write your review' d='Modules.Productcomments.Shop'}
</button>
{if !$hasSummary}
{$smarty.capture.post_review_button nofilter}
{/if}

{if $hasSummary}
<div class="product-comments-summary">
<div class="product-comments-summary__left">
<div class="product-comments-summary__score-container">
<span class="product-comments-summary__average-score">{$average_grade|number_format:1}</span>
<span class="product-comments-summary__max-score">{l s='/5.0' d='Modules.Productcomments.Shop'}</span>
</div>
<div class="product-comments-summary__stars">
{include file='module:productcomments/views/templates/hook/average-grade-stars.tpl' grade=$average_grade showGradeAverage=false showNbComments=false}
</div>
<div class="product-comments-summary__count-info text-muted small">
{if $nb_comments > 1}
{l s='Based on %s reviews' sprintf=[$nb_comments] d='Modules.Productcomments.Shop'}
{else}
{l s='Based on %s review' sprintf=[$nb_comments] d='Modules.Productcomments.Shop'}
{/if}
</div>
</div>

<div class="product-comments-summary__right">
<div class="product-comments-summary__grade-list">
{foreach $summary as $grade => $details}
<div class="product-comments-summary__grade-item">
<div class="product-comments-summary__grade-label">
<span class="product-comments-summary__grade-value">{$grade}</span>
<div class="product-comments-summary__star-icon">
<div class="star-content" aria-hidden="true">
<div class="star-on"></div>
</div>
</div>
</div>

<div
class="product-comments-summary__progress progress"
role="progressbar"
aria-label="{if $grade > 1}{l s='%s stars' sprintf=[$grade] d='Modules.Productcomments.Shop'}{else}{l s='%s star' sprintf=[$grade] d='Modules.Productcomments.Shop'}{/if}"
aria-valuenow="{$details.percent|number_format:2}"
aria-valuemin="0"
aria-valuemax="100"
>
<div class="product-comments-summary__progress-bar progress-bar rounded" style="width: {$details.percent|number_format:2}%;"></div>
</div>

<div class="product-comments-summary__stats small" aria-hidden="true">
<span class="product-comments-summary__count">{$details.count}</span>
</div>
</div>
{/foreach}
</div>
</div>
</div>
{elseif $nb_comments == 0}
{include file='module:productcomments/views/templates/hook/empty-product-comment.tpl'}
Expand Down
92 changes: 91 additions & 1 deletion src/scss/prestashop/modules/_productcomments.scss
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,27 @@
padding: 0;
margin-block-end: 1rem;

&:has(#product-comments-list-btn-group) {
justify-content: space-between;
}

.section-title {
margin-block-end: 0;
}

#product-comments-list-btn-group {
margin-block-end: 0;
}
}

// Comments list button group
#product-comments-list-btn-group {
width: 100%;
margin-block-end: 1rem;

@include media-breakpoint-up(sm) {
width: auto;
}
}

// Empty comments
Expand Down Expand Up @@ -343,7 +356,7 @@
.grade-stars {
position: relative;
display: inline-block;
min-width: 7.5rem;
min-width: 7rem;
height: 1.25rem;

&.small-stars {
Expand All @@ -360,3 +373,80 @@
margin-block-end: 3rem;
}
}

/**
* Product comments summary
*/
.product-comments-summary {
display: grid;
grid-template-columns: 1fr;
gap: 1rem;
padding: 1.5rem;
margin-block-end: 1rem;
background: var(--bs-tertiary-bg);
border: var(--bs-border-width) var(--bs-border-style) var(--bs-border-color);
border-radius: var(--bs-border-radius);

&__left {
display: flex;
flex-flow: column;
align-items: center;
justify-content: center;
}

&__average-score {
font-size: 3.5rem;
font-weight: 700;
}

&__stars {
margin-block-end: 0.5rem;
}

&__star-icon {
position: relative;
display: inline-block;
min-width: 1.5rem;
height: 1.25rem;
}

&__grade-list {
display: flex;
flex-direction: column;
gap: 0.5rem;
}

&__grade-item {
display: flex;
gap: 0.5rem;
align-items: center;
}

&__grade-label {
display: flex;
gap: 0.25rem;
align-items: center;
justify-content: flex-end;
}

&__grade-value {
width: 1ch;
font-weight: 600;
text-align: center;
}

&__progress {
--bs-progress-height: 0.625rem;

flex-grow: 1;
}

&__stats {
width: 4ch;
text-align: center;
}

@include media-breakpoint-up(md) {
grid-template-columns: 4fr 8fr;
}
}