Editing specifications html

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
4 years ago
Hi, i want to edit my specifications tab,
If i want to put two attributes on same specifications i got it like this


But i want to get it like this:



Im using nopCommerce 3.70 version.

Thank you :)
4 years ago
You need to print specifications group by SpecificationAttributeName. Open _ProductSpecifications.cshtml (Views > Product). Change specification attribute table like below.

<tbody>
    @{
        var grps = Model.GroupBy(x=> x.SpecificationAttributeName).ToList();
        for (var i = 0; i < grps.Count; i++)
        {
            var grp = grps[i];
            <tr @(i % 2 == 0 ? Html.Raw(" class=\"odd\"") : Html.Raw(" class=\"even\""))>
                <td class="spec-name">
                    @grp.FirstOrDefault().SpecificationAttributeName
                </td>
                <td class="spec-value">
                    @if (!string.IsNullOrEmpty(grp.FirstOrDefault().ColorSquaresRgb) && (grp.FirstOrDefault().AttributeTypeId == (int)SpecificationAttributeType.Option))
                    {
                        <div class="attribute-squares color-squares">
                            @foreach (var item in grp)
                            {
                                <span class="attribute-square-container" title="@Html.Raw(item.ValueRaw)">
                                    <span class="attribute-square" style="background-color: @(item.ColorSquaresRgb);">&nbsp;</span>
                                </span>
                            }
                        </div>
                    }
                    else
                    {
                        @Html.Raw(string.Join(@" / ", grp.Select(x => x.ValueRaw)))
                    }
                </td>
            </tr>
        }
    }
</tbody>


And output will be like this.
4 years ago
Hi, thanks for supporting me, i tried your code but i got compile error





_productspecifications looks like this:
@model IList<ProductSpecificationModel>
@using Nop.Web.Models.Catalog;
@if (Model.Count > 0)
{
    <div class="product-specs-box">
        <div class="title">
            <strong>@T("Products.Specs")</strong>
        </div>
        <div class="table-wrapper">
            <table class="data-table">
                <colgroup>
                    <col width="25%" />
                    <col />
                </colgroup>
                <tbody>
                    @{
                        var grps = Model.GroupBy(x => x.SpecificationAttributeName).ToList();
                        for (var i = 0; i < grps.Count; i++)
                        {
                            var grp = grps[i];
                            <tr @(i % 2 == 0 ? Html.Raw(" class=\"odd\"") : Html.Raw(" class=\"even\""))>
                                <td class="spec-name">
                                    @grp.FirstOrDefault().SpecificationAttributeName
                                </td>
                                <td class="spec-value">
                                    @if (!string.IsNullOrEmpty(grp.FirstOrDefault().ColorSquaresRgb) && (grp.FirstOrDefault().AttributeTypeId == (int)SpecificationAttributeType.Option))
                    {
                                        <div class="attribute-squares color-squares">
                                            @foreach (var item in grp)
                                            {
                                                <span class="attribute-square-container" title="@Html.Raw(item.ValueRaw)">
                                                    <span class="attribute-square" style="background-color: @(item.ColorSquaresRgb);">&nbsp;</span>
                                                </span>
                                            }
                                        </div>
                                    }
                                    else
                                    {
                                        @Html.Raw(string.Join(@" / ", grp.Select(x => x.ValueRaw)))
                                    }
                                </td>
                            </tr>
                        }
                    }
                </tbody>
            </table>
        </div>
    </div>
}
4 years ago
As per error screen, able to see that you are using nopCommerce 3.70 - right? ColorSquaresRgb was added later, that is why you got this error. Just modify cshtml according your nopCommerce version and suggestion by @mhsjaber.

Regards,
Tom
4 years ago
nop4you wrote:
As per error screen, able to see that you are using nopCommerce 3.70 - right? ColorSquaresRgb was added later, that is why you got this error. Just modify cshtml according your nopCommerce version and suggestion by @mhsjaber.

Regards,
Tom



Yeah i said that on first post,

i'll try it now :)
4 years ago
                <tbody>
                    @{
                        var grps = Model.GroupBy(x => x.SpecificationAttributeName).ToList();
                        for (var i = 0; i < grps.Count; i++)
                        {
                            var grp = grps[i];
                            <tr @(i % 2 == 0 ? Html.Raw(" class=\"odd\"") : Html.Raw(" class=\"even\""))>
                                <td class="spec-name">
                                    @grp.FirstOrDefault().SpecificationAttributeName
                                </td>
                                <td class="spec-value">
                                        @Html.Raw(string.Join(@" / ", grp.Select(x => x.ValueRaw)))
                                </td>
                            </tr>
                        }
                    }
                </tbody>



Is this okay, i mean it's working for me, but should i expect bugs ?
4 years ago
Answered in PM.

Yes, it is okay.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.