Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

2.9 KB
Raw Blame
@using System.Globalization
@model VendorReviewOverviewModel
@{
    var ratingPercent = 0;
    if (Model.TotalReviews != 0)
    {
        ratingPercent = Model.RatingSum * 100 / Model.TotalReviews / 5;
    }
}
@*
    The island marker is load-bearing. Nothing on the vendor page's header carries
    one, so without it this block is markup no island compiles: the <template v-if>
    below renders nothing and <b-form-rating> stays an unknown element - no error,
    no stars. It only shows up once a vendor has AllowCustomerReviews set, which is
    a per-vendor field, so the seed store hides the problem.

    Safe as a mount point: the itemprop attributes are Razor's, and this element
    carries no Vue directive of its own - Vue reads a mount point's innerHTML and
    would ignore one.
*@
@if (Model.AllowCustomerReviews)
{
    <div class="vendor-reviews-overview d-inline-flex align-items-center flex-wrap"
         vue-island="vendorreviewsoverview vendorreviews"
         @if (Model.TotalReviews > 0)
         {
             <text> itemprop="aggregateRating" itemscope itemtype="https://schema.org/AggregateRating" </text>
         }>
        @{
            double ratingValue = 0;
            if (Model.TotalReviews != 0)
            {
                ratingValue = Convert.ToDouble(Model.RatingSum * (double)100 / Model.TotalReviews / 100);
            }
        }
        <div class="rating">
            <b-form-rating id="rating-inline" class="p-0" variant="warning" no-border size="sm" show-value precision="2" v-model="vendorreviewsoverview.rating" readonly inline value="@(ratingValue.ToString("0.00", CultureInfo.InvariantCulture))"></b-form-rating>
            <template v-if="vendorreviewsoverview.Model.TotalReviews > 0">
                <div class="product-review-links order-3">
                    <a class="btn btn-outline-info btn-sm review-scroll-button" href="#review-tab" role="button" @@click="document.getElementById('review-tab-tab').click()">
                        {{vendorreviewsoverview.Model.TotalReviews}}
                        @Loc["Reviews.Overview.Reviews"]
                    </a>
                </div>
                @{
                    var ratingValuee = ratingPercent / (double)20;
                }
                <span itemprop="reviewCount" style="display: none;">(@ratingValuee.ToString("0.0", new CultureInfo("en-US")))</span>
            </template>
            <template v-else>
                <div class="vendor-no-reviews order-3">
                    <a class="btn btn-sm btn-outline-info" @@click="vendorreviews.addVendorReview('@Url.RouteUrl("VendorReviews", new { vendorId = Model.VendorId })')">
                        @Loc["VendorReviews.Overview.First"]
                    </a>
                </div>
            </template>
        </div>
    </div>
}
<script type="application/json" data-grand-vm="vendorReviewOverview">@Json.Serialize(new { model = Model })</script>